[PATCH] D123648: Restrict lvalue-to-rvalue conversions in CGExprConstant.
Eli Friedman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 13 12:35:15 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd791de0e25e1: Restrict lvalue-to-rvalue conversions in CGExprConstant. (authored by efriedma).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123648/new/
https://reviews.llvm.org/D123648
Files:
clang/lib/CodeGen/CGExprConstant.cpp
clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
Index: clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
===================================================================
--- clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -9,7 +9,7 @@
// CHECK: @_ZN7PR507872x_E = external global i32, align 4
// CHECK-NEXT: @_ZN7PR507872x1E = constant i32* @_ZN7PR507872x_E, align 8
-// CHECK-NEXT: @_ZN7PR507872x2E = global i32* @_ZN7PR507872x_E, align 4
+// CHECK-NEXT: @_ZN7PR507872x2E = global i32 0, align 4
}
namespace PR51484 {
@@ -18,7 +18,7 @@
consteval X g() { return {0}; }
void f() { g(); }
-// CHECK: define dso_local void @_ZN7PR514841fEv() #0 {
+// CHECK: define dso_local void @_ZN7PR514841fEv() #1 {
// CHECK: entry:
// CHECK-NOT: call i32 @_ZN7PR514841gEv()
// CHECK: ret void
Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1092,7 +1092,16 @@
destAS, destTy);
}
- case CK_LValueToRValue:
+ case CK_LValueToRValue: {
+ // We don't really support doing lvalue-to-rvalue conversions here; any
+ // interesting conversions should be done in Evaluate(). But as a
+ // special case, allow compound literals to support the gcc extension
+ // allowing "struct x {int x;} x = (struct x) {};".
+ if (auto *E = dyn_cast<CompoundLiteralExpr>(subExpr->IgnoreParens()))
+ return Visit(E->getInitializer(), destType);
+ return nullptr;
+ }
+
case CK_AtomicToNonAtomic:
case CK_NonAtomicToAtomic:
case CK_NoOp:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123648.422602.patch
Type: text/x-patch
Size: 1703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220413/af118fb6/attachment.bin>
More information about the cfe-commits
mailing list