[clang] 5adb9a2 - [Clang] Fix crash on `void{}` (#147514)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 8 08:40:46 PDT 2025
Author: Corentin Jabot
Date: 2025-07-08T17:40:43+02:00
New Revision: 5adb9a2936855a27d4325a7a73b691f8aa67f35c
URL: https://github.com/llvm/llvm-project/commit/5adb9a2936855a27d4325a7a73b691f8aa67f35c
DIFF: https://github.com/llvm/llvm-project/commit/5adb9a2936855a27d4325a7a73b691f8aa67f35c.diff
LOG: [Clang] Fix crash on `void{}` (#147514)
Caused by an incorrect assertion.
Fixes #116440
Added:
Modified:
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index fc441dd92d1ee..44931d0481e26 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2114,8 +2114,10 @@ static int getAsInt32(llvm::ConstantInt *C, llvm::Type *I32Ty) {
Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
bool Ignore = TestAndClearIgnoreResultAssign();
(void)Ignore;
- assert (Ignore == false && "init list ignored");
unsigned NumInitElements = E->getNumInits();
+ assert(Ignore == false ||
+ (NumInitElements == 0 && E->getType()->isVoidType()) &&
+ "init list ignored");
// HLSL initialization lists in the AST are an expansion which can contain
// side-effecting expressions wrapped in opaque value expressions. To properly
diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
index 2f6a6820a7589..837d86814088b 100644
--- a/clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
+++ b/clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
@@ -1,7 +1,19 @@
-// RUN: %clang_cc1 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux -emit-llvm -o - %s | FileCheck %s
void f()
{
// CHECK: store i32 0
int i{};
}
+
+
+namespace GH116440 {
+void f() {
+ void{};
+ void();
+}
+
+// CHECK: define{{.*}} void @_ZN8GH1164401fEv()
+// CHECK-NEXT: entry
+// CHECK-NEXT: ret void
+}
More information about the cfe-commits
mailing list