Skip to content

Commit f08b41b

Browse files
tbaederrdvbuka
authored andcommitted
[clang][bytecode] Fail on reads from constexpr-unknown pointers (llvm#164996)
If they aren't const. Fixes llvm#164985
1 parent de9e669 commit f08b41b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,8 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
832832
return false;
833833
if (!CheckVolatile(S, OpPC, Ptr, AK))
834834
return false;
835+
if (!Ptr.isConst() && !S.inConstantContext() && isConstexprUnknown(Ptr))
836+
return false;
835837
return true;
836838
}
837839

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions | FileCheck %s
2+
// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions -fexperimental-new-constant-interpreter | FileCheck %s
3+
4+
5+
/// The read from a used to succeed, causing the entire if statement to vanish.
6+
extern void e();
7+
int somefunc() {
8+
auto foo = [a = false]() mutable {
9+
if (a)
10+
e();
11+
};
12+
foo();
13+
}
14+
15+
// CHECK: call void @_Z1ev()

0 commit comments

Comments
 (0)