[clang] [clang][bytecode] Allow more function calls in CPCE mode (PR #192597)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 23:11:21 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We previously didn't diagnose the attached test cases correctly.
---
Full diff: https://github.com/llvm/llvm-project/pull/192597.diff
4 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (-3)
- (modified) clang/lib/AST/ByteCode/Interp.h (+1-1)
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+10)
- (modified) clang/test/SemaCXX/cxx2a-consteval.cpp (+1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 17d194355208d..f6fe28c03f0be 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1006,9 +1006,6 @@ static bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
return false;
}
- if (S.checkingPotentialConstantExpression() && S.Current->getDepth() != 0)
- return false;
-
if (F->isValid() && F->hasBody() &&
(F->isConstexpr() || (S.Current->MSVCConstexprAllowed &&
F->getDecl()->hasAttr<MSConstexprAttr>())))
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 2bc74fcfe7b95..0f7f2c4e1fdec 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2070,7 +2070,7 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
}
inline bool GetPtrThisBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
- if (S.checkingPotentialConstantExpression())
+ if (S.checkingPotentialConstantExpression() && S.Current->isBottomFrame())
return false;
if (!CheckThis(S, OpPC))
return false;
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index 3eb0d1a13bf49..6467aa2e1d20b 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -612,6 +612,16 @@ namespace CastedDelete {
}
static_assert(foo() == 1); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
+
+ constexpr bool nvdtor() { // both-error {{never produces a constant expression}}
+ struct S {
+ constexpr ~S() {}
+ };
+ struct T : S {};
+ delete (S*)new T; // both-note {{delete of object with dynamic type 'T' through pointer to base class type 'S' with non-virtual destructor}}
+ return true;
+ }
+
}
constexpr void use_after_free_2() { // both-error {{never produces a constant expression}}
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 92bfa40caec4e..6440a4e85df83 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value -Wno-vla %s -verify
+// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value -Wno-vla %s -verify -fexperimental-new-constant-interpreter
typedef __SIZE_TYPE__ size_t;
``````````
</details>
https://github.com/llvm/llvm-project/pull/192597
More information about the cfe-commits
mailing list