Skip to content

[clang] Fix unexpected warnings after a01307a #75591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,17 @@ InitListChecker::FillInEmptyInitializations(const InitializedEntity &Entity,
WarnIfMissingField &=
SemaRef.getLangOpts().CPlusPlus || !hasAnyDesignatedInits(SForm);

if (OuterILE) {
// When nested designators are present, there might be two nested init
// lists created and only outer will contain designated initializer
// expression, so check outer list as well.
InitListExpr *OuterSForm = OuterILE->isSyntacticForm()
? OuterILE
: OuterILE->getSyntacticForm();
WarnIfMissingField &= SemaRef.getLangOpts().CPlusPlus ||
!hasAnyDesignatedInits(OuterSForm);
}

unsigned NumElems = numStructUnionElements(ILE->getType());
if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
++NumElems;
Expand Down
23 changes: 23 additions & 0 deletions clang/test/Sema/missing-field-initializers.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,26 @@ struct S {
// f1, now we no longer issue that warning (note, this code is still unsafe
// because of the buffer overrun).
struct S s = {1, {1, 2}};

struct S1 {
long int l;
struct { int a, b; } d1;
};

struct S1 s01 = { 1, {1} }; // expected-warning {{missing field 'b' initializer}}
struct S1 s02 = { .d1.a = 1 }; // designator avoids MFI warning

union U1 {
long int l;
struct { int a, b; } d1;
};

union U1 u01 = { 1 };
union U1 u02 = { .d1.a = 1 }; // designator avoids MFI warning

struct S2 {
long int l;
struct { int a, b; struct {int c; } d2; } d1;
};

struct S2 s22 = { .d1.d2.c = 1 }; // designator avoids MFI warning