Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

scan-build crashes during postprocessing if BUGFILE no longer exists #14096

Closed Quuxplusone closed 10 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR14061
Status RESOLVED FIXED
Importance P normal
Reported by Matti Niemenmaa (matti.niemenmaa+llvmbugs@iki.fi)
Reported on 2012-10-11 00:51:29 -0700
Last modified on 2014-07-17 03:49:50 -0700
Version trunk
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, pawel@32bitmicro.com, sylvestre@debian.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
If a file in which the static analyzer found a bug no longer exists when scan-
build does its postprocessing over the report* files, scan-build exits
unceremoniously with a message like the following:

Use of uninitialized value $_[0] in substitution (s///) at
/usr/share/perl5/core_perl/File/Basename.pm line 341, <IN> line 63.
fileparse(): need a valid pathname at /path/to/scan-build line 247

The root cause is abs_path returning undef if the path no longer exists. I
propose the following simple fix (patch based on the git mirror but simple
enough):

diff --git i/tools/scan-build/scan-build w/tools/scan-build/scan-build
index a13b235..3ed6e3f 100755
--- i/tools/scan-build/scan-build
+++ w/tools/scan-build/scan-build
@@ -363,6 +363,10 @@ sub ScanFile {
     }
     elsif (/<!-- BUGFILE (.*) -->$/) {
       $BugFile = abs_path($1);
+      if (!defined $BugFile) {
+         # The file no longer exists: use the original path.
+         $BugFile = $1;
+      }
       UpdatePrefix($BugFile);
     }
     elsif (/<!-- BUGPATHLENGTH (.*) -->$/) {

I ran into this whilst using the tup build system ( http://gittup.org/tup/ ),
which uses temporary FUSE file systems to determine what files are accessed by
the compiler. Thus I'd end up with BUGFILE lines such as:

<!-- BUGFILE /path/to/project/.tup/mnt/@tupjob-1234/path/to/project/src.c -->

Handling those properly would require some tup-specific recognition in scan-
build and most likely isn't worth the trouble, but fixing the crash might be
helpful for other situations as well. (E.g. somebody inadvertently removes a
source file while scan-build is still running and then doesn't get an
index.html for the scan-build run that took an hour?)

As an aside, the UpdatePrefix function seems to be a bit greedy: it doesn't
compute the common path, it goes specifically for the common prefix. I noticed
that it removes the '@tupjob-' part for my files, so it seems that if all my
source files started with the letter 'a' it would chop off that 'a' when
showing the path in index.html. Maybe it should only compute prefixes that end
with a directory separator.
Quuxplusone commented 10 years ago
Applied in commit r213235.

(I had the same issue with Thunderbird build)
Thanks for the patch and sorry about the delay ...