[clang] 974bda8 - [clang][bytecode] Reject constexpr-unknown pointers from Inc ops (#135548)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 13 09:57:59 PDT 2025
Author: Timm Baeder
Date: 2025-04-13T18:57:55+02:00
New Revision: 974bda8f61e056f90b17baa6db686c91d20ebe9d
URL: https://github.com/llvm/llvm-project/commit/974bda8f61e056f90b17baa6db686c91d20ebe9d
DIFF: https://github.com/llvm/llvm-project/commit/974bda8f61e056f90b17baa6db686c91d20ebe9d.diff
LOG: [clang][bytecode] Reject constexpr-unknown pointers from Inc ops (#135548)
We used to accept c++ as a known value here, causing wrong codegen.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/codegen.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 0afd772c73b85..3e1f36da8925f 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -307,7 +307,7 @@ bool isConstexprUnknown(const Pointer &P) {
if (P.isDummy())
return false;
const VarDecl *VD = P.block()->getDescriptor()->asVarDecl();
- return VD && VD->hasLocalStorage();
+ return VD && VD->hasLocalStorage() && !isa<ParmVarDecl>(VD);
}
bool CheckBCPResult(InterpState &S, const Pointer &Ptr) {
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 4e84dcc8d551d..b4e15b3ffbe68 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -771,6 +771,11 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
bool CanOverflow) {
assert(!Ptr.isDummy());
+ if (!S.inConstantContext()) {
+ if (isConstexprUnknown(Ptr))
+ return false;
+ }
+
if constexpr (std::is_same_v<T, Boolean>) {
if (!S.getLangOpts().CPlusPlus14)
return Invalid(S, OpPC);
diff --git a/clang/test/AST/ByteCode/codegen.cpp b/clang/test/AST/ByteCode/codegen.cpp
index ea2c812f30f6f..7c853a20362b8 100644
--- a/clang/test/AST/ByteCode/codegen.cpp
+++ b/clang/test/AST/ByteCode/codegen.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s
#ifdef __SIZEOF_INT128__
@@ -95,3 +95,12 @@ void f(A *a) {
// CHECK: call void @_ZN1AD1Ev(
A::E e3 = A().Foo;
}
+
+int notdead() {
+ auto l = [c=0]() mutable {
+ return c++ < 5 ? 10 : 12;
+ };
+ return l();
+}
+// CHECK: _ZZ7notdeadvEN3$_0clEv
+// CHECK: ret i32 %cond
More information about the cfe-commits
mailing list