This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Teach scan-build how to rebuild index.html without analyzing.
ClosedPublic

Authored by NoQ on Feb 12 2020, 12:46 AM.

Details

Summary

This is useful for performing custom build system integration that works by appending '--analyze --analyzer-output html' to all clang build commands. In this case there is now still a way to have a fancy index.html with the output.

Diff Detail

Event Timeline

NoQ created this revision.Feb 12 2020, 12:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2020, 12:46 AM
NoQ marked an inline comment as done.Feb 12 2020, 12:48 AM
NoQ added inline comments.
clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
12–13

The script is indeed capable of finding html reports in sub-directories and it's a fairly useful feature because in a custom build system integration it's likely that clang's -o flag will be very messed up.

Charusso accepted this revision.Feb 12 2020, 1:42 AM

Thanks! I would mention in the Summary the necessary flags to perform index-only output. (May write some release notes?)

That option sounds very strange, but I like it. For example to run only necessary custom tests one could write:

-analyzer-checker=core,unix,custom.checkers \
-analyzer-config silence-checkers="core;unix"
clang/tools/scan-build/bin/scan-build
953

May inject Diag "Analysis run complete.\n"; here?

976

If we stick to printing information to the user: Diag "No bugs found.\n"?.

1302

What about --index-only?

1617

I may smash this duplicated error-handling above in one if-stmt, given that the options are correlate with each other.

This revision is now accepted and ready to land.Feb 12 2020, 1:42 AM
NoQ marked 6 inline comments as done.Feb 17 2020, 10:17 PM
NoQ added inline comments.
clang/tools/scan-build/bin/scan-build
953

Indeed!

976

We already kind of have it when it says "deleting output directory because it contains no reports".

1302

Renamed to --generate-index-only :)

1617

Dunno, i'd rather keep the structure. The function is huge, i'd rather keep it well-structured, and "each option is handled in exactly once if-statement" is good for it.

This revision was automatically updated to reflect the committed changes.
NoQ reopened this revision.Feb 17 2020, 10:53 PM
NoQ marked 2 inline comments as done.

Reverted due to a lot of buildbot failures, eg. http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/62758/steps/test-check-all/logs/stdio

$ "/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm-project/clang/tools/scan-build/bin/scan-build" "--use-analyzer=/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/build/bin/clang" "--generate-index-only" "/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/build/tools/clang/test/Analysis/scan-build/rebuild_index/Output/rebuild_index.test.tmp.output_dir"
# command output:
scan-build: Analysis run complete.
scan-build: 3 bugs found.
scan-build: Run 'scan-view /home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/build/tools/clang/test/Analysis/scan-build/rebuild_index/Output/rebuild_index.test.tmp.output_dir' to examine bug reports.

$ ":" "RUN: at line 16"
$ "ls" "/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/build/tools/clang/test/Analysis/scan-build/rebuild_index/Output/rebuild_index.test.tmp.output_dir"
$ "/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/build/bin/FileCheck" "-check-prefix" "CHECK-FILES" "/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm-project/clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test"
# command stderr:
/home/buildslave/ps4-buildslave4/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/llvm-project/clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test:19:19: error: CHECK-FILES-NEXT: expected string not found in input
CHECK-FILES-NEXT: report-1.html
                  ^
<stdin>:2:1: note: scanning from here
report-2.html
^

error: command failed with exit status: 1

Weird, all three bugs found but report-1 is not present, is it just that ls doesn't sort the output or is it about our deduplication removing a different duplicate?..

This revision is now accepted and ready to land.Feb 17 2020, 10:53 PM

That is very unfortunate, but may if you could introduce a bullet-proof ls we could see if the scan-build sub-directory removal is non-alphabetical. I think the latter smells more badly.

clang/test/Analysis/scan-build/rebuild_index/rebuild_index.test
16

If you think that the ls is the problem may we need ls -R to print out every folder. (https://explainshell.com/explain?cmd=ls+-R)

There are more exotic ways to sort the order, like LANG=C ls: https://stackoverflow.com/questions/878249/unixs-ls-sort-by-name/878269

Could you mention how to use this feature in the Summary please?

cd reports
scan-build --generate-index-only .

And something is not right, I have tried it:

Use of uninitialized value $Clang in concatenation (.) or string at /llvm-project/clang/tools/scan-build/bin/scan-build line 1895.
sh: 1: : Permission denied

But it made the index.html and works like a charm.

NoQ added a comment.Mar 4 2020, 8:08 AM

Could you mention how to use this feature in the Summary please?

cd reports
scan-build --generate-index-only .

Yup, this was supposed to work.

And something is not right, I have tried it:

Use of uninitialized value $Clang in concatenation (.) or string at /llvm-project/clang/tools/scan-build/bin/scan-build line 1895.

Uh-oh. Does this still show up if you specify --use-analyzer explicitly? Because %scan_build in tests includes this flag because otherwise it has no knowledge of the clang build directory.

sh: 1: : Permission denied

This looks like a separate problem, dunno.

In D74467#1905416, @NoQ wrote:

Could you mention how to use this feature in the Summary please?
And something is not right, I have tried it:

Use of uninitialized value $Clang in concatenation (.) or string at /llvm-project/clang/tools/scan-build/bin/scan-build line 1895.

Uh-oh. Does this still show up if you specify --use-analyzer explicitly? Because %scan_build in tests includes this flag because otherwise it has no knowledge of the clang build directory.

sh: 1: : Permission denied

This looks like a separate problem, dunno.

Well, then please mention the proper usage is:

cd reports
scan-build --use-analyzer clang --generate-index-only .

With that none of the concatenation and sh permission issue shows up. However it would be a nice QoL if that extra flag is not needed to generate HTML.

NoQ closed this revision.Apr 7 2020, 11:51 AM

Re-landed as rG0c27fd82e1e6.

I sorted the list of HTML files before deduplicating and the buildbots seem silent for now.

Also fxd the uninitialized variable $Clang use when --use-analyzer= is not specified; here's what it was used for: