diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index a2f3203762f7662d57bb02530acf3fc575efed98..8a9674484a5f7a9733d8df275097e3a0df0a56d6 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -132,15 +132,21 @@ static bool isExpandedFromConfigurationMacro(const Stmt *S, // so that we can refine it later. SourceLocation L = S->getLocStart(); if (L.isMacroID()) { + SourceManager &SM = PP.getSourceManager(); if (IgnoreYES_NO) { // The Objective-C constant 'YES' and 'NO' // are defined as macros. Do not treat them // as configuration values. - SourceManager &SM = PP.getSourceManager(); SourceLocation TopL = getTopMostMacro(L, SM); StringRef MacroName = PP.getImmediateMacroName(TopL); if (MacroName == "YES" || MacroName == "NO") return false; + } else if (!PP.getLangOpts().CPlusPlus) { + // Do not treat C 'false' and 'true' macros as configuration values. + SourceLocation TopL = getTopMostMacro(L, SM); + StringRef MacroName = PP.getImmediateMacroName(TopL); + if (MacroName == "false" || MacroName == "true") + return false; } return true; } diff --git a/test/Sema/warn-unreachable.c b/test/Sema/warn-unreachable.c index 34e0296a20490405310c8761bbd236df91850c45..1f7921610b9b1def95cd6b731d926a0d71369f76 100644 --- a/test/Sema/warn-unreachable.c +++ b/test/Sema/warn-unreachable.c @@ -451,3 +451,13 @@ void unaryOpFixitCastSubExpr(int x) { // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:")" unaryOpFixitCastSubExpr(x); // expected-warning {{code will never be executed}} } + +#define false 0 +#define true 1 + +void testTrueFalseMacros() { + if (false) // expected-note {{silence by adding parentheses to mark code as explicitly dead}} + testTrueFalseMacros(); // expected-warning {{code will never be executed}} + if (!true) // expected-note {{silence by adding parentheses to mark code as explicitly dead}} + testTrueFalseMacros(); // expected-warning {{code will never be executed}} +}