[PATCH] D143334: [clang][Interp] Fix diagnosing uninitialized ctor record arrays

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 5 02:12:37 PST 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

No idea why I used `isa<RecordType>(ElemType.getTypePtr())` here, but it broke detecting that the element type is of record type.

Other than that, I think a previous patch made it possible to enable those two tests that have been disabled so far.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143334

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


Index: clang/test/AST/Interp/cxx20.cpp
===================================================================
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -138,8 +138,8 @@
 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,10 +174,6 @@
                    // ref-error {{must be initialized by a constant expression}} \
                    // ref-note {{subobject of type 'int' is not initialized}}
 
-
-  // FIXME: These two are currently disabled because the array fields
-  //   cannot be initialized.
-#if 0
   class C3 {
   public:
     A a[2];
@@ -198,7 +194,6 @@
                    // expected-note {{subobject of type 'bool' is not initialized}} \
                    // ref-error {{must be initialized by a constant expression}} \
                    // ref-note {{subobject of type 'bool' is not initialized}}
-#endif
 };
 
 namespace ConstThis {
Index: clang/lib/AST/Interp/Interp.cpp
===================================================================
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -387,7 +387,7 @@
   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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143334.494879.patch
Type: text/x-patch
Size: 1771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230205/ca87bfda/attachment.bin>


More information about the cfe-commits mailing list