[clang] 40c26ec - [clang][Interp] Fix diagnosing uninitialized ctor record arrays

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 02:40:03 PDT 2023


Author: Timm Bäder
Date: 2023-05-31T11:39:40+02:00
New Revision: 40c26ec48c8a8ec3c72dde912d3d7118917c8e71

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

LOG: [clang][Interp] Fix diagnosing uninitialized ctor record arrays

Differential Revision: https://reviews.llvm.org/D143334

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.cpp
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 4d331467f8f2e..0479f4c60c16c 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -386,7 +386,7 @@ static bool CheckArrayInitialized(InterpState &S, CodePtr OpPC,
   size_t NumElems = CAT->getSize().getZExtValue();
   QualType ElemType = CAT->getElementType();
 
-  if (isa<RecordType>(ElemType.getTypePtr())) {
+  if (ElemType->isRecordType()) {
     const Record *R = BasePtr.getElemRecord();
     for (size_t I = 0; I != NumElems; ++I) {
       Pointer ElemPtr = BasePtr.atIndex(I).narrow();

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 2bf935ef2375b..5d9fa90b482ea 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -138,8 +138,8 @@ static_assert(!b4); // ref-error {{not an integral constant expression}} \
 namespace UninitializedFields {
   class A {
   public:
-    int a; // expected-note 2{{subobject declared here}} \
-           // ref-note 2{{subobject declared here}}
+    int a; // expected-note 3{{subobject declared here}} \
+           // ref-note 3{{subobject declared here}}
     constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant expression}} \
@@ -174,19 +174,15 @@ namespace UninitializedFields {
                    // ref-error {{must be initialized by a constant expression}} \
                    // ref-note {{subobject 'a' is not initialized}}
 
-
-  // FIXME: These two are currently disabled because the array fields
-  //   cannot be initialized.
-#if 0
   class C3 {
   public:
     A a[2];
     constexpr C3() {}
   };
   constexpr C3 c3; // expected-error {{must be initialized by a constant expression}} \
-                   // expected-note {{subobject of type 'int' is not initialized}} \
+                   // expected-note {{subobject 'a' is not initialized}} \
                    // ref-error {{must be initialized by a constant expression}} \
-                   // ref-note {{subobject of type 'int' is not initialized}}
+                   // ref-note {{subobject 'a' is not initialized}}
 
   class C4 {
   public:
@@ -195,10 +191,9 @@ namespace UninitializedFields {
     constexpr C4(){}
   };
   constexpr C4 c4; // expected-error {{must be initialized by a constant expression}} \
-                   // expected-note {{subobject of type 'bool' is not initialized}} \
+                   // expected-note {{subobject 'B' is not initialized}} \
                    // ref-error {{must be initialized by a constant expression}} \
-                   // ref-note {{subobject of type 'bool' is not initialized}}
-#endif
+                   // ref-note {{subobject 'B' is not initialized}}
 };
 
 namespace ConstThis {


        


More information about the cfe-commits mailing list