[PATCH] D154486: [Clang] Fix a crash when trying to initialize an invalid aggregate.
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 5 06:46:03 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bc7f3fb9367: [Clang] Fix a crash when trying to initialize an invalid aggregate. (authored by cor3ntin).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154486/new/
https://reviews.llvm.org/D154486
Files:
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp
Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===================================================================
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,25 @@
// expected-warning at -1 {{braces around scalar init}}
// beforecxx20-warning at -2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
}
+
+
+namespace GH63278 {
+struct S {
+ int a = 0;
+ int b {0};
+ auto x = 1; // expected-error {{'auto' not allowed in non-static struct member}}
+ static const auto y = 1;
+};
+
+int test() {
+ // used to crash
+ S a(0, 1);
+ S b(0);
+ S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' from a parenthesized list of values is a C++20 extension}}
+
+ S d {0, 1};
+ S e {0};
+ S f {0, 0, 1};
+}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -9387,10 +9387,13 @@
}
}
+ Expr *Init = CurInit.get();
+ if (!Init)
+ return ExprError();
+
// Check whether the initializer has a shorter lifetime than the initialized
// entity, and if not, either lifetime-extend or warn as appropriate.
- if (auto *Init = CurInit.get())
- S.checkInitializerLifetime(Entity, Init);
+ S.checkInitializerLifetime(Entity, Init);
// Diagnose non-fatal problems with the completed initialization.
if (InitializedEntity::EntityKind EK = Entity.getKind();
@@ -9398,16 +9401,13 @@
EK == InitializedEntity::EK_ParenAggInitMember) &&
cast<FieldDecl>(Entity.getDecl())->isBitField())
S.CheckBitFieldInitialization(Kind.getLocation(),
- cast<FieldDecl>(Entity.getDecl()),
- CurInit.get());
+ cast<FieldDecl>(Entity.getDecl()), Init);
// Check for std::move on construction.
- if (const Expr *E = CurInit.get()) {
- CheckMoveOnConstruction(S, E,
- Entity.getKind() == InitializedEntity::EK_Result);
- }
+ CheckMoveOnConstruction(S, Init,
+ Entity.getKind() == InitializedEntity::EK_Result);
- return CurInit;
+ return Init;
}
/// Somewhere within T there is an uninitialized reference subobject.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154486.537345.patch
Type: text/x-patch
Size: 2362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/96e735bc/attachment-0001.bin>
More information about the cfe-commits
mailing list