Skip to content

Commit e096b28

Browse files
committed
[clang][Interp] Fix CXXUuidOfExprs with incomplete record types
Create a dummy variable for those cases.
1 parent 3cd3b21 commit e096b28

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,15 +2695,26 @@ bool ByteCodeExprGen<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
26952695
return true;
26962696
assert(!Initializing);
26972697

2698-
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(E->getGuidDecl());
2698+
const MSGuidDecl *GuidDecl = E->getGuidDecl();
2699+
const RecordDecl *RD = GuidDecl->getType()->getAsRecordDecl();
2700+
assert(RD);
2701+
// If the definiton of the result type is incomplete, just return a dummy.
2702+
// If (and when) that is read from, we will fail, but not now.
2703+
if (!RD->isCompleteDefinition()) {
2704+
if (std::optional<unsigned> I = P.getOrCreateDummy(GuidDecl))
2705+
return this->emitGetPtrGlobal(*I, E);
2706+
return false;
2707+
}
2708+
2709+
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(GuidDecl);
26992710
if (!GlobalIndex)
27002711
return false;
27012712
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
27022713
return false;
27032714

27042715
assert(this->getRecord(E->getType()));
27052716

2706-
const APValue &V = E->getGuidDecl()->getAsAPValue();
2717+
const APValue &V = GuidDecl->getAsAPValue();
27072718
if (V.getKind() == APValue::None)
27082719
return true;
27092720

clang/test/CodeGenCXX/microsoft-uuidof.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-64
55
// RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -DWRONG_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-WRONG-GUID
66

7+
/// The same, but with the new constant interpreter.
8+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -DDEFINE_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID
9+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -DDEFINE_GUID -DBRACKET_ATTRIB -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID
10+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s
11+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-64
12+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -DDEFINE_GUID -DWRONG_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-WRONG-GUID
13+
714
#ifdef DEFINE_GUID
815
struct _GUID {
916
#ifdef WRONG_GUID

0 commit comments

Comments
 (0)