aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-26[StaticAnalyzer] Remove unused includes (NFC) (#141525)Kazu Hirata1-4/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-03-18Reapply "[analyzer] Delay the checker constructions after parsing" (#128369)Balazs Benics1-10/+8
Reapply "[analyzer] Delay the checker constructions after parsing" (#128350) This reverts commit db836edf47f36ed04cab919a7a2c4414f4d0d7e6, as-is. Depends on #128368
2025-03-17[analyzer] Introduce per-entry-point statistics (#131175)Arseniy Zaostrovnykh1-12/+22
So far CSA was relying on the LLVM Statistic package that allowed us to gather some data about analysis of an entire translation unit. However, the translation unit consists of a collection of loosely related entry points. Aggregating data across multiple such entry points is often counter productive. This change introduces a new lightweight always-on facility to collect Boolean or numerical statistics for each entry point and dump them in a CSV format. Such format makes it easy to aggregate data across multiple translation units and analyze it with common data-processing tools. We break down the existing statistics that were collected on the per-TU basis into values per entry point. Additionally, we enable the statistics unconditionally (STATISTIC -> ALWAYS_ENABLED_STATISTIC) to facilitate their use (you can gather the data with a simple run-time flag rather than having to recompile the analyzer). These statistics are very light and add virtually no overhead. Co-authored-by: Balazs Benics <benicsbalazs@gmail.com> CPP-6160
2025-02-24[analyzer] Clean up slightly the messed up ownership model of the analyzer ↵Balazs Benics1-10/+11
(#128368) Well, yes. It's not pretty. At least after this we would have a bit more unique pointers than before. This is for fixing the memory leak diagnosed by: https://lab.llvm.org/buildbot/#/builders/24/builds/5580 And that caused the revert of #127409. After these uptrs that patch can re-land finally.
2025-02-22Revert "[analyzer] Delay the checker constructions after parsing" (#128350)Balazs Benics1-8/+10
Reverts llvm/llvm-project#127409 This caused a test failure: LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot11` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/55/builds/7431 <details> <summary>Here is the relevant piece of the build log for the reference</summary> ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 86643 tests, 72 workers -- Testing: FAIL: Clang :: Analysis/cxx11-crashes.cpp (1006 of 86643) ******************** TEST 'Clang :: Analysis/cxx11-crashes.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/cxx11-crashes.cpp.script: line 1: 1936960 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp -- ******************** Testing: FAIL: Clang :: Analysis/stack-block-returned.cpp (1505 of 86643) ******************** TEST 'Clang :: Analysis/stack-block-returned.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/stack-block-returned.cpp.script: line 1: 1940139 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp -- ******************** Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Slowest Tests: -------------------------------------------------------------------------- 59.70s: Clang :: Driver/fsanitize.c 48.34s: Clang :: Preprocessor/riscv-target-features.c 41.66s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp 40.68s: Clang :: OpenMP/target_update_codegen.cpp 39.21s: Clang :: Driver/arm-cortex-cpus-2.c 38.19s: Clang :: Driver/arm-cortex-cpus-1.c 36.55s: Clang :: Preprocessor/arm-target-features.c Step 11 (stage2/hwasan check) failure: stage2/hwasan check (failure) ... llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 86643 tests, 72 workers -- Testing: FAIL: Clang :: Analysis/cxx11-crashes.cpp (1006 of 86643) ******************** TEST 'Clang :: Analysis/cxx11-crashes.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/cxx11-crashes.cpp.script: line 1: 1936960 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp -- ******************** Testing: FAIL: Clang :: Analysis/stack-block-returned.cpp (1505 of 86643) ******************** TEST 'Clang :: Analysis/stack-block-returned.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/stack-block-returned.cpp.script: line 1: 1940139 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp -- ******************** Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Slowest Tests: -------------------------------------------------------------------------- 59.70s: Clang :: Driver/fsanitize.c 48.34s: Clang :: Preprocessor/riscv-target-features.c 41.66s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp 40.68s: Clang :: OpenMP/target_update_codegen.cpp 39.21s: Clang :: Driver/arm-cortex-cpus-2.c 38.19s: Clang :: Driver/arm-cortex-cpus-1.c 36.55s: Clang :: Preprocessor/arm-target-features.c ``` </details>
2025-02-22[analyzer] Delay the checker constructions after parsing (#127409)Balazs Benics1-10/+8
If we were to delay checker constructions after we have a filled ASTContext, then we could get rid of a bunch of "lazy initializers" in checkers. Turns out in the register functions of the checkers we could transfer the ASTContext and all other things to checkers, so those could benefit from in-class initializers and const fields. For example, if a checker would take the ASTContext as the first field, then the rest of the fields could use it in their in-class initializers, so the ctor of the checker would only need to set a single field! This would open uup countless opportunities for cleaning up the asthetics of our checkers. I attached a single use-case for the AST and the PP as demonstrating purposes. You can imagine the rest. **FYI: This may be a breaking change** to some downstream users that may had some means to attach different listeners and what not to e.g. the Preprocessor inside their checker register functions. Since we delay the calls to these register fns after parsing is already done, they would of course miss the parsing Preprocessor events.
2025-02-05[analyzer] Add time-trace scopes for high-level analyzer steps (#125508)Arseniy Zaostrovnykh1-8/+37
Specifically, add a scope for - each work-list step, - each entry point, - each checker run within a step, and - bug-suppression phase at the end of the analysis of an entry-point. These scopes add no perceptible run-time overhead when time-tracing is disabled. You can enable it and generate a time trace using the `-ftime-trace=file.json` option. See also the RFC: https://discourse.llvm.org/t/analyzer-rfc-ftime-trace-time-scopes-for-steps-and-entry-points/84343 -- CPP-6065
2024-11-15[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use ↵Sirraide1-10/+10
DynamicRecursiveASTVisitor (#115144) This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and `StaticAnalysis` to inherit from DRAV instead. This is over half of the visitors that inherit from RAV directly. See also #115132, #110040, #93462 LLVM Compile-Time Tracker link for this branch: https://llvm-compile-time-tracker.com/compare.php?from=5adb5c05a2e9f31385fbba8b0436cbc07d91a44d&to=b58e589a86c06ba28d4d90613864d10be29aa5ba&stat=instructions%3Au
2024-03-25[analyzer] Set and display CSA analysis entry points as notes on debugging ↵Balazs Benics1-1/+3
(#84823) When debugging CSA issues, sometimes it would be useful to have a dedicated note for the analysis entry point, aka. the function name you would need to pass as "-analyze-function=XYZ" to reproduce a specific issue. One way we use (or will use) this downstream is to provide tooling on top of creduce to enhance to supercharge productivity by automatically reduce cases on crashes for example. This will be added only if the "-analyzer-note-analysis-entry-points" is set or the "analyzer-display-progress" is on. This additional entry point marker will be the first "note" if enabled, with the following message: "[debug] analyzing from XYZ". They are prefixed by "[debug]" to remind the CSA developer that this is only meant to be visible for them, for debugging purposes. CPP-5012
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-09-05[clang] NFCI: Change returned AnalyzerOptions smart pointer to referenceJan Svoboda1-30/+30
2022-11-28[analyzer] Remove the unused LocalCheckers.h headerBalazs Benics1-1/+0
2022-06-15[analyzer][NFC] Remove dead code and modernize surroundingsBalazs Benics1-1/+0
Thanks @kazu for helping me clean these parts in D127799. I'm leaving the dump methods, along with the unused visitor handlers and the forwarding methods. The dead parts actually helped to uncover two bugs, to which I'm going to post separate patches. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D127836
2022-06-14Reland "[analyzer] Deprecate `-analyzer-store region` flag"Balazs Benics1-7/+1
I'm trying to remove unused options from the `Analyses.def` file, then merge the rest of the useful options into the `AnalyzerOptions.def`. Then make sure one can set these by an `-analyzer-config XXX=YYY` style flag. Then surface the `-analyzer-config` to the `clang` frontend; After all of this, we can pursue the tablegen approach described https://discourse.llvm.org/t/rfc-tablegen-clang-static-analyzer-engine-options-for-better-documentation/61488 In this patch, I'm proposing flag deprecations. We should support deprecated analyzer flags for exactly one release. In this case I'm planning to drop this flag in `clang-16`. In the clang frontend, now we won't pass this option to the cc1 frontend, rather emit a warning diagnostic reminding the users about this deprecated flag, which will be turned into error in clang-16. Unfortunately, I had to remove all the tests referring to this flag, causing a mass change. I've also added a test for checking this warning. I've seen that `scan-build` also uses this flag, but I think we should remove that part only after we turn this into a hard error. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D126215
2022-06-10Revert "[analyzer] Deprecate `-analyzer-store region` flag"Nico Weber1-1/+7
This reverts commit d50d9946d1d7e5f20881f0bc71fbd025040b1c96. Broke check-clang, see comments on https://reviews.llvm.org/D126067 Also revert dependent change "[analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag" This reverts commit 07b4a6d0461fe64e10d30029ed3d598e49ca3810. Also revert "[analyzer] Fix buildbots after introducing a new frontend warning" This reverts commit 90374df15ddc58d823ca42326a76f58e748f20eb. (See https://reviews.llvm.org/rG90374df15ddc58d823ca42326a76f58e748f20eb)
2022-06-10[analyzer] Deprecate `-analyzer-store region` flagBalazs Benics1-7/+1
I'm trying to remove unused options from the `Analyses.def` file, then merge the rest of the useful options into the `AnalyzerOptions.def`. Then make sure one can set these by an `-analyzer-config XXX=YYY` style flag. Then surface the `-analyzer-config` to the `clang` frontend; After all of this, we can pursue the tablegen approach described https://discourse.llvm.org/t/rfc-tablegen-clang-static-analyzer-engine-options-for-better-documentation/61488 In this patch, I'm proposing flag deprecations. We should support deprecated analyzer flags for exactly one release. In this case I'm planning to drop this flag in `clang-16`. In the clang frontend, now we won't pass this option to the cc1 frontend, rather emit a warning diagnostic reminding the users about this deprecated flag, which will be turned into error in clang-16. Unfortunately, I had to remove all the tests referring to this flag, causing a mass change. I've also added a test for checking this warning. I've seen that `scan-build` also uses this flag, but I think we should remove that part only after we turn this into a hard error. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D126215
2022-05-18[clang][analyzer][ctu] Make CTU a two phase analysisGabor Marton1-0/+12
This new CTU implementation is the natural extension of the normal single TU analysis. The approach consists of two analysis phases. During the first phase, we do a normal single TU analysis. During this phase, if we find a foreign function (that could be inlined from another TU) then we don’t inline that immediately, we rather mark that to be analysed later. When the first phase is finished then we start the second phase, the CTU phase. In this phase, we continue the analysis from that point (exploded node) which had been enqueued during the first phase. We gradually extend the exploded graph of the single TU analysis with the new node that was created by the inlining of the foreign function. We count the number of analysis steps of the first phase and we limit the second (ctu) phase with this number. This new implementation makes it convenient for the users to run the single-TU and the CTU analysis in one go, they don't need to run the two analysis separately. Thus, we name this new implementation as "onego" CTU. Discussion: https://discourse.llvm.org/t/rfc-much-faster-cross-translation-unit-ctu-analysis-implementation/61728 Differential Revision: https://reviews.llvm.org/D123773
2022-04-01[analyzer][ctu] Only import const and trivial VarDeclsGabor Marton1-1/+1
Do import the definition of objects from a foreign translation unit if that's type is const and trivial. Differential Revision: https://reviews.llvm.org/D122805
2022-02-16Revert "Revert "[analyzer] Prevent misuses of -analyze-function""Balazs Benics1-0/+30
This reverts commit 620d99b7edc64ee87b1ce209f179305e6a919006. Let's see if removing the two offending RUN lines makes this patch pass. Not ideal to drop tests but, it's just a debugging feature, probably not that important.
2022-02-08Revert "[analyzer] Prevent misuses of -analyze-function"Balazs Benics1-30/+0
This reverts commit 841817b1ed26c1fbb709957d54c0e2751624fbf8. Ah, it still fails on build bots for some reason. Pinning the target triple was not enough.
2022-02-08[analyzer] Prevent misuses of -analyze-functionBalazs Benics1-0/+30
Sometimes when I pass the mentioned option I forget about passing the parameter list for c++ sources. It would be also useful newcomers to learn about this. This patch introduces some logic checking common misuses involving `-analyze-function`. Reviewed-By: martong Differential Revision: https://reviews.llvm.org/D118690
2022-02-07[NFC][Analyzer] Use range based for loop.Jun Zhang1-6/+4
Use range base loop loop to improve code readability. Differential Revision: https://reviews.llvm.org/D119103
2022-02-02Revert "[analyzer] Prevent misuses of -analyze-function"Balazs Benics1-30/+0
This reverts commit 9d6a6159730171bc0faf78d7f109d6543f4c93c2. Exit Code: 1 Command Output (stderr): -- /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/Analysis/analyze-function-guide.cpp:53:21: error: CHECK-EMPTY-NOT: excluded string found in input // CHECK-EMPTY-NOT: Every top-level function was skipped. ^ <stdin>:1:1: note: found here Every top-level function was skipped. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Input file: <stdin> Check file: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/Analysis/analyze-function-guide.cpp -dump-input=help explains the following input dump. Input was: <<<<<< 1: Every top-level function was skipped. not:53 !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match expected 2: Pass the -analyzer-display-progress for tracking which functions are analyzed. >>>>>>
2022-02-02[analyzer] Prevent misuses of -analyze-functionBalazs Benics1-0/+30
Sometimes when I pass the mentioned option I forget about passing the parameter list for c++ sources. It would be also useful newcomers to learn about this. This patch introduces some logic checking common misuses involving `-analyze-function`. Reviewed-By: martong Differential Revision: https://reviews.llvm.org/D118690
2022-01-09[clang] Fix bugprone argument comments (NFC)Kazu Hirata1-1/+1
Identified with bugprone-argument-comment.
2021-12-06[analyzer] Ignore flex generated filesBalazs Benics1-19/+28
Some projects [1,2,3] have flex-generated files besides bison-generated ones. Unfortunately, the comment `"/* A lexical scanner generated by flex */"` generated by the tools is not necessarily at the beginning of the file, thus we need to quickly skim through the file for this needle string. Luckily, StringRef can do this operation in an efficient way. That being said, now the bison comment is not required to be at the very beginning of the file. This allows us to detect a couple more cases [4,5,6]. Alternatively, we could say that we only allow whitespace characters before matching the bison/flex header comment. That would prevent the (probably) unnecessary string search in the buffer. However, I could not verify that these tools would actually respect this assumption. Additionally to this, e.g. the Twin project [1] has other non-whitespace characters (some preprocessor directives) before the flex-generated header comment. So the heuristic in the previous paragraph won't work with that. Thus, I would advocate the current implementation. According to my measurement, this patch won't introduce measurable performance degradation, even though we will do 2 linear scans. I introduce the ignore-bison-generated-files and ignore-flex-generated-files to disable skipping these files. Both of these options are true by default. [1]: https://github.com/cosmos72/twin/blob/master/server/rcparse_lex.cpp#L7 [2]: https://github.com/marcauresoar/make-examples/blob/22362cdcf9dd7c597b5049ce7f176621e2e9ac7a/sandbox/count-words/lexer.c#L6 [3]: https://github.com/vladcmanea/2nd-faculty-year-Formal-Languages---Automata-assignments/blob/11abdf64629d9eb741438ba69f04636769d5a374/lab1/lex.yy.c#L6 [4]: https://github.com/KritikaChoudhary/System-Software-Lab/blob/47f5b2cfe2a2738fd54eae9f8439817f6a22034e/B_yacc/1/y1.tab.h#L2 [5]: https://github.com/VirtualMonitor/VirtualMonitor/blob/71d1bf9b1e7b392a7bd0c73dc217138dc5865651/src/VBox/Additions/x11/x11include/xorg-server-1.8.0/parser.h#L2 [6]: https://github.com/bspaulding/DrawTest/blob/3f773ceb13de14275429036b9cbc5aa19e29bab9/Framework/OpenEars.framework/Versions/A/Headers/jsgf_parser.h#L2 Reviewed By: xazax.hun Differential Revision: https://reviews.llvm.org/D114510
2021-11-29[analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()Balazs Benics1-9/+17
I just read this part of the code, and I found the nested ifs less readable. Reviewed By: martong Differential Revision: https://reviews.llvm.org/D114441
2021-07-13[analyzer] Print time taken to analyze each functionSharmaRithik1-7/+33
Summary: This patch is a part of an attempt to obtain more timer data from the analyzer. In this patch, we try to use LLVM::TimeRecord to save time before starting the analysis and to print the time that a specific function takes while getting analyzed. The timer data is printed along with the -analyzer-display-progress outputs. ANALYZE (Syntax): test.c functionName : 0.4 ms ANALYZE (Path, Inline_Regular): test.c functionName : 2.6 ms Authored By: RithikSharma Reviewer: NoQ, xazax.hun, teemperor, vsavchenko Reviewed By: NoQ Differential Revision: https://reviews.llvm.org/D105565
2021-07-12[analyzer][NFC] Display the correct function name even in crash dumpsBalazs Benics1-56/+3
The `-analyzer-display-progress` displayed the function name of the currently analyzed function. It differs in C and C++. In C++, it prints the argument types as well in a comma-separated list. While in C, only the function name is displayed, without the brackets. E.g.: C++: foo(), foo(int, float) C: foo In crash traces, the analyzer dumps the location contexts, but the string is not enough for `-analyze-function` in C++ mode. This patch addresses the issue by dumping the proper function names even in stack traces. Reviewed By: NoQ Differential Revision: https://reviews.llvm.org/D105708
2021-02-22[analyzer] Create MacroExpansionContext member in AnalysisConsumerBalazs Benics1-2/+10
Adds a `MacroExpansionContext` member to the `AnalysisConsumer` class. Tracks macro expansions only if the `ShouldDisplayMacroExpansions` is set. Passes a reference down the pipeline letting AnalysisConsumers query macro expansions during bugreport construction. Reviewed By: martong, Szelethus Differential Revision: https://reviews.llvm.org/D93223
2021-01-08Revert "Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic ↵Alexander Belyaev1-2/+2
consumer implementations to libAnalysis.""""" This reverts commit 6b0ee02747ed22d41e175d15f27025183341e6f8. Circular dependency again.
2021-01-07Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic ↵Artem Dergachev1-2/+2
consumer implementations to libAnalysis."""" This reverts commit b12f26733a4259c90e5f387aceb9f23c35e003b8. Fix dead include that looked like another missed circular dependency.
2021-01-07Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic consumer ↵David Blaikie1-2/+2
implementations to libAnalysis.""" This reverts commit d2ddc694ff94743d9735aaf07edcaf6db8aaca04. This still contains a circular dependency between Analysis and CrossTU: $ grep -r include.*Analysis clang/include/clang/CrossTU clang/include/clang/CrossTU/CrossTranslationUnit.h: #include "clang/Analysis/CrossTUAnalysisHelper.h" $ grep -r include.*CrossTU clang/lib/Analysis clang/lib/Analysis/PlistHTMLPathDiagnosticConsumer.cpp: #include "clang/CrossTU/CrossTranslationUnit.h" clang/lib/Analysis/PlistPathDiagnosticConsumer.cpp: #include "clang/Analysis/CrossTUAnalysisHelper.h"
2021-01-07Revert "Revert "[analyzer] NFC: Move path diagnostic consumer ↵Artem Dergachev1-2/+2
implementations to libAnalysis."" This reverts commit 5663bf201f5c444d6fb56fb1bd471bc53c17d837. The cyclic dependency problem is addressed now. This is the ~fifth attempt to land this change.
2020-12-11Revert "[analyzer] NFC: Move path diagnostic consumer implementations to ↵Haojian Wu1-2/+2
libAnalysis." The patch introduced a cycle dependency: clangAnalysis -> clangFrontend -> clangSema -> clangAnalysis This reverts commit 00ffea77ad887b576e9db82d98c97a31fee172cb. This reverts commit ea6641085d025ca0a5cef940465ef14d0ccace02.
2020-12-10Revert "Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic ↵Artem Dergachev1-2/+2
consumer implementations to libAnalysis."""" This reverts commit 6a89cb8136f3435bd977b419b683dc0acc98e61e.
2020-11-17Revert "Revert "Revert "[analyzer] NFC: Move path diagnostic consumer ↵Artem Dergachev1-2/+2
implementations to libAnalysis.""" This reverts commit 41bcc05e2a4e3062eb12ac6e071bc835decc38f5.
2020-11-17Revert "Revert "[analyzer] NFC: Move path diagnostic consumer ↵Artem Dergachev1-2/+2
implementations to libAnalysis."" This reverts commit 77bb3ebebbca13f0648beb433fbd1b06ba95a19c.
2020-11-16Revert "Revert "[analyzer] NFC: Separate PathDiagnosticConsumer options from ↵Artem Dergachev1-1/+1
AnalyzerOptions."" This reverts commit 10f1ca99b498347186ec74b01046ad292bde9a4c. (cherry picked from commit c599fc738a70e482976c6cc0ea31bef561641279)
2020-10-15clang/StaticAnalyzer: Stop using SourceManager::getBufferDuncan P. N. Exon Smith1-1/+1
Update clang/lib/StaticAnalyzer to stop relying on a `MemoryBuffer*`, using the `MemoryBufferRef` from `getBufferOrNone` or the `Optional<MemoryBufferRef>` from `getBufferOrFake`, depending on whether there's logic for checking validity of the buffer. The change to clang/lib/StaticAnalyzer/Core/IssueHash.cpp is potentially a functionality change, since the logic was wrong (it checked for `nullptr`, which was never returned by the old API), but if that was reachable the new behaviour should be better. Differential Revision: https://reviews.llvm.org/D89414
2020-10-13Revert "[analyzer] NFC: Separate PathDiagnosticConsumer options from ↵Artem Dergachev1-1/+1
AnalyzerOptions." This reverts commit fd4b3f123d6e64769881e4c6351d5bbbdac30ce3.
2020-10-13Revert "[analyzer] NFC: Move path diagnostic consumer implementations to ↵Artem Dergachev1-2/+2
libAnalysis." This reverts commit 44b7cf2983b6a8373c99a9b254f8c3f944e03f35.
2020-10-13[analyzer] NFC: Move path diagnostic consumer implementations to libAnalysis.Artem Dergachev1-2/+2
With this change, we're more or less ready to allow users outside of the Static Analyzer to take advantage of path diagnostic consumers for emitting their warnings in different formats. Differential Revision: https://reviews.llvm.org/D67422
2020-10-13[analyzer] NFC: Separate PathDiagnosticConsumer options from AnalyzerOptions.Artem Dergachev1-1/+1
The AnalyzerOptions object contains too much information that's entirely specific to the Analyzer. It is also being referenced by path diagnostic consumers to tweak their behavior. In order for path diagnostic consumers to function separately from the analyzer, make a smaller options object that only contains relevant options. Differential Revision: https://reviews.llvm.org/D67420
2020-07-02Fix some typos (unkown -> unknown); NFCAaron Ballman1-1/+1
2020-05-22Revert "[analyzer] Change the default output type to PD_TEXT_MINIMAL in the ↵Kirstóf Umann1-1/+0
frontend, error if an output loc is missing for PathDiagConsumers that need it" This reverts commit fe1a3a7e8c8be33968b9a768666489823dabab10.
2020-05-20[analyzer] Change the default output type to PD_TEXT_MINIMAL in the ↵Kirstóf Umann1-0/+1
frontend, error if an output loc is missing for PathDiagConsumers that need it The title and the included test file sums everything up -- the only thing I'm mildly afraid of is whether anyone actually depends on the weird behavior of HTMLDiagnostics pretending to be TextDiagnostics if an output directory is not supplied. If it is, I guess we would need to resort to tiptoeing around the compatibility flag. Differential Revision: https://reviews.llvm.org/D76510
2020-03-26[analyzer] Add the Preprocessor to CheckerManagerKirstóf Umann1-1/+1
2020-03-26Reland "[analyzer][NFC] Tie CheckerRegistry to CheckerManager, allow ↵Kristóf Umann1-3/+2
CheckerManager to be constructed for non-analysis purposes" Originally commited in rG57b8a407493c34c3680e7e1e4cb82e097f43744a, but it broke the modules bot. This is solved by putting the contructors of the CheckerManager class to the Frontend library. Differential Revision: https://reviews.llvm.org/D75360
2020-03-23[analyzer] Delete unneeded headers and using after D76509 for layering checkFangrui Song1-3/+0
Otherwise it is incorrect to remove clangStaticAnalyzerFrontend's dependency on clangRewrite and clangToolingCore.