llvm-project/clang/lib
Nico Weber 0e631639be Tweak how -Wunused-value interacts with macros
1. Make the warning more strict in C mode. r172696 added code to suppress
   warnings from macro expansions in system headers, which checks
   `SourceMgr.isMacroBodyExpansion(E->IgnoreParens()->getExprLoc())`. Consider
   this snippet:

   #define FOO(x) (x)
   void f(int a) {
     FOO(a);
   }

   In C, the line `FOO(a)` is an `ImplicitCastExpr(ParenExpr(DeclRefExpr))`,
   while it's just a `ParenExpr(DeclRefExpr)` in C++. So in C++,
   `E->IgnoreParens()` returns the `DeclRefExpr` and the check tests the
   SourceLoc of `a`. In C, the `ImplicitCastExpr` has the effect of checking the
   SourceLoc of `FOO`, which is a macro body expansion, which causes the
   diagnostic to be skipped. It looks unintentional that clang does different
   things for C and C++ here, so use `IgnoreParenImpCasts` instead of
   `IgnoreParens` here. This has the effect of the warning firing more often
   than previously in C code – it now fires as often as it fires in C++ code.

2. Suppress the warning if it would warn on `UNREFERENCED_PARAMETER`.
   `UNREFERENCED_PARAMETER` is a commonly used macro on Windows and it happens
   to uselessly trigger -Wunused-value. As discussed in the thread
   "rfc: winnt.h's UNREFERENCED_PARAMETER() vs clang's -Wunused-value" on
   cfe-dev, fix this by special-casing this specific macro. (This costs a string
   comparison and some fast-path lexing per warning, but the warning is emitted
   rarely. It fires once in Windows.h itself, so this code runs at least once
   per TU including Windows.h, but it doesn't run hundreds of times.)

http://reviews.llvm.org/D13969

llvm-svn: 251441
2015-10-27 19:47:40 +00:00
..
ARCMigrate Define weak and __weak to mean ARC-style weak references, even in MRC. 2015-10-22 18:38:17 +00:00
AST [MSVC] Workaround for ICE in cl.exe when compiling ASTContext.cpp in Release Win32 2015-10-27 17:01:10 +00:00
ASTMatchers [AST] Re-add TypeLocs and NestedNameSpecifierLocs to the ParentMap. 2015-10-23 09:04:55 +00:00
Analysis [coroutines] Creation of promise object, lookup of operator co_await, building 2015-10-27 06:02:45 +00:00
Basic Simplify boolean conditional return statements in lib/Basic. 2015-10-24 23:15:31 +00:00
CodeGen Allow linking multiple bitcode files. 2015-10-27 17:56:59 +00:00
Driver [mips] Separated mips specific -Wa options, so that they are not checked on other platforms. 2015-10-27 18:04:42 +00:00
Edit Replace double negation of !FileID.isInvalid() with FileID.isValid(). 2015-10-03 10:46:20 +00:00
Format clang-format: Undo unwanted format change done in r251405. 2015-10-27 13:42:08 +00:00
Frontend Allow linking multiple bitcode files. 2015-10-27 17:56:59 +00:00
FrontendTool Provide a BuryPointer for unique_ptrs. 2014-08-29 16:53:14 +00:00
Headers Handle target builtin options that are all required rather than 2015-10-27 06:11:03 +00:00
Index Roll-back r250822. 2015-10-20 13:23:58 +00:00
Lex Define weak and __weak to mean ARC-style weak references, even in MRC. 2015-10-22 18:38:17 +00:00
Parse [coroutines] Creation of promise object, lookup of operator co_await, building 2015-10-27 06:02:45 +00:00
Rewrite Roll-back r250822. 2015-10-20 13:23:58 +00:00
Sema Tweak how -Wunused-value interacts with macros 2015-10-27 19:47:40 +00:00
Serialization [coroutines] Creation of promise object, lookup of operator co_await, building 2015-10-27 06:02:45 +00:00
StaticAnalyzer [analyzer] Fix lambdas that are capturing constants. 2015-10-27 13:46:39 +00:00
Tooling Unbreak the shared cmake build. libToolingCore now depends on libAST. 2015-10-22 15:45:54 +00:00
CMakeLists.txt Fix build with various feature flag combinations 2014-07-14 22:17:22 +00:00
Makefile Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00