This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add support for new expressions.
ClosedPublic

Authored by mboehme on Apr 6 2023, 4:28 AM.

Diff Detail

Event Timeline

mboehme created this revision.Apr 6 2023, 4:28 AM
Herald added a project: Restricted Project. · View Herald Transcript
mboehme requested review of this revision.Apr 6 2023, 4:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2023, 4:28 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 added inline comments.
clang/include/clang/Analysis/FlowSensitive/Value.h
315 ↗(On Diff #511366)

Modifying already-created values is wrong since values are supposed to be immutable (I know we already do it in setChild above, but let's not add more?)

A value can be stored in multiple locations, and if one of them is deleted, the other users of the same value shouldn't observe the change.

clang/lib/Analysis/FlowSensitive/Transfer.cpp
485

I'm not convinced that we need to break the loc/value association for deleted heap allocations. After all, we don't do that for stack allocations that go out of scope. So why bother for the heap? Especially since "delete" is very rare in modern idiomatic C++.

490

It is correct that we shouldn't deallocate PointerValue, but the reasons for that are different:

(1) The code being analyzed might have multiple copies of the pointer, and it might have a double-free or a use-after-free. The analyzer shouldn't execute UB when the program being analyzed has UB.

(2) The PointerValue is needed to analyze other basic blocks.

(3) The downstream code that is going to inspect the environments at various program points will need the PointerValues (like the test in this patch).

@gribozavr2 Just to make sure I understand you correctly here (before I make any changes to the code): IIUC you recommend simply doing nothing on a delete expression? (Your arguments for this make sense to me, just want to double-check I understood correctly.)

@gribozavr2 Just to make sure I understand you correctly here (before I make any changes to the code): IIUC you recommend simply doing nothing on a delete expression? (Your arguments for this make sense to me, just want to double-check I understood correctly.)

Yes, that's my suggestion.

mboehme updated this revision to Diff 512434.Apr 11 2023, 6:51 AM

Eliminate specific handling of delete expressions.

mboehme retitled this revision from [clang][dataflow] Add support for new and delete expressions. to [clang][dataflow] Add support for new expressions..Apr 11 2023, 6:51 AM
mboehme edited the summary of this revision. (Show Details)
mboehme marked 3 inline comments as done.Apr 11 2023, 6:55 AM
mboehme added inline comments.
clang/include/clang/Analysis/FlowSensitive/Value.h
315 ↗(On Diff #511366)

Modifying already-created values is wrong since values are supposed to be immutable (I know we already do it in setChild above, but let's not add more?)

Good point -- removed.

A value can be stored in multiple locations, and if one of them is deleted, the other users of the same value shouldn't observe the change.

No longer relevant, but just to complete the discussion: I don't believe this is true for StructValues because of the way that prvalues of class type get materialized into result objects. I believe this causes every StructValue to be materialized into exactly one AggregateStorageLocation.

clang/lib/Analysis/FlowSensitive/Transfer.cpp
485

Good point. This makes everything much simpler. Done.

490

(1) The code being analyzed might have multiple copies of the pointer, and it might have a double-free or a use-after-free. The analyzer shouldn't execute UB when the program being analyzed has UB.

That's what I was trying to say with my comment here -- but this is now moot anyway, as we no longer do anything for deletes.

gribozavr2 accepted this revision.Apr 11 2023, 7:30 AM
This revision is now accepted and ready to land.Apr 11 2023, 7:30 AM
xazax.hun accepted this revision.Apr 17 2023, 8:46 AM
This revision was automatically updated to reflect the committed changes.
mboehme marked 3 inline comments as done.