[clang] c524f1a - No longer crash when a consteval function returns a structure
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 4 06:41:19 PDT 2021
Author: Aaron Ballman
Date: 2021-11-04T09:41:10-04:00
New Revision: c524f1a0764da0c8d1775b2860dfc33901ca9c8f
URL: https://github.com/llvm/llvm-project/commit/c524f1a0764da0c8d1775b2860dfc33901ca9c8f
DIFF: https://github.com/llvm/llvm-project/commit/c524f1a0764da0c8d1775b2860dfc33901ca9c8f.diff
LOG: No longer crash when a consteval function returns a structure
Ensure that the destination slot exists in this case. This addresses PR51484.
Added:
Modified:
clang/lib/CodeGen/CGExprAgg.cpp
clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 1e81ad9f2dc7a..5b56a587fa5f7 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -127,6 +127,8 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
}
void VisitConstantExpr(ConstantExpr *E) {
+ EnsureDest(E->getType());
+
if (llvm::Value *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E)) {
CGF.EmitAggregateStore(Result, Dest.getAddress(),
E->getType().isVolatileQualified());
diff --git a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
index ef868fa85749f..19f02c4cf41d0 100644
--- a/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
+++ b/clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
@@ -12,3 +12,15 @@ auto x2 = X();
// CHECK-NEXT: @_ZN7PR507872x2E = global i32* @_ZN7PR507872x_E, align 4
}
+namespace PR51484 {
+// This code would previously cause a crash.
+struct X { int val; };
+consteval X g() { return {0}; }
+void f() { g(); }
+
+// CHECK: define dso_local void @_ZN7PR514841fEv() #0 {
+// CHECK: entry:
+// CHECK-NOT: call i32 @_ZN7PR514841gEv()
+// CHECK: ret void
+// CHECK: }
+}
More information about the cfe-commits
mailing list