[PATCH] [analyzer] fix an issue on #include<..> when using scan-build with -isystem

Takeshi Yoshimura yos at sslab.ics.keio.ac.jp
Tue Jun 2 04:43:53 PDT 2015


scan-build fails to perform static analysis if a hooked compilation uses
-isystem options in particular forms. It results in odd build errors,
which include<..>'ed files are not found even though the build before the
static analysis succeeds. This patch addresses a bug reported in PR13237:
https://llvm.org/bugs/show_bug.cgi?id=13237

The fault is a broken regular expression to extract paths after include 
options string in ccc-analyzer. Specifically, the analyzer looks over the
path string after -isystem if we put a space between them. Note that scan-
build already can correctly parse the option when there are no spaces 
between -isystem and the path (e.g., -isystem/path/to/dir/).

I also removed an FIXME near there since I do not think $ARGV[$i] can 
overflow here. $ARGV overflows mean there are no strings after include 
options. It prevents the compilation before static analysis from 
succeeding, i.e., we cannot reach here.

http://reviews.llvm.org/D10182

Files:
  test/Analysis/scan-build-isystem.c
  test/Analysis/scan-build-isystem.h
  tools/scan-build/ccc-analyzer

Index: test/Analysis/scan-build-isystem.c
===================================================================
--- /dev/null
+++ test/Analysis/scan-build-isystem.c
@@ -0,0 +1,10 @@
+// RUN: perl %S/../../tools/scan-build/scan-build --use-analyzer %clang -o %t %clang_cc1 -isystem%S -fsyntax-only %s 2>&1
+// RUN: perl %S/../../tools/scan-build/scan-build --use-analyzer %clang -o %t %clang_cc1 -isystem %S -fsyntax-only %s 2>&1
+// ccc-analyzer has to correctly look up and include -isystem directory to avoid static analysis failures in scan-build.
+
+#include <scan-build-isystem.h>
+
+void f() {
+  int * i = 0;
+  *i = 1; // CHECK: Dereference of null pointer
+}
Index: test/Analysis/scan-build-isystem.h
===================================================================
--- /dev/null
+++ test/Analysis/scan-build-isystem.h
@@ -0,0 +1 @@
+// dummy file
\ No newline at end of file
Index: tools/scan-build/ccc-analyzer
===================================================================
--- tools/scan-build/ccc-analyzer
+++ tools/scan-build/ccc-analyzer
@@ -576,10 +576,9 @@
   }
 
   # Compile mode flags.
-  if ($Arg =~ /^-[D,I,U,isystem](.*)$/) {
+  if ($Arg =~ /^-[D,I,U](.*)$/ || $Arg =~ /^-isystem(.*)$/) {
     my $Tmp = $Arg;
     if ($1 eq '') {
-      # FIXME: Check if we are going off the end.
       ++$i;
       $Tmp = $Arg . $ARGV[$i];
     }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10182.26964.patch
Type: text/x-patch
Size: 1363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150602/6e378344/attachment.bin>


More information about the cfe-commits mailing list