[clang] [clang][bytecode] Allow checking builtin functions... (PR #119328)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 9 21:36:09 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
... 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
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}} \
``````````
</details>
https://github.com/llvm/llvm-project/pull/119328
More information about the cfe-commits
mailing list