Page MenuHomePhabricator

[analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'
ClosedPublic

Authored by NoQ on Dec 18 2018, 6:38 AM.

Diff Detail

Event Timeline

Szelethus created this revision.Dec 18 2018, 6:38 AM
NoQ added a comment.Dec 18 2018, 4:44 PM

Ugh. No, it doesn't work. It seems that stuff after -Xclang is not included in Args (even at the beginning of the function, when no arguments are consumed), and it doesn't make it into CmdArgs (yet?).

Test passes because -analyzer-config is a sub-string of the file name. If you rename the test, it stops working (:

I'll be debugging this a bit more on my end, but help is welcome. And in any case, thanks a lot for looking into this!~ I'm even more surprised how hard it is to come up with a sensible solution to our weird problem.

test/Analysis/invalid-analyzer-config-value.c
72

This run-line *does* have -analyze specified, because that's what --analyze expands to. I guess the test that we need would be along the lines of clang -Xclang -analyzer-config ... without --analyze.

NoQ added a comment.Dec 18 2018, 4:53 PM

These arguments seem to be available during the top-level call, Driver::BuildCompilation. I guess we need to stick this somewhere in between.

Szelethus marked an inline comment as done.Dec 19 2018, 12:20 AM
Szelethus added inline comments.
test/Analysis/invalid-analyzer-config-value.c
72

Uhhhh sorry about that.

Yea, should've used hasArg anyways. I'll look into this tonight.

Szelethus marked an inline comment as done.Dec 19 2018, 11:11 AM
Szelethus added inline comments.
lib/Driver/ToolChains/Clang.cpp
3694

When I dump Args for the following invocation, I get this:

clang -c dummie.cpp -Xclang -analyzer-config -Xclang blahblah=haha

* < Opt:<FlagClass Prefixes:["-"] Name:"c" Group:<GroupClass Name:"<action group>">
>
 Index:0 Values: []>
* < Opt:<InputClass Prefixes:[] Name:"<input>">
 Index:1 Values: ['test/Analysis/cxx-uninitialized-object.cpp']>
* < Opt:<SeparateClass Prefixes:["-"] Name:"Xclang" Group:<GroupClass Name:"<CompileOnly group>">
>
 Index:2 Values: ['-analyzer-config']>
* < Opt:<SeparateClass Prefixes:["-"] Name:"Xclang" Group:<GroupClass Name:"<CompileOnly group>">
>
 Index:4 Values: ['blahblah=haha']>

so there should be a way to retrieve it. For Args.getArgString(/*index*/3) it also prints "-analyzer-config" -- but I'm still looking for a "proper" way.

I'm still looking for a sensible solution, but I'll at least share a patch that actually works.

Szelethus marked 2 inline comments as done.Dec 19 2018, 11:34 AM
Szelethus added inline comments.
test/Analysis/invalid-analyzer-config-value.c
72

I checked this against a completely different file, and it works.

NoQ accepted this revision.Dec 19 2018, 1:46 PM

It works! :D

I guess, please commit this if you don't find anything better.

test/Analysis/invalid-analyzer-config-value.c
72

Given that we stepped on this, i guess it's still worth it to rename the test file.

This revision is now accepted and ready to land.Dec 19 2018, 1:46 PM
NoQ added inline comments.Dec 19 2018, 6:30 PM
lib/Driver/ToolChains/Clang.cpp
3697

Needs an LLVM-style loop!~ :)

lib/Driver/ToolChains/Clang.cpp
3697

Shouldn't this be under else- for the previous branch? Otherwise it seems that the option would be added twice.

NoQ added a comment.Dec 20 2018, 12:45 PM

@Szelethus: Ok if we commit this real quick and then see if there's a better solution?

Szelethus marked an inline comment as done.Dec 20 2018, 12:50 PM

Sure! I'm on my phone, and will be for a little while, can you commit on my behalf?

lib/Driver/ToolChains/Clang.cpp
3697

I originally deleted that line, but I lost in somewhere :/

NoQ commandeered this revision.Dec 20 2018, 12:51 PM
NoQ updated this revision to Diff 179135.
NoQ edited reviewers, added: Szelethus; removed: NoQ.

Re-remove the first argument append.

Add a test in which file name doesn't match our search.

Szelethus accepted this revision.Dec 20 2018, 1:06 PM

Thanks! Sorry about being a little slow with this, I'm sadly busier than I expected, but I'll definitely think about a nicer solution.

This revision was automatically updated to reflect the committed changes.
NoQ added a comment.Dec 20 2018, 2:03 PM

Np! We really appreciate your work!

NoQ added a comment.Dec 20 2018, 2:22 PM

Hmm, this http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/14563/steps/test-stage2-compiler/logs/stdio also looks like ours. I guess i'll revert cause i've no idea what causes that.

I think Args.getArgString might return nullptr so that's why you could crash.

NoQ added a comment.Dec 20 2018, 3:46 PM

I think Args.getArgString might return nullptr so that's why you could crash.

Nope, we crash on index lookup. It seems that Args.size() is larger than the small vector that we're allowed to access via .getArgStrings(). I tried Args.getNumInputArgStrings() and it seems better.

NoQ reopened this revision.Dec 20 2018, 3:52 PM
This revision is now accepted and ready to land.Dec 20 2018, 3:52 PM
NoQ updated this revision to Diff 179191.Dec 20 2018, 3:56 PM

Though yeah, thanks, we might be crashing for that reason as well in the future!

NoQ updated this revision to Diff 179193.Dec 20 2018, 3:57 PM

Remove debug prints >.<

NoQ added a comment.Dec 20 2018, 4:57 PM

George committed this as rC349863. Before that happened, we kinda figured out how it works: -analyzer-config is not a flag, it's an argument of the -Xclang flag, so we should look for -Xclang and see what value does the argument have.

Now, there's also -Xanalyzer. But -Xanalyzer is automatically not consumed during compilation, so any -analyzer-config flags passed through it would be ignored during compilation.

However, --analyze -Xanalyzer -analyzer-config ... is now broken :/

NoQ closed this revision.Dec 21 2018, 11:59 AM

Should be sorted our in rC349866.

Ugh, what a mess :) Thanks everyone :)

Missed out on the developments. Thank you so much for handling this!