Skip to content

Commit 83248eb

Browse files
committed
[Clang][CodeGen] Bail out on constexpr unknown values in ConstantEmitter
1 parent 876174f commit 83248eb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,8 +1883,10 @@ llvm::Constant *ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
18831883

18841884
// Try to emit the initializer. Note that this can allow some things that
18851885
// are not allowed by tryEmitPrivateForMemory alone.
1886-
if (APValue *value = D.evaluateValue())
1887-
return tryEmitPrivateForMemory(*value, destType);
1886+
if (APValue *value = D.evaluateValue()) {
1887+
if (!value->allowConstexprUnknown())
1888+
return tryEmitPrivateForMemory(*value, destType);
1889+
}
18881890

18891891
return nullptr;
18901892
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++23 %s -emit-llvm -o - | FileCheck %s
2+
3+
extern int& s;
4+
5+
// CHECK: @_Z4testv()
6+
// CHECK-NEXT: entry:
7+
// CHECK-NEXT: [[I:%.*]] = alloca ptr, align {{.*}}
8+
// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @s, align {{.*}}
9+
// CHECK-NEXT: store ptr [[X]], ptr [[I]], align {{.*}}
10+
int& test() {
11+
auto &i = s;
12+
return i;
13+
}

0 commit comments

Comments
 (0)