This is an archive of the discontinued LLVM Phabricator instance.

[clang-scan-deps] Add support for clang-cl
ClosedPublic

Authored by saudi on Nov 26 2020, 10:35 AM.

Details

Summary

clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

Diff Detail

Event Timeline

saudi created this revision.Nov 26 2020, 10:35 AM
saudi requested review of this revision.Nov 26 2020, 10:35 AM
hans added a comment.Nov 27 2020, 2:23 AM

Seems reasonable to me, but someone who actually knows clang-scan-deps should take a look too.

clang/tools/clang-scan-deps/ClangScanDeps.cpp
487

these string constants should be const char NullFile[] = ....

but since it seems you're only using NullFile for the /Fo or -o options below, I'd suggest just folding it into those options instead. Then you could also avoid having to do the (Twine("/Fo") + NullFile).str() dance and could just do push_back ("/Fonul");

saudi updated this revision to Diff 308068.Nov 27 2020, 8:44 AM

Removed /Fo option. -o is also supported by clang-cl and overrides /Fo options that are found earlier in the command line.

saudi marked an inline comment as done.Nov 27 2020, 8:45 AM
saudi updated this revision to Diff 308770.Dec 1 2020, 2:16 PM

Rebase after https://reviews.llvm.org/D92330.
Also, improved the detection of target obj file.

Bigcheese accepted this revision.Dec 11 2020, 2:51 PM

lgtm. Thanks for the patch.

This revision is now accepted and ready to land.Dec 11 2020, 2:51 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Dec 14 2020, 10:26 AM

Looks like this breaks tests on mac: http://45.33.8.238/macm1/174/step_6.txt

Ptal, and revert for now if it takes a while to fix

saudi updated this revision to Diff 316768.Jan 14 2021, 1:35 PM
saudi edited the summary of this revision. (Show Details)

Updated the tests for clang-cl command lines:
I moved the input files to end of command line, with --, to avoid linux-style paths conflict with clang-cl arguments.

I also had to fix the code to support --, as clang-scan-deps adds arguments to the command line.

saudi reopened this revision.Jan 14 2021, 1:35 PM
This revision is now accepted and ready to land.Jan 14 2021, 1:35 PM
saudi requested review of this revision.Jan 14 2021, 1:35 PM
saudi added a comment.Jan 19 2021, 8:51 AM

Ping!
Would anybody have a chance to take a look at this? I'd like to submit this before the LLVM 12 branch, if possible? Thanks in advance!

It would be great if you could split the -- support out into a separate patch to commit ahead of time, but I left a couple of comments since I was taking a look.

clang/lib/Tooling/Tooling.cpp
438–440 ↗(On Diff #316768)

Seems like this should break early on --. You could also avoid the subsequent llvm::find by remembering where it is.

clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
4–11

It's not clear why you made these changes. Can you clarify?

saudi updated this revision to Diff 318248.Jan 21 2021, 10:01 AM
saudi edited the summary of this revision. (Show Details)

Removed the support for "--" command lines, it was extracted to patch D95099.
Applied suggested fixes.

saudi marked an inline comment as done.Jan 21 2021, 10:06 AM
saudi added inline comments.
clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
4–11

The added "--" was not necessary, I removed it.
The added "_clang" was because I added a CHECK: line for the .c file, but "static-analyzer.c" would cause false positives with %S.

-> see the new comment in the static-analyzer.c

Removed the support for "--" command lines, it was extracted to patch D95099.
Applied suggested fixes.

Thanks!

@Bigcheese, since you reviewed the original patch, are you able to take a look at the updated version?

saudi updated this revision to Diff 318553.Jan 22 2021, 9:29 AM
saudi marked an inline comment as done.

Applied the suggestions from the parent patch D95099

dexonsmith accepted this revision.Feb 8 2021, 11:53 AM

LGTM. This is similar enough to the original patch I'm comfortable signing off, even though @Bigcheese hasn't had a chance to take a look.

This revision is now accepted and ready to land.Feb 8 2021, 11:53 AM
gulfem added a subscriber: gulfem.Apr 19 2021, 1:11 PM

This seems to break our Fucshia builds.
If we cannot do a quick fix, we need to revert this patch.
Please see the error message below:

FAIL: Clang :: ClangScanDeps/vfsoverlay.cpp (1863 of 27822)
******************** TEST 'Clang :: ClangScanDeps/vfsoverlay.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';   rm -rf /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir
: 'RUN: at line 2';   rm -rf /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.cdb
: 'RUN: at line 3';   mkdir -p /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir
: 'RUN: at line 4';   cp /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/vfsoverlay.cpp /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay_input.cpp
: 'RUN: at line 5';   cp /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/vfsoverlay.cpp /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay_input_clangcl.cpp
: 'RUN: at line 6';   sed -e "s|DIR|/opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir|g" /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/Inputs/vfsoverlay.yaml > /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay.yaml
: 'RUN: at line 7';   mkdir /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/Inputs
: 'RUN: at line 8';   cp /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/Inputs/header.h /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/Inputs/header.h
: 'RUN: at line 9';   sed -e "s|DIR|/opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir|g" /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json > /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.cdb
: 'RUN: at line 11';   clang-scan-deps -compilation-database /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.cdb -j 1 |    /opt/s/w/ir/x/w/staging/llvm_build/bin/FileCheck /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/vfsoverlay.cpp
--
Exit Code: 1

Command Output (stderr):
--
/opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/vfsoverlay.cpp:20:11: error: CHECK: expected string not found in input
// CHECK: vfsoverlay_input_clangcl.o
          ^
<stdin>:3:113: note: scanning from here
 /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/Inputs/header.h
                                                                                                                ^
<stdin>:5:98: note: possible intended match here
 /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay_input_clangcl.cpp \
                                                                                                 ^

Input file: <stdin>
Check file: /opt/s/w/ir/x/w/llvm-project/clang/test/ClangScanDeps/vfsoverlay.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay_input.o: \ 
            2:  /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay_input.cpp \ 
            3:  /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/Inputs/header.h 
check:20'0                                                                                                                     X error: no match found
            4: pt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay.yaml: \ 
check:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            5:  /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/vfsoverlay_input_clangcl.cpp \ 
check:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:20'1                                                                                                      ?                               possible intended match
            6:  /opt/s/w/ir/x/w/staging/llvm_build/tools/clang/test/ClangScanDeps/Output/vfsoverlay.cpp.tmp.dir/Inputs/header.h 
check:20'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>

@gulfem We're taking a look now. Could you please post a link to the full build log, including the cmake flags used?

@gulfem We're taking a look now. Could you please post a link to the full build log, including the cmake flags used?

This is the link to one of our failing builds:
https://ci.chromium.org/ui/p/fuchsia/builders/ci/clang-linux-arm64/b8849674814150864912/overview

Here, you can see the cmake flags:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8849674814150864912/+/u/clang/configure/execution_details

Thanks! We found the issue. I think I'll revert the patch, and will reland a fixed version.

Thanks! We found the issue. I think I'll revert the patch, and will reland a fixed version.

Great, thank you!