This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][NFC] Make AnalyzerConfig round-tripping deterministic
AbandonedPublic

Authored by steakhal on Jul 4 2023, 5:08 AM.

Details

Summary

In asserted builds, we do a so-called "round-tripping". This is called
from CompilerInvocation::CreateFromArgs, which eventually calls
generateCC1CommandLine from the lambda. That, in turn, calls a bunch
of GenerateXXX functions, thus ours as well: GenerateAnalyzerArgs.
The round tripping ensures some consistency property, also that the
generator generates the arguments in a deterministic order.

This works at the moment, but as soon as we add a new AnalyzerOption to
the AnalyzerOptions.def file, it's pretty likely that it will produce
the same sequence of args BUT in a different order for the second round
of round-tripping, resulting in an err_cc1_round_trip_mismatch
diagnostic.

This happens because inside GenerateAnalyzerArgs, we iterate over the
Opts.Config, which is of type StringMap. Well, the iteration order
is not guaranteed to be deterministic for that. Quote
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h

StringMap iteration order, however, is not guaranteed to be
deterministic, so any uses which require that should instead use a
std::map.

Consequently, to allow adding/removing analyzer options to
AnalyzerOptions.def without relying on the current iteration order, we
need to make that deterministic. And that is what I'm proposing in this
patch.

Diff Detail

Event Timeline

steakhal created this revision.Jul 4 2023, 5:08 AM
Herald added a reviewer: njames93. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
steakhal requested review of this revision.Jul 4 2023, 5:08 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 4 2023, 5:08 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Has this not been addressed by D142861 already?

Has this not been addressed by D142861 already?

Hm, The same failure. This must be related. I'll have a look.
But, you can try it yourself that the issue still remains:
Add a new StringRef option to the AnalyzerOptions.def and it's likely it will break the clang/test/Analysis/shallow-mode.m test.

steakhal abandoned this revision.Jul 4 2023, 8:28 AM

Ah, D142861 is only on main, that's why we don't have that. I'll cherry-pick that then.
@jansvoboda11 Thanks for the xref!

Confirmed, that fixes the issue. Abandoning this one.