Skip to content

Commit 5adb9a2

Browse files
authored
[Clang] Fix crash on void{} (#147514)
Caused by an incorrect assertion. Fixes #116440
1 parent bbefd33 commit 5adb9a2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,8 +2114,10 @@ static int getAsInt32(llvm::ConstantInt *C, llvm::Type *I32Ty) {
21142114
Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
21152115
bool Ignore = TestAndClearIgnoreResultAssign();
21162116
(void)Ignore;
2117-
assert (Ignore == false && "init list ignored");
21182117
unsigned NumInitElements = E->getNumInits();
2118+
assert(Ignore == false ||
2119+
(NumInitElements == 0 && E->getType()->isVoidType()) &&
2120+
"init list ignored");
21192121

21202122
// HLSL initialization lists in the AST are an expansion which can contain
21212123
// side-effecting expressions wrapped in opaque value expressions. To properly
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
// RUN: %clang_cc1 -std=c++11 -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s
22

33
void f()
44
{
55
// CHECK: store i32 0
66
int i{};
77
}
8+
9+
10+
namespace GH116440 {
11+
void f() {
12+
void{};
13+
void();
14+
}
15+
16+
// CHECK: define{{.*}} void @_ZN8GH1164401fEv()
17+
// CHECK-NEXT: entry
18+
// CHECK-NEXT: ret void
19+
}

0 commit comments

Comments
 (0)