[clang] [clang][analyzer] scan-build: Ensure path prefixes exist (PR #71053)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 05:18:44 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

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


More information about the cfe-commits mailing list