Skip to content
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

[clang] Fix wrong warning about missing init for flexible array members #66341

Merged
merged 2 commits into from
Sep 15, 2023

Conversation

Fznamznon
Copy link
Contributor

9108897 shouldn't have removed an additional check that field has incomplete array type.

Fixes #66300

9108897 shoudn't have removed an additional check that field has
incomplete array type.

Fixes llvm#66300
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 14, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 14, 2023

@llvm/pr-subscribers-clang

Changes 9108897 shouldn't have removed an additional check that field has incomplete array type.

Fixes #66300

Full diff: https://github.com/llvm/llvm-project/pull/66341.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaInit.cpp (+2-1)
  • (modified) clang/test/Sema/missing-field-initializers.c (+8)
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93f05e2e47285e4..cb57a2d1a555caa 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2395,7 +2395,8 @@ void InitListChecker::CheckStructUnionTypes(
       if (HasDesignatedInit && InitializedFields.count(*it))
         continue;
 
-      if (!it->isUnnamedBitfield() && !it->hasInClassInitializer()) {
+      if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&
+          !it->getType()->isIncompleteArrayType()) {
         SemaRef.Diag(IList->getSourceRange().getEnd(),
                      diag::warn_missing_field_initializers)
             << *it;
diff --git a/clang/test/Sema/missing-field-initializers.c b/clang/test/Sema/missing-field-initializers.c
index 90e0e2a345b08c6..39b2b55300184cc 100644
--- a/clang/test/Sema/missing-field-initializers.c
+++ b/clang/test/Sema/missing-field-initializers.c
@@ -50,3 +50,11 @@ struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
   { 1, 2 },
   { 1 } // expected-warning {{missing field 'b' initializer}}
 };
+
+// GH66300
+struct S {
+  int f0;
+  int f1[];
+};
+
+struct S s = {1, {1, 2}}; // No warning

@Fznamznon Fznamznon requested a review from a team September 14, 2023 08:42
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !
(double checking: this does not need a release note because it fixes something that was changed post 17 branch. Correct?)

@Fznamznon
Copy link
Contributor Author

(double checking: this does not need a release note because it fixes something that was changed post 17 branch. Correct?)

Exactly. There is a release note for guilty change.

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
@shafik
Copy link
Collaborator

shafik commented Sep 14, 2023

Thank you for the quick fix

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Fznamznon Fznamznon merged commit 38b4df5 into llvm:main Sep 15, 2023
2 checks passed
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
…rs (llvm#66341)

9108897 shouldn't have removed an
additional check that field has incomplete array type.

Fixes llvm#66300

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
5 participants