This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Perform structural comparison of indirection values in `join`.
ClosedPublic

Authored by ymandel on Apr 27 2022, 10:35 AM.

Details

Summary

This patch changes Environment::join, in the case that two values at the same
location are not (pointer) equal, to structurally compare indirection values
(pointers and references) for equivalence (that is, equivalent pointees) before
resorting to merging.

This change makes join consistent with equivalence, which also performs
structural comparison. It also fixes a bug where the values are ReferenceValue
but the merge creates a non-reference value. This case arises when the
ReferenceValues were created to represent an lvalue, so the "reference-ness"
is not reflected in the type. In this case, the pointees will always be
equivalent, because lvalues at the same code location point to the location of a
fixed declaration, whose location is itself stable across blocks.

We were unable to reproduce a unit test for this latter bug, but have verified
the fix in the context of a larger piece of code that triggers the bug.

Diff Detail

Event Timeline

ymandel created this revision.Apr 27 2022, 10:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 10:35 AM
ymandel requested review of this revision.Apr 27 2022, 10:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 10:35 AM
xazax.hun accepted this revision.Apr 27 2022, 10:41 AM
This revision is now accepted and ready to land.Apr 27 2022, 10:41 AM
sgatev accepted this revision.Apr 28 2022, 12:37 AM
sgatev added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
366–374

Let's add merging of distinct indirection values to mergeDistinctValues where we already have code for merging distinct boolean values.

ymandel marked an inline comment as done.Apr 28 2022, 10:58 AM
ymandel added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
366–374

Good idea, done. That's nicer, thanks.