[scan-build] Fix clang++ pathname again
authorStephan Bergmann <sbergman@redhat.com>
Thu, 15 Oct 2020 16:10:22 +0000 (18:10 +0200)
committerStephan Bergmann <sbergman@redhat.com>
Tue, 3 Nov 2020 07:17:17 +0000 (08:17 +0100)
e00629f777d9d62875730f40d266727df300dbb2 "[scan-build] Fix clang++ pathname" had
removed the -MAJOR.MINOR suffix, but since presumably LLVM 7 the suffix is only
-MAJOR, so ClangCXX (i.e., the CLANG_CXX environment variable passed to
clang/tools/scan-build/libexec/ccc-analyzer) now contained a non-existing
/path/to/clang-12++ (which apparently went largely unnoticed as
clang/tools/scan-build/libexec/ccc-analyzer falls back to just 'clang++' if the
executable denoted by CLANG_CXX does not exist).

For the new clang/test/Analysis/scan-build/cxx-name.test to be effective,
%scan-build must now take care to pass the clang executable's resolved pathname
(i.e., ending in .../clang-MAJOR rather than just .../clang) to --use-analyzer.

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

clang/test/Analysis/scan-build/cxx-name.test [new file with mode: 0644]
clang/test/Analysis/scan-build/lit.local.cfg
clang/tools/scan-build/bin/scan-build

diff --git a/clang/test/Analysis/scan-build/cxx-name.test b/clang/test/Analysis/scan-build/cxx-name.test
new file mode 100644 (file)
index 0000000..483762d
--- /dev/null
@@ -0,0 +1,9 @@
+REQUIRES: shell
+
+RUN: %scan-build sh -c 'echo "CLANG_CXX=/$(basename "$CLANG_CXX")/"' | FileCheck %s
+
+Check that scan-build sets the CLANG_CXX environment variable (meant to be
+consumed by ccc-analyzer) to an appropriate pathname for the clang++ executable,
+derived from the pathname of the clang executable:
+
+CHECK: CLANG_CXX=/clang++{{(\.exe)?}}/
index b4e097d..09ed921 100644 (file)
@@ -15,4 +15,4 @@ config.substitutions.append(('%scan-build',
                                                     'tools',
                                                     'scan-build',
                                                     'bin')),
-                                 config.clang)))
+                                 os.path.realpath(config.clang))))
index aed8c41..645f550 100755 (executable)
@@ -1925,7 +1925,7 @@ if ($Clang !~ /\+\+(\.exe)?$/) {
     $ClangCXX =~ s/.exe$/++.exe/;
   }
   else {
-    $ClangCXX =~ s/\-\d+\.\d+$//;
+    $ClangCXX =~ s/\-\d+(\.\d+)?$//;
     $ClangCXX .= "++";
   }
 }