From 6615f2b3d673e422789287bb7ae097df00ca32a1 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 5 Apr 2017 14:07:21 +0000 Subject: -Wunreachable-code: 'true' and 'false' should not be treated as configuration macros Clang should emit -Wunreachable-code warnings in C mode for code that's unreachable because of a 'false' or '!true' condition. llvm-svn: 299541 --- clang/lib/Analysis/ReachableCode.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'clang/lib/Analysis/ReachableCode.cpp') diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp index a2f3203..8a96744 100644 --- a/clang/lib/Analysis/ReachableCode.cpp +++ b/clang/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; } -- cgit v1.1