From 5ef8aefaba448c0833e34737c2a25d9aaaff0f36 Mon Sep 17 00:00:00 2001 From: Daniel Marjamaki Date: Wed, 2 Aug 2017 08:26:56 +0000 Subject: [PATCH] [StaticAnalyzer] Fix false positives for unreachable code in macros. Example: #define MACRO(C) if (C) { static int x; .. } void foo() { MACRO(0); } Differential Revision: https://reviews.llvm.org/D36141 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309799 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp | 2 +- test/Analysis/unreachable-code-path.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp index ccd8e9a18b..6f21e868b1 100644 --- a/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -112,7 +112,7 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, continue; // Check for false positives - if (CB->size() > 0 && isInvalidPath(CB, *PM)) + if (isInvalidPath(CB, *PM)) continue; // It is good practice to always have a "default" label in a "switch", even diff --git a/test/Analysis/unreachable-code-path.c b/test/Analysis/unreachable-code-path.c index ff58587be2..effa4d9bfa 100644 --- a/test/Analysis/unreachable-code-path.c +++ b/test/Analysis/unreachable-code-path.c @@ -213,3 +213,13 @@ void macro(void) { RETURN(1); // no-warning } +// Avoid FP when macro argument is known +void writeSomething(int *x); +#define MACRO(C) \ + if (!C) { \ + static int x; \ + writeSomething(&x); \ + } +void macro2(void) { + MACRO(1); +} -- 2.40.0