yamaguchi updated this revision to Diff 97228.
yamaguchi added a comment.
Add check if there is -Wmissing-braces enabled or not.
https://reviews.llvm.org/D32646
Files:
lib/Sema/SemaInit.cpp
test/Sema/warn-missing-braces.c
Index: test/Sema/warn-missing-braces.c
===================================================================
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
// RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+ unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}}
expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,16 @@
StructuredSubobjectInitList->setRBraceLoc(EndLoc);
}
- // Complain about missing braces.
- if (T->isArrayType() || T->isRecordType()) {
+ // Complain about missing braces when rhs is not a macro from system
header.
+ // getSpellingLoc() isn't cheap, so only call it if the warning is enabled.
+ if ((T->isArrayType() || T->isRecordType()) &&
+ !SemaRef.Diags.isIgnored(diag::warn_missing_braces,
+ StructuredSubobjectInitList->getLocStart())) {
+ SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+ SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+ if (SpellingLoc.isValid() &&
+ SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
+ return;
SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
<< StructuredSubobjectInitList->getSourceRange()
Index: test/Sema/warn-missing-braces.c
===================================================================
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
// RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+ unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,16 @@
StructuredSubobjectInitList->setRBraceLoc(EndLoc);
}
- // Complain about missing braces.
- if (T->isArrayType() || T->isRecordType()) {
+ // Complain about missing braces when rhs is not a macro from system header.
+ // getSpellingLoc() isn't cheap, so only call it if the warning is enabled.
+ if ((T->isArrayType() || T->isRecordType()) &&
+ !SemaRef.Diags.isIgnored(diag::warn_missing_braces,
+ StructuredSubobjectInitList->getLocStart())) {
+ SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+ SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+ if (SpellingLoc.isValid() &&
+ SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
+ return;
SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
<< StructuredSubobjectInitList->getSourceRange()
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits