Skip to content

Conversation

@tbaederr
Copy link
Contributor

... in checkingPotentialConstantExpression mode. This is what the current interpreter does, yet it doesn't do so for __builtin_operator_new.

... in checkingPotentialConstantExpression mode. This is what the
current interpreter does, yet it doesn't do so for
`__builtin_operator_new`.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

... in checkingPotentialConstantExpression mode. This is what the current interpreter does, yet it doesn't do so for __builtin_operator_new.


Full diff: https://github.com/llvm/llvm-project/pull/119328.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Interp.cpp (+4-1)
  • (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+2-2)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 435af1201890c8..7c7752080746e9 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1360,7 +1360,10 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
 
 bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
             const CallExpr *CE, uint32_t BuiltinID) {
-  if (S.checkingPotentialConstantExpression())
+  // A little arbitrary, but the current interpreter allows evaluation
+  // of builtin functions in this mode, with some exceptions.
+  if (BuiltinID == Builtin::BI__builtin_operator_new &&
+      S.checkingPotentialConstantExpression())
     return false;
   auto NewFrame = std::make_unique<InterpFrame>(S, Func, OpPC);
 
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index a67b6b665f3790..7dd08cb5fa1c35 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1198,11 +1198,11 @@ namespace BuiltinMemcpy {
   }
   static_assert(simpleMove() == 12);
 
-  constexpr int memcpyTypeRem() { // ref-error {{never produces a constant expression}}
+  constexpr int memcpyTypeRem() { // both-error {{never produces a constant expression}}
     int a = 12;
     int b = 0;
     __builtin_memmove(&b, &a, 1); // both-note {{'memmove' not supported: size to copy (1) is not a multiple of size of element type 'int'}} \
-                                  // ref-note {{not supported}}
+                                  // both-note {{not supported}}
     return b;
   }
   static_assert(memcpyTypeRem() == 12); // both-error {{not an integral constant expression}} \

@tbaederr tbaederr merged commit ce15873 into llvm:main Dec 10, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants