[clang] 36f8c8b - [clang][bytecode] Fix rejecting non-constexpr array ctors (#127448)

via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 16 23:06:16 PST 2025


Author: Timm Baeder
Date: 2025-02-17T08:06:12+01:00
New Revision: 36f8c8b43836775c3d9d8da63b97d984b19853d1

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

LOG: [clang][bytecode] Fix rejecting non-constexpr array ctors (#127448)

We shouldn't abort here when compiling, this is happening (and properly
diagnosed) when interpreting the bytecode.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/new-delete.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index c8ace39d56fd0..59c236c9da8c8 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3029,7 +3029,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
 
     size_t NumElems = CAT->getZExtSize();
     const Function *Func = getFunction(E->getConstructor());
-    if (!Func || !Func->isConstexpr())
+    if (!Func)
       return false;
 
     // FIXME(perf): We're calling the constructor once per array element here,

diff  --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index 31f066b37858d..e9850d27666e5 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -865,7 +865,6 @@ constexpr unsigned short ssmall = SS<unsigned short>(100)[42];
 constexpr auto Ss = SS<S>()[0];
 
 
-
 namespace IncompleteArray {
   struct A {
     int b = 10;
@@ -908,8 +907,19 @@ namespace IncompleteArray {
     return c;
   }
   static_assert(test4() == 12);
+}
 
+namespace NonConstexprArrayCtor {
+  struct S {
+    S() {} // both-note 2{{declared here}}
+  };
 
+  constexpr bool test() { // both-error {{never produces a constant expression}}
+     auto s = new S[1]; // both-note 2{{non-constexpr constructor}}
+     return true;
+  }
+  static_assert(test()); // both-error {{not an integral constant expression}} \
+                         // both-note {{in call to}}
 }
 
 #else


        


More information about the cfe-commits mailing list