aaronpuchert updated this revision to Diff 387056.
aaronpuchert marked an inline comment as done.
aaronpuchert added a comment.

Also fix code generation for `void{}`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99466/new/

https://reviews.llvm.org/D99466

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGenCXX/value-init.cpp


Index: clang/test/CodeGenCXX/value-init.cpp
===================================================================
--- clang/test/CodeGenCXX/value-init.cpp
+++ clang/test/CodeGenCXX/value-init.cpp
@@ -338,4 +338,15 @@
   struct optional : optional_data_dtor_base, optional_assign_base {};
   optional f(optional a) { return {optional(a)}; }
 }
+
+namespace PR48889 {
+  // Just make sure we don't hit an assertion, the IR is otherwise unchanged.
+  constexpr void f() {}
+  void paren_list(bool b) {
+    return b ? f() : void();
+  }
+  void braced_list(bool b) {
+    return b ? f() : void{};
+  }
+}
 #endif
Index: clang/lib/CodeGen/CGExprScalar.cpp
===================================================================
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -1523,6 +1523,10 @@
 }
 
 Value *ScalarExprEmitter::EmitNullValue(QualType Ty) {
+  // [expr.type.conv]: if the type is cv void and the initializer is () or {},
+  // the expression is a prvalue of type void that performs no initialization.
+  if (Ty->isVoidType())
+    return nullptr;
   return CGF.EmitFromMemory(CGF.CGM.EmitNullConstant(Ty), Ty);
 }
 


Index: clang/test/CodeGenCXX/value-init.cpp
===================================================================
--- clang/test/CodeGenCXX/value-init.cpp
+++ clang/test/CodeGenCXX/value-init.cpp
@@ -338,4 +338,15 @@
   struct optional : optional_data_dtor_base, optional_assign_base {};
   optional f(optional a) { return {optional(a)}; }
 }
+
+namespace PR48889 {
+  // Just make sure we don't hit an assertion, the IR is otherwise unchanged.
+  constexpr void f() {}
+  void paren_list(bool b) {
+    return b ? f() : void();
+  }
+  void braced_list(bool b) {
+    return b ? f() : void{};
+  }
+}
 #endif
Index: clang/lib/CodeGen/CGExprScalar.cpp
===================================================================
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -1523,6 +1523,10 @@
 }
 
 Value *ScalarExprEmitter::EmitNullValue(QualType Ty) {
+  // [expr.type.conv]: if the type is cv void and the initializer is () or {},
+  // the expression is a prvalue of type void that performs no initialization.
+  if (Ty->isVoidType())
+    return nullptr;
   return CGF.EmitFromMemory(CGF.CGM.EmitNullConstant(Ty), Ty);
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to