Skip to content

Commit

Permalink
[StaticAnalyzer] Fix false positives for unreachable code in macros.
Browse files Browse the repository at this point in the history
Example:

#define MACRO(C)   if (C) { static int x; .. }
void foo() {
	MACRO(0);
}

Differential Revision: https://reviews.llvm.org/D36141

llvm-svn: 309799
  • Loading branch information
Daniel Marjamaki committed Aug 2, 2017
1 parent 4115330 commit fabe840
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Analysis/unreachable-code-path.c
Expand Up @@ -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);
}

0 comments on commit fabe840

Please sign in to comment.