Author: Timm Bäder
Date: 2024-06-27T08:53:20+02:00
New Revision: e096b282cc228f8c5c774c857a943eaa0f5e1586

URL: 
https://github.com/llvm/llvm-project/commit/e096b282cc228f8c5c774c857a943eaa0f5e1586
DIFF: 
https://github.com/llvm/llvm-project/commit/e096b282cc228f8c5c774c857a943eaa0f5e1586.diff

LOG: [clang][Interp] Fix CXXUuidOfExprs with incomplete record types

Create a dummy variable for those cases.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/CodeGenCXX/microsoft-uuidof.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3170b2faeaa0b..5b06f0e0f2f05 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2695,7 +2695,18 @@ bool ByteCodeExprGen<Emitter>::VisitCXXUuidofExpr(const 
CXXUuidofExpr *E) {
     return true;
   assert(!Initializing);
 
-  std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(E->getGuidDecl());
+  const MSGuidDecl *GuidDecl = E->getGuidDecl();
+  const RecordDecl *RD = GuidDecl->getType()->getAsRecordDecl();
+  assert(RD);
+  // If the definiton of the result type is incomplete, just return a dummy.
+  // If (and when) that is read from, we will fail, but not now.
+  if (!RD->isCompleteDefinition()) {
+    if (std::optional<unsigned> I = P.getOrCreateDummy(GuidDecl))
+      return this->emitGetPtrGlobal(*I, E);
+    return false;
+  }
+
+  std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(GuidDecl);
   if (!GlobalIndex)
     return false;
   if (!this->emitGetPtrGlobal(*GlobalIndex, E))
@@ -2703,7 +2714,7 @@ bool ByteCodeExprGen<Emitter>::VisitCXXUuidofExpr(const 
CXXUuidofExpr *E) {
 
   assert(this->getRecord(E->getType()));
 
-  const APValue &V = E->getGuidDecl()->getAsAPValue();
+  const APValue &V = GuidDecl->getAsAPValue();
   if (V.getKind() == APValue::None)
     return true;
 

diff  --git a/clang/test/CodeGenCXX/microsoft-uuidof.cpp 
b/clang/test/CodeGenCXX/microsoft-uuidof.cpp
index 35b4f027e54d1..2de964a152dd5 100644
--- a/clang/test/CodeGenCXX/microsoft-uuidof.cpp
+++ b/clang/test/CodeGenCXX/microsoft-uuidof.cpp
@@ -4,6 +4,13 @@
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions 
| FileCheck %s --check-prefix=CHECK-64
 // 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
 
+/// The same, but with the new constant interpreter.
+// 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
+// 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
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - 
-triple=i386-pc-linux -fms-extensions | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - 
-triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-64
+// 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
+
 #ifdef DEFINE_GUID
 struct _GUID {
 #ifdef WRONG_GUID


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to