This is an archive of the discontinued LLVM Phabricator instance.

[Clang] avoid relying on StringMap iteration order when roundtripping -analyzer-config
ClosedPublic

Authored by erikdesjardins on Jan 29 2023, 7:57 PM.

Details

Summary

I am working on another patch that changes StringMap's hash function,
which changes the iteration order here, and breaks some tests,
specifically:

clang/test/Analysis/NSString.m
clang/test/Analysis/shallow-mode.m

with errors like:

generated arguments do not match in round-trip
generated arguments #1 in round-trip: <...> "-analyzer-config" "ipa=inlining" "-analyzer-config" "max-nodes=75000" <...>
generated arguments #2 in round-trip: <...> "-analyzer-config" "max-nodes=75000" "-analyzer-config" "ipa=inlining" <...>

To avoid this, sort the options by key, instead of using the default map
iteration order.

Diff Detail

Event Timeline

erikdesjardins created this revision.Jan 29 2023, 7:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 29 2023, 7:57 PM
erikdesjardins requested review of this revision.Jan 29 2023, 7:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 29 2023, 7:57 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thanks for the patch. Left a couple of small suggestions.

clang/lib/Frontend/CompilerInvocation.cpp
880–887

Per our coding style, we don't put braces around bodies with just a single statement.

881

I think you should be able to drop llvm::.

881

No reason to allocate for this temporary storage IMO, you could replace std::string with StringRef.

887

You could use C++17 structured bindings: for (const auto &[Key, Value] : SortedConfigOpts) { ... }.

jansvoboda11 accepted this revision.Jan 30 2023, 9:13 AM
This revision is now accepted and ready to land.Jan 30 2023, 9:13 AM
MaskRay accepted this revision.Jan 30 2023, 9:57 AM
MaskRay added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
884

If you use pair instead of tuple, you can use llvm::less_first()

dblaikie added inline comments.Jan 30 2023, 10:55 AM
clang/lib/Frontend/CompilerInvocation.cpp
880–887

We usually skip braces on single line blocks

881

Perhaps std::pair would be slightly easier to read than std::tuple?

887–889

maybe a structured binding here?

(heh, don't mind my feedback being duplicate - didn't refresh before submitting - glad other folks got to it before me! :) )

Improve code style. ninja check-clang still passes (as expected)

erikdesjardins marked 8 inline comments as done.Jan 30 2023, 2:39 PM
MaskRay accepted this revision.Jan 30 2023, 2:39 PM

I don't have commit access, please commit this on my behalf: Erik Desjardins <erikdesjardinspublic@gmail.com>

This revision was landed with ongoing or failed builds.Feb 1 2023, 1:54 PM
This revision was automatically updated to reflect the committed changes.