This is an archive of the discontinued LLVM Phabricator instance.

[-Wunsafe-buffer-usage] Reducing non-determinism in diagnostics output stream
ClosedPublic

Authored by ziqingluo-90 on Mar 13 2023, 3:17 PM.

Details

Summary

The -Wunsafe-buffer-usage analysis outputs diagnostics in the order of pointer values to associated VarDecls. This creates non-determinism in the order of diagnostics in output since it cannot be guaranteed in pointer values. However, our fix-it tests were written under the assumption that diagnostics are output in source location order. This results in non-deterministic failures in our tests when diagnostics are not output in source location order, such as
buildbot fail (We disabled the test for windows but didn't understand the failure that time).

The reason that a test fail, albeit possible, is much less likely than a test pass is probably because pointer values to AST nodes nearly respect to the order of node creation/parse.

Diff Detail

Event Timeline

ziqingluo-90 created this revision.Mar 13 2023, 3:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 3:17 PM
ziqingluo-90 requested review of this revision.Mar 13 2023, 3:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 3:17 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ziqingluo-90 added inline comments.Mar 13 2023, 3:19 PM
clang/lib/Analysis/UnsafeBufferUsage.cpp
1081

Warnings are still emitted in non-deterministic order within a single VarDecl group. But it should not affect test results.

NoQ accepted this revision.Mar 13 2023, 3:26 PM

LGTM, let's land asap!

clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h
65–71 ↗(On Diff #504860)

Nice template solution!

Can we keep it in the .cpp file? It's not really part of our analysis's user interface, at least not yet.

This revision is now accepted and ready to land.Mar 13 2023, 3:26 PM
jkorous accepted this revision.Mar 13 2023, 3:32 PM

+1 to moving the comparator to the .cpp file; otherwise LGTM!
Thanks for fixing this!

Address comments

This revision was landed with ongoing or failed builds.Mar 13 2023, 5:22 PM
This revision was automatically updated to reflect the committed changes.