[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 07:30:58 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/135548
We used to accept c++ as a known value here, causing wrong codegen.
>From a64e39a20719b89dd946f404e83d32026f8db377 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.h | 5 +++++
clang/test/AST/ByteCode/codegen.cpp | 11 ++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
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