[clang][bytecode] Fail on reads from constexpr-unknown pointers (#164996)

If they aren't const.

Fixes https://github.com/llvm/llvm-project/issues/164985
This commit is contained in:
Timm Baeder
2025-10-27 09:38:23 +01:00
committed by GitHub
parent de9e18dc75
commit bc37018a0b
2 changed files with 17 additions and 0 deletions

View File

@@ -832,6 +832,8 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
return false;
if (!CheckVolatile(S, OpPC, Ptr, AK))
return false;
if (!Ptr.isConst() && !S.inConstantContext() && isConstexprUnknown(Ptr))
return false;
return true;
}

View File

@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions -fexperimental-new-constant-interpreter | FileCheck %s
/// The read from a used to succeed, causing the entire if statement to vanish.
extern void e();
int somefunc() {
auto foo = [a = false]() mutable {
if (a)
e();
};
foo();
}
// CHECK: call void @_Z1ev()