llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (amcn)

<details>
<summary>Changes</summary>

scan-build's `UpdatePrefix` calculates the shared prefix of a set of files. Its 
use of strings and regular expressions to do so means that it can sometimes end 
up calculating a prefix which does not correspond to a real directory that 
exists on the filesystem. If such a prefix is calculated, when it is 
subsequently used in the calculation of the paths to files containing bugs in 
the toplevel html report, it can cause incorrect paths to be generated.

This patch fixes this by requiring that a calculated prefix exist in the 
filesystem for it to be considered valid.

I noticed this when using `scan-build` to analyse a project which contains 
several folders each starting with a common prefix. `UpdatePrefix` was 
including this prefix in its calculated prefix, which subsequently caused the 
paths in the report to lack it. I have created a project which can demonstrate 
the issue [here](https://github.com/amcn/scan-build-path-bug-example-repo).


---
Full diff: https://github.com/llvm/llvm-project/pull/71053.diff


1 Files Affected:

- (modified) clang/tools/scan-build/bin/scan-build (+1-1) 


``````````diff
diff --git a/clang/tools/scan-build/bin/scan-build 
b/clang/tools/scan-build/bin/scan-build
index 04734d9cfa9af69..074989ab543af2c 100755
--- a/clang/tools/scan-build/bin/scan-build
+++ b/clang/tools/scan-build/bin/scan-build
@@ -282,7 +282,7 @@ sub UpdatePrefix {
     return;
   }
 
-  chop $Prefix while (!($x =~ /^\Q$Prefix/));
+  chop $Prefix while (!($x =~ /^\Q$Prefix/) || !(-e $Prefix));
 }
 
 sub GetPrefix {

``````````

</details>


https://github.com/llvm/llvm-project/pull/71053
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to