This is an archive of the discontinued LLVM Phabricator instance.

[clang/Sema] Fix non-deterministic order for certain kind of diagnostics
ClosedPublic

Authored by akyrtzi on Oct 3 2022, 5:11 PM.

Details

Summary

In the context of caching clang invocations it is important to emit diagnostics in deterministic order;
the same clang invocation should result in the same diagnostic output.

rdar://100336989

Diff Detail

Event Timeline

akyrtzi created this revision.Oct 3 2022, 5:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 5:11 PM
Herald added a subscriber: mgrang. · View Herald Transcript
akyrtzi requested review of this revision.Oct 3 2022, 5:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 5:11 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Oct 3 2022, 5:51 PM
steven_wu accepted this revision.Oct 4 2022, 9:24 AM

LGTM.

RemoveDecl does become more expensive but I don't have better solution. I am also wondering if as follow up we should add an option to VerifyDiagnosticConsumer to be location aware (so the diagnostics from a file is emitted in order) to prevent more problem like this.

benlangmuir added inline comments.Oct 4 2022, 9:50 AM
clang/include/clang/AST/DeclObjC.h
1091

Can we use the existing PropertyDeclOrder instead of changing the map type? Or else get rid of the PO parameter to functions using PropertyMap if we keep the MapVector?

LGTM.

RemoveDecl does become more expensive but I don't have better solution.

Luckily AFAICT this is not a "hot" function.

I am also wondering if as follow up we should add an option to VerifyDiagnosticConsumer to be location aware (so the diagnostics from a file is emitted in order) to prevent more problem like this.

Interesting idea! Something to keep in mind.

akyrtzi added inline comments.Oct 4 2022, 1:30 PM
clang/include/clang/AST/DeclObjC.h
1091

I'll take a look.

akyrtzi updated this revision to Diff 465241.Oct 4 2022, 5:56 PM

Remove PropertyDeclOrder parameter from the collectPropertiesToImplement functions. This is not necessary with PropertyMap becoming a MapVector.

akyrtzi marked an inline comment as done.Oct 4 2022, 5:58 PM
akyrtzi added inline comments.
clang/include/clang/AST/DeclObjC.h
1091

See updated patch.

The diagnostic machinery (e.g. in DiagnoseUnimplementedProperties) for these ObjC diagnostics is using PropertyMap separately from the collectPropertiesToImplement functions, so I kept the map type change and removed PropertyDeclOrder from these functions accepting PropertyMap.
This is better for maintainance since it'd be an easy mistake to add new code that iterates the DenseMap instead of the vector.

benlangmuir accepted this revision.Oct 5 2022, 11:55 AM
This revision was landed with ongoing or failed builds.Oct 5 2022, 12:58 PM
This revision was automatically updated to reflect the committed changes.

Thanks for letting me know! I'll take a look.