[clang] [clang][bytecode] Reject constexpr-unknown pointers from Inc ops (PR #135548)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 13 08:41:06 PDT 2025
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/135548
>From d26fc41fbfcb7c6c3159e3a7314d84c2ce2785b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 13 Apr 2025 16:25:28 +0200
Subject: [PATCH] [clang][bytecode] Reject constexpr-unknown pointers from Inc
ops
We used to accept c++ as a known value here, causing wrong codegen.
---
clang/lib/AST/ByteCode/Interp.cpp | 2 +-
clang/lib/AST/ByteCode/Interp.h | 5 +++++
clang/test/AST/ByteCode/codegen.cpp | 11 ++++++++++-
3 files changed, 16 insertions(+), 2 deletions(-)
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