Skip to content

Conversation

@cor3ntin
Copy link
Contributor

@cor3ntin cor3ntin commented Jul 8, 2025

Caused by an incorrect assertion.

Fixes #116440

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Jul 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2025

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)

Changes

Caused by an incorrect assertion.

Fixes #116440


Full diff: https://github.com/llvm/llvm-project/pull/147514.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGExprScalar.cpp (+3-1)
  • (modified) clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp (+9)
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..478ad40359727 100644
--- a/clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
+++ b/clang/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
@@ -5,3 +5,12 @@ void f()
   // CHECK: store i32 0
   int i{};
 }
+
+
+namespace GH116440 {
+void f() {
+  void{};
+  void();
+}
+
+}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add check-lines to this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want me to check? noting is emitted

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the function header then CHECK-NEXT: ret void confirms that it actually does nothing/makes it through codegen without going sideways.

So:

// CHECK: define{{.*}} void @{{.*}}GH116440{{.*}}()
// CHECK-NEXT: {{.*}}:
// CHECK-NEXT: ret void

That should work on both windows and itanium manglers, though be more specific on the function name if this test uses a triple.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no target-triple on this test, so this will fail in windows mode. You can try running it with -triple x86_64-windows-pc to see what I mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups!

@cor3ntin cor3ntin force-pushed the corentin/gh116440 branch from 7f8cabb to 6ca3ffa Compare July 8, 2025 14:07
@cor3ntin cor3ntin merged commit 5adb9a2 into llvm:main Jul 8, 2025
9 checks passed
Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we missed a release note?

Comment on lines +2118 to +2120
assert(Ignore == false ||
(NumInitElements == 0 && E->getType()->isVoidType()) &&
"init list ignored");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new assert formulation raises a warning in gcc -Wall: https://godbolt.org/z/G8v1zqE4Y
And the grouping of the comment "init list ignored" to only the second condition seems unintended or misleading. Could we revise this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #158635

erichkeane added a commit to erichkeane/llvm-project that referenced this pull request Sep 15, 2025
As brought up on the review for llvm#147514, the original patch doesn't
correctly parenthesize the expression in the assert.  This fixes it.
erichkeane added a commit that referenced this pull request Sep 15, 2025
As brought up on the review for #147514, the original patch doesn't
correctly parenthesize the expression in the assert. This fixes it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Clang] ICE on void{}

5 participants