[PATCH] D35564: Suppress -pedantic warnings about GNU extension StmtExpr in glibc's assert macro
Stephan Bergmann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 18 01:58:13 PDT 2017
sberg updated this revision to Diff 111634.
sberg added a comment.
(the original diff had inadvertently lacked full -U999999 context; uploaded a new diff)
https://reviews.llvm.org/D35564
Files:
clang/lib/Basic/DiagnosticIDs.cpp
clang/test/SemaCXX/warn-sysheader-macro.cpp
Index: clang/test/SemaCXX/warn-sysheader-macro.cpp
===================================================================
--- clang/test/SemaCXX/warn-sysheader-macro.cpp
+++ clang/test/SemaCXX/warn-sysheader-macro.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow -Wold-style-cast %s
+// RUN: %clang_cc1 -verify -fsyntax-only -Wshadow -Wold-style-cast -pedantic %s
// Test that macro expansions from system headers don't trigger 'syntactic'
// warnings that are not actionable.
@@ -12,6 +12,8 @@
#define OLD_STYLE_CAST(a) ((int) (a))
+#define ASSERT(a) ({ if (a) {} else {} })
+
#else
#define IS_SYSHEADER
@@ -32,4 +34,9 @@
int i = OLD_STYLE_CAST(0);
}
+void testExtension() {
+ ASSERT(true);
+ ASSERT(({ true; })); // expected-warning {{use of GNU statement expression extension}}
+}
+
#endif
Index: clang/lib/Basic/DiagnosticIDs.cpp
===================================================================
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -396,6 +396,14 @@
return toLevel(getDiagnosticSeverity(DiagID, Loc, Diag));
}
+static bool isSystemFunctionMacroBodyExpansion(SourceLocation Loc,
+ const SourceManager &SM) {
+ if (!(SM.isInSystemMacro(Loc) && SM.isMacroBodyExpansion(Loc)))
+ return false;
+ auto Range = SM.getImmediateExpansionRange(Loc);
+ return Range.first != Range.second;
+}
+
/// \brief Based on the way the client configured the Diagnostic
/// object, classify the specified diagnostic ID into a Level, consumable by
/// the DiagnosticClient.
@@ -469,8 +477,10 @@
// because we also want to ignore extensions and warnings in -Werror and
// -pedantic-errors modes, which *map* warnings/extensions to errors.
if (State->SuppressSystemWarnings && !ShowInSystemHeader && Loc.isValid() &&
- Diag.getSourceManager().isInSystemHeader(
- Diag.getSourceManager().getExpansionLoc(Loc)))
+ (Diag.getSourceManager().isInSystemHeader(
+ Diag.getSourceManager().getExpansionLoc(Loc)) ||
+ (IsExtensionDiag &&
+ isSystemFunctionMacroBodyExpansion(Loc, Diag.getSourceManager()))))
return diag::Severity::Ignored;
return Result;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35564.111634.patch
Type: text/x-patch
Size: 2231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170818/0fa9cd62/attachment.bin>
More information about the cfe-commits
mailing list