[clang] 38b4df5 - [clang] Fix wrong warning about missing init for flexible array members (#66341)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 01:57:54 PDT 2023


Author: Mariya Podchishchaeva
Date: 2023-09-15T10:57:51+02:00
New Revision: 38b4df5e2e852c6f04aad1d2751e552c62851205

URL: https://github.com/llvm/llvm-project/commit/38b4df5e2e852c6f04aad1d2751e552c62851205
DIFF: https://github.com/llvm/llvm-project/commit/38b4df5e2e852c6f04aad1d2751e552c62851205.diff

LOG: [clang] Fix wrong warning about missing init for flexible array members (#66341)

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

Fixes https://github.com/llvm/llvm-project/issues/66300

Co-authored-by: Aaron Ballman <aaron at aaronballman.com>

Added: 
    

Modified: 
    clang/lib/Sema/SemaInit.cpp
    clang/test/Sema/missing-field-initializers.c

Removed: 
    


################################################################################
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..1e65b2d62e1ab84 100644
--- a/clang/test/Sema/missing-field-initializers.c
+++ b/clang/test/Sema/missing-field-initializers.c
@@ -50,3 +50,14 @@ 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[];
+};
+
+// We previously would accidentally diagnose missing a field initializer for
+// 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}};


        


More information about the cfe-commits mailing list