[PATCH] D154437: [analyzer][NFC] Make AnalyzerConfig round-tripping deterministic
Balázs Benics via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 4 05:08:57 PDT 2023
steakhal created this revision.
steakhal added reviewers: NoQ, xazax.hun, jansvoboda11.
Herald added subscribers: PiotrZSL, carlosgalvezp, manas, ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, mgrang, szepet, baloghadamsoftware.
Herald added a reviewer: Szelethus.
Herald added a reviewer: njames93.
Herald added a project: All.
steakhal requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154437
Files:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154437.537058.patch
Type: text/x-patch
Size: 6018 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230704/3aed38f0/attachment-0001.bin>
More information about the cfe-commits
mailing list