https://github.com/necto updated https://github.com/llvm/llvm-project/pull/242339
>From 4ae804e7d687c9ae72b8979933d588530d5178cc Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Fri, 13 Nov 2026 10:27:27 +0100 Subject: [PATCH 1/9] [analyzer] Add an option to support unity-builds in CSA Unity-build, a.k.a jumbo-build or unified-build is a practice to build multiple C or C++ source files in a single compilation command by including them into a synthetic TU main file using preprocessor `#include` directives. By default CSA would skip all functions in the files that are compiled in this manner because the said functions would not be defined in the "main TU" file, but in "headers", that are really #include'd sources. Add unitybuild-file-extensions option (empty by default) that enables CSA to start analysis of functions defined in #include'd files as long as their extension matches one of the extensions configured. Assisted by GPT-Sol LLM. -- CPP-9564 --- .../StaticAnalyzer/Core/AnalyzerOptions.def | 8 ++ .../Core/PathSensitive/AnalysisManager.h | 19 ++++- .../StaticAnalyzer/Core/AnalysisManager.cpp | 14 ++++ clang/lib/StaticAnalyzer/Core/BugReporter.cpp | 22 ++++-- clang/test/Analysis/analyzer-config.c | 1 + .../Analysis/unitybuild-file-extensions.cpp | 73 +++++++++++++++++++ 6 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 clang/test/Analysis/unitybuild-file-extensions.cpp diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index 90b80e5201aa82..8355867fa2775d 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -227,6 +227,14 @@ ANALYZER_OPTION( "the number of nondeterministic diagnostics than " "\"crosscheck-with-z3-timeout-threshold\" in practice.", 3) +ANALYZER_OPTION( + StringRef, UnityBuildFileExtensions, "unitybuild-file-extensions", + "Semicolon-separated file extensions (including leading dots, e.g. " + "'.cpp;.impl;.c') of included files whose functions are considered " + "analysis entry points, regardless of the including file's name. " + "Empty by default.", + "") + ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile, "report-in-main-source-file", "Whether or not the diagnostic report should be always " diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h index eeb015e26b3ce8..a2187f5ca3406e 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h @@ -20,6 +20,8 @@ #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" namespace clang { @@ -43,6 +45,7 @@ class AnalysisManager : public BugReporterData { ConstraintManagerCreator CreateConstraintMgr; CheckerManager *CheckerMgr; + SmallVector<StringRef> UnityBuildFileExtensions; public: AnalyzerOptions &options; @@ -124,10 +127,22 @@ class AnalysisManager : public BugReporterData { return AnaCtxMgr.getContext(D); } - static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) { + ArrayRef<StringRef> getUnityBuildFileExtensions() const { + return UnityBuildFileExtensions; + } + + static bool isInCodeFile(SourceLocation SL, const SourceManager &SM, + ArrayRef<StringRef> UnityBuildFileExtensions) { if (SM.isInMainFile(SL)) return true; + // Treat configured included source files #include "foo.cpp" same as the + // main file. + StringRef FileName = SM.getFilename(SL); + for (StringRef Extension : UnityBuildFileExtensions) + if (FileName.ends_with(Extension)) + return true; + // Support the "unified sources" compilation method (eg. WebKit) that // involves producing non-header files that include other non-header files. // We should be included directly from a UnifiedSource* file @@ -151,7 +166,7 @@ class AnalysisManager : public BugReporterData { bool isInCodeFile(SourceLocation SL) { const SourceManager &SM = getASTContext().getSourceManager(); - return isInCodeFile(SL, SM); + return isInCodeFile(SL, SM, UnityBuildFileExtensions); } }; diff --git a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp index 8a16716f951b85..f952f43e6f031c 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" +#include "clang/Basic/DiagnosticDriver.h" using namespace clang; using namespace ento; @@ -38,6 +39,19 @@ AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP, PathConsumers(std::move(PDC)), CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr), options(Options) { + SmallVector<StringRef> Extensions; + if (!Options.UnityBuildFileExtensions.empty()) + Options.UnityBuildFileExtensions.split(Extensions, ';'); + for (StringRef Extension : Extensions) { + Extension = Extension.trim(); + if (Extension.empty()) { + ASTCtx.getDiagnostics().Report(diag::err_analyzer_config_invalid_input) + << "unitybuild-file-extensions" << "a non-empty file extension"; + continue; + } + UnityBuildFileExtensions.push_back(Extension); + } + AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd(); AnaCtxMgr.getCFGBuildOptions().OmitImplicitValueInitializers = true; AnaCtxMgr.getCFGBuildOptions().AddCXXDefaultInitExprInAggregates = diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp index d61187055c9af9..cb968f3067509b 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -3297,18 +3297,21 @@ BugReporter::generateDiagnosticForConsumerMap( static PathDiagnosticCallPiece * getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP, - const SourceManager &SMgr) { + const SourceManager &SMgr, + ArrayRef<StringRef> UnityBuildFileExtensions) { SourceLocation CallLoc = CP->callEnter.asLocation(); // If the call is within a macro, don't do anything (for now). if (CallLoc.isMacroID()) return nullptr; - assert(AnalysisManager::isInCodeFile(CallLoc, SMgr) && - "The call piece should not be in a header file."); + assert( + AnalysisManager::isInCodeFile(CallLoc, SMgr, UnityBuildFileExtensions) && + "The call piece should not be in a header file."); // Check if CP represents a path through a function outside of the main file. - if (!AnalysisManager::isInCodeFile(CP->callEnterWithin.asLocation(), SMgr)) + if (!AnalysisManager::isInCodeFile(CP->callEnterWithin.asLocation(), SMgr, + UnityBuildFileExtensions)) return CP; const PathPieces &Path = CP->path; @@ -3318,13 +3321,15 @@ getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP, // Check if the last piece in the callee path is a call to a function outside // of the main file. if (auto *CPInner = dyn_cast<PathDiagnosticCallPiece>(Path.back().get())) - return getFirstStackedCallToHeaderFile(CPInner, SMgr); + return getFirstStackedCallToHeaderFile(CPInner, SMgr, + UnityBuildFileExtensions); // Otherwise, the last piece is in the main file. return nullptr; } -static void resetDiagnosticLocationToMainFile(PathDiagnostic &PD) { +static void resetDiagnosticLocationToMainFile( + PathDiagnostic &PD, ArrayRef<StringRef> UnityBuildFileExtensions) { if (PD.path.empty()) return; @@ -3335,7 +3340,7 @@ static void resetDiagnosticLocationToMainFile(PathDiagnostic &PD) { // We only need to check if the report ends inside headers, if the last piece // is a call piece. if (auto *CP = dyn_cast<PathDiagnosticCallPiece>(LastP)) { - CP = getFirstStackedCallToHeaderFile(CP, SMgr); + CP = getFirstStackedCallToHeaderFile(CP, SMgr, UnityBuildFileExtensions); if (CP) { // Mark the piece. CP->setAsLastInMainSourceFile(); @@ -3391,7 +3396,8 @@ PathSensitiveBugReporter::generateDiagnosticForConsumerMap( const AnalyzerOptions &Opts = getAnalyzerOptions(); for (auto const &P : *Out) if (Opts.ShouldReportIssuesInMainSourceFile && !Opts.AnalyzeAll) - resetDiagnosticLocationToMainFile(*P.second); + resetDiagnosticLocationToMainFile( + *P.second, Eng.getAnalysisManager().getUnityBuildFileExtensions()); return Out; } diff --git a/clang/test/Analysis/analyzer-config.c b/clang/test/Analysis/analyzer-config.c index 6715688ac56ecf..9587117dd3d034 100644 --- a/clang/test/Analysis/analyzer-config.c +++ b/clang/test/Analysis/analyzer-config.c @@ -135,6 +135,7 @@ // CHECK-NEXT: suppress-null-return-paths = true // CHECK-NEXT: track-conditions = true // CHECK-NEXT: track-conditions-debug = false +// CHECK-NEXT: unitybuild-file-extensions = "" // CHECK-NEXT: unix.DynamicMemoryModeling:AddNoOwnershipChangeNotes = true // CHECK-NEXT: unix.DynamicMemoryModeling:ModelAllocationFailure = false // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false diff --git a/clang/test/Analysis/unitybuild-file-extensions.cpp b/clang/test/Analysis/unitybuild-file-extensions.cpp new file mode 100644 index 00000000000000..5e460cb43d7c84 --- /dev/null +++ b/clang/test/Analysis/unitybuild-file-extensions.cpp @@ -0,0 +1,73 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %t/main.cpp +// RUN: not %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-config 'unitybuild-file-extensions=; ;' \ +// RUN: %t/main.cpp 2>&1 | FileCheck %s --check-prefix=EMPTY +// EMPTY: invalid input for analyzer-config option 'unitybuild-file-extensions', that expects a non-empty file extension +// RUN: %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-config 'unitybuild-file-extensions=.cpp;.impl;.c' \ +// RUN: -verify=expected,all-extensions %t/main.cpp +// RUN: %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-config unitybuild-file-extensions=.impl \ +// RUN: -verify=expected,impl-only %t/main.cpp + +//--- foo.cpp +int includedCppFunction(int x) { + if (x == 0) + return 1 / x; // all-extensions-warning{{Division by zero}} + return 0; +} + +// This bug is found through the call from main.cpp, even by the default run. +int calledIncludedCppFunction(int x) { + return 1 / x; // expected-warning{{Division by zero}} +} + +//--- header.h +int headerFunction(int x) { + // .h extension is not included in any of the runs. + if (x == 0) + return 1 / x; // no-warning + return 0; +} + +// This bug is also found through a call from main.cpp, not as an entry point. +int calledHeaderFunction(int x) { + return 1 / x; // expected-warning{{Division by zero}} +} + +//--- file-extensions.impl +int includedImplFunction(int x) { + if (x == 0) + return 1 / x; // all-extensions-warning{{Division by zero}} impl-only-warning{{Division by zero}} + return 0; +} + +//--- file-extensions.c +int includedCFunction(int x) { + if (x == 0) + return 1 / x; // all-extensions-warning{{Division by zero}} + return 0; +} + +//--- main.cpp +// With the empty default, only the main file contributes entry points. +// The configured list also adds included files with matching extensions. +#include "foo.cpp" +#include "header.h" +#include "file-extensions.impl" +#include "file-extensions.c" + +int mainFileFunction(int x) { + if (x == 0) + return 1 / x; // expected-warning{{Division by zero}} + return 0; +} + +int mainFileCaller(bool callHeader) { + if (callHeader) + return calledHeaderFunction(0); + return calledIncludedCppFunction(0); +} >From 2af1bd46f8a922bcdbcf4125a173426c7e100992 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Fri, 13 Nov 2026 16:30:57 +0100 Subject: [PATCH 2/9] Extend test to demonstrate the support for nested included files --- clang/test/Analysis/unitybuild-file-extensions.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clang/test/Analysis/unitybuild-file-extensions.cpp b/clang/test/Analysis/unitybuild-file-extensions.cpp index 5e460cb43d7c84..a9517cf9426f69 100644 --- a/clang/test/Analysis/unitybuild-file-extensions.cpp +++ b/clang/test/Analysis/unitybuild-file-extensions.cpp @@ -14,6 +14,8 @@ // RUN: -verify=expected,impl-only %t/main.cpp //--- foo.cpp +#include "nested.h" + int includedCppFunction(int x) { if (x == 0) return 1 / x; // all-extensions-warning{{Division by zero}} @@ -25,6 +27,17 @@ int calledIncludedCppFunction(int x) { return 1 / x; // expected-warning{{Division by zero}} } +//--- nested.h +#include "nested.cpp" + +//--- nested.cpp +// main.cpp includes this file through foo.cpp and nested.h. +int nestedCppFunction(int x) { + if (x == 0) + return 1 / x; // all-extensions-warning{{Division by zero}} + return 0; +} + //--- header.h int headerFunction(int x) { // .h extension is not included in any of the runs. >From fe4cd1f7c1d94fae3fb6b0f63d3606adeb7b2d2e Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Fri, 13 Nov 2026 17:33:41 +0100 Subject: [PATCH 3/9] Remove the redundant default value description --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index 8355867fa2775d..a266c7d2a5fe97 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -231,8 +231,7 @@ ANALYZER_OPTION( StringRef, UnityBuildFileExtensions, "unitybuild-file-extensions", "Semicolon-separated file extensions (including leading dots, e.g. " "'.cpp;.impl;.c') of included files whose functions are considered " - "analysis entry points, regardless of the including file's name. " - "Empty by default.", + "analysis entry points, regardless of the including file's name. ", "") ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile, >From 0730505b4e5758395d017b630b523d084e57ff49 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Fri, 13 Nov 2026 17:34:30 +0100 Subject: [PATCH 4/9] Mention alternative names of unity builds --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index a266c7d2a5fe97..983154567c3466 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -231,7 +231,11 @@ ANALYZER_OPTION( StringRef, UnityBuildFileExtensions, "unitybuild-file-extensions", "Semicolon-separated file extensions (including leading dots, e.g. " "'.cpp;.impl;.c') of included files whose functions are considered " - "analysis entry points, regardless of the including file's name. ", + "analysis entry points, regardless of the including file's name. " + "This supports unity builds (also called jumbo builds, unified builds, " + "blob builds, amalgamated builds, monolithic builds, conglomerate builds, " + "single compilation units (SCU), single translation units (STU), or " + "unified sources).", "") ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile, >From 7c1ba9f2a293cb2e262ab831614bf914ec6d6581 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Mon, 16 Nov 2026 10:46:11 +0100 Subject: [PATCH 5/9] Remove parens --- .../include/clang/StaticAnalyzer/Core/AnalyzerOptions.def | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index 983154567c3466..ff3c41d1d598df 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -232,10 +232,10 @@ ANALYZER_OPTION( "Semicolon-separated file extensions (including leading dots, e.g. " "'.cpp;.impl;.c') of included files whose functions are considered " "analysis entry points, regardless of the including file's name. " - "This supports unity builds (also called jumbo builds, unified builds, " - "blob builds, amalgamated builds, monolithic builds, conglomerate builds, " - "single compilation units (SCU), single translation units (STU), or " - "unified sources).", + "This practice is also known as unity build, jumbo build, unified build, " + "blob build, amalgamated build, monolithic build, conglomerate build, " + "single compilation unit (SCU), single translation unit (STU), or " + "unified sources.", "") ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile, >From d6809cdd1c006e36993255e85e8f018aac349f82 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Mon, 16 Nov 2026 10:56:05 +0100 Subject: [PATCH 6/9] Document the option in user docs and mention it in release notes --- clang/docs/ReleaseNotes.md | 5 +++++ .../analyzer/user-docs/CommandLineUsage.md | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 14382a06db34c5..42bd354acb3c72 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1550,6 +1550,11 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and #### Improvements +- The user can opt in to analyze functions coming from files participating in + unity or jumbo builds as analysis entry points with + `-analyzer-config unitybuild-file-extensions=<file-extensions>`. + The default behavior is unchanged. + - `unix.StdCLibraryFunctions` now ignores `restrict` qualifiers in C library declarations such as `fopen` when targeting MSVC to avoid false negatives in C99 and later C standards. diff --git a/clang/docs/analyzer/user-docs/CommandLineUsage.md b/clang/docs/analyzer/user-docs/CommandLineUsage.md index 49b556fce336cc..1b80bb8af146f1 100644 --- a/clang/docs/analyzer/user-docs/CommandLineUsage.md +++ b/clang/docs/analyzer/user-docs/CommandLineUsage.md @@ -27,6 +27,24 @@ For project-wide analysis, use a tool such as scan-build or CodeChecker to drive $ scan-build -sarif -o reports make ``` +## Unity builds + +In a unity build (also called a jumbo build or unified-sources build), a source +file includes other source files. By default, the analyzer may not treat +functions in those included files as analysis entry points. Set +`unitybuild-file-extensions` to a semicolon-separated list of extensions to +analyze functions in matching included files as entry points, even when the +files are included through other source files or headers. For example: + +```console +$ clang --analyze -Xclang -analyzer-config -Xclang 'unitybuild-file-extensions=.c;.cc;.cpp;.cxx;.m;.mm' unified.cpp +``` + +Include the leading dot in each extension and quote the value so the shell does +not interpret the semicolons as command separators. The option does not make +functions in included headers entry points unless you explicitly list their +extensions. + ## Comparison of CodeChecker and scan-build The static analyzer is by design a GUI tool originally intended to be consumed by the XCode IDE. >From e7ae092fc7c4cfd4ae9365f6ff0f94c49bc2c859 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Mon, 16 Nov 2026 11:44:17 +0100 Subject: [PATCH 7/9] [NFC] Hide UnityBuildFileExtensions field, remove isInCodeFile overload --- .../Core/PathSensitive/AnalysisManager.h | 13 ++-------- clang/lib/StaticAnalyzer/Core/BugReporter.cpp | 24 +++++++------------ 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h index a2187f5ca3406e..2e3af6902d2f38 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h @@ -127,12 +127,8 @@ class AnalysisManager : public BugReporterData { return AnaCtxMgr.getContext(D); } - ArrayRef<StringRef> getUnityBuildFileExtensions() const { - return UnityBuildFileExtensions; - } - - static bool isInCodeFile(SourceLocation SL, const SourceManager &SM, - ArrayRef<StringRef> UnityBuildFileExtensions) { + bool isInCodeFile(SourceLocation SL) const { + const SourceManager &SM = Ctx.getSourceManager(); if (SM.isInMainFile(SL)) return true; @@ -163,11 +159,6 @@ class AnalysisManager : public BugReporterData { return false; } - - bool isInCodeFile(SourceLocation SL) { - const SourceManager &SM = getASTContext().getSourceManager(); - return isInCodeFile(SL, SM, UnityBuildFileExtensions); - } }; } // enAnaCtxMgrspace diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp index cb968f3067509b..c0ade4e5f85708 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -3297,21 +3297,18 @@ BugReporter::generateDiagnosticForConsumerMap( static PathDiagnosticCallPiece * getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP, - const SourceManager &SMgr, - ArrayRef<StringRef> UnityBuildFileExtensions) { + const AnalysisManager &AMgr) { SourceLocation CallLoc = CP->callEnter.asLocation(); // If the call is within a macro, don't do anything (for now). if (CallLoc.isMacroID()) return nullptr; - assert( - AnalysisManager::isInCodeFile(CallLoc, SMgr, UnityBuildFileExtensions) && - "The call piece should not be in a header file."); + assert(AMgr.isInCodeFile(CallLoc) && + "The call piece should not be in a header file."); // Check if CP represents a path through a function outside of the main file. - if (!AnalysisManager::isInCodeFile(CP->callEnterWithin.asLocation(), SMgr, - UnityBuildFileExtensions)) + if (!AMgr.isInCodeFile(CP->callEnterWithin.asLocation())) return CP; const PathPieces &Path = CP->path; @@ -3321,26 +3318,24 @@ getFirstStackedCallToHeaderFile(PathDiagnosticCallPiece *CP, // Check if the last piece in the callee path is a call to a function outside // of the main file. if (auto *CPInner = dyn_cast<PathDiagnosticCallPiece>(Path.back().get())) - return getFirstStackedCallToHeaderFile(CPInner, SMgr, - UnityBuildFileExtensions); + return getFirstStackedCallToHeaderFile(CPInner, AMgr); // Otherwise, the last piece is in the main file. return nullptr; } -static void resetDiagnosticLocationToMainFile( - PathDiagnostic &PD, ArrayRef<StringRef> UnityBuildFileExtensions) { +static void resetDiagnosticLocationToMainFile(PathDiagnostic &PD, + const AnalysisManager &AMgr) { if (PD.path.empty()) return; PathDiagnosticPiece *LastP = PD.path.back().get(); assert(LastP); - const SourceManager &SMgr = LastP->getLocation().getManager(); // We only need to check if the report ends inside headers, if the last piece // is a call piece. if (auto *CP = dyn_cast<PathDiagnosticCallPiece>(LastP)) { - CP = getFirstStackedCallToHeaderFile(CP, SMgr, UnityBuildFileExtensions); + CP = getFirstStackedCallToHeaderFile(CP, AMgr); if (CP) { // Mark the piece. CP->setAsLastInMainSourceFile(); @@ -3396,8 +3391,7 @@ PathSensitiveBugReporter::generateDiagnosticForConsumerMap( const AnalyzerOptions &Opts = getAnalyzerOptions(); for (auto const &P : *Out) if (Opts.ShouldReportIssuesInMainSourceFile && !Opts.AnalyzeAll) - resetDiagnosticLocationToMainFile( - *P.second, Eng.getAnalysisManager().getUnityBuildFileExtensions()); + resetDiagnosticLocationToMainFile(*P.second, Eng.getAnalysisManager()); return Out; } >From 67672103b7768755da8be1fa1fc8079facad2240 Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Mon, 16 Nov 2026 12:47:51 +0100 Subject: [PATCH 8/9] Remove SCU and STU abbreviation from description --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def index ff3c41d1d598df..d253a18ee4fd83 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def +++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def @@ -234,8 +234,7 @@ ANALYZER_OPTION( "analysis entry points, regardless of the including file's name. " "This practice is also known as unity build, jumbo build, unified build, " "blob build, amalgamated build, monolithic build, conglomerate build, " - "single compilation unit (SCU), single translation unit (STU), or " - "unified sources.", + "single compilation unit, single translation unit, or unified sources.", "") ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile, >From 0dce474a359aa4408244304f8558a32af104820a Mon Sep 17 00:00:00 2001 From: Arseniy Zaostrovnykh <[email protected]> Date: Mon, 16 Nov 2026 15:58:42 +0100 Subject: [PATCH 9/9] Apply batched suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: DonĂ¡t Nagy <[email protected]> --- clang/docs/analyzer/user-docs/CommandLineUsage.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clang/docs/analyzer/user-docs/CommandLineUsage.md b/clang/docs/analyzer/user-docs/CommandLineUsage.md index 1b80bb8af146f1..92ed94a9d12b33 100644 --- a/clang/docs/analyzer/user-docs/CommandLineUsage.md +++ b/clang/docs/analyzer/user-docs/CommandLineUsage.md @@ -30,7 +30,7 @@ $ scan-build -sarif -o reports make ## Unity builds In a unity build (also called a jumbo build or unified-sources build), a source -file includes other source files. By default, the analyzer may not treat +file includes other source files. By default, the analyzer never treats functions in those included files as analysis entry points. Set `unitybuild-file-extensions` to a semicolon-separated list of extensions to analyze functions in matching included files as entry points, even when the @@ -41,9 +41,7 @@ $ clang --analyze -Xclang -analyzer-config -Xclang 'unitybuild-file-extensions=. ``` Include the leading dot in each extension and quote the value so the shell does -not interpret the semicolons as command separators. The option does not make -functions in included headers entry points unless you explicitly list their -extensions. +not interpret the semicolons as command separators. ## Comparison of CodeChecker and scan-build _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
