[PATCH] D99466: Fix PR48889: assertion failure for void() in flattened ternary expression
Aaron Puchert via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 28 05:32:23 PDT 2021
aaronpuchert created this revision.
aaronpuchert added a reviewer: rsmith.
aaronpuchert requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
We treat the expression void() as CXXScalarValueInitExpr for historic
reasons probably, but void isn't a scalar type. The current standard
considers this a functional cast expression, where void is explicitly
exempted from initialization.
Repository:
rG LLVM Github Monorepo
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,12 @@
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 g(bool b) {
+ return b ? f() : void();
+ }
+}
#endif
Index: clang/lib/CodeGen/CGExprScalar.cpp
===================================================================
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -463,7 +463,10 @@
return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
}
Value *VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E) {
- return EmitNullValue(E->getType());
+ // [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.
+ QualType T = E->getType();
+ return T->isVoidType() ? nullptr : EmitNullValue(E->getType());
}
Value *VisitGNUNullExpr(const GNUNullExpr *E) {
return EmitNullValue(E->getType());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99466.333718.patch
Type: text/x-patch
Size: 1302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210328/86f0e9e4/attachment.bin>
More information about the cfe-commits
mailing list