This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix BindingDecl evaluation for reference types.
ClosedPublic

Authored by isuckatcs on Jun 28 2022, 2:07 AM.

Details

Summary

The case when the bound variable is reference type in a BindingDecl wasn't handled, which lead to false positives.

Diff Detail

Event Timeline

isuckatcs created this revision.Jun 28 2022, 2:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 2:07 AM
isuckatcs requested review of this revision.Jun 28 2022, 2:07 AM
Szelethus added inline comments.Jun 28 2022, 4:39 AM
clang/test/Analysis/structured_bindings.cpp
20

I wouldn't use function main unless the tests needs specifically that.

Szelethus accepted this revision.Jun 28 2022, 5:31 AM

I tried poking this from a few directions, like nasty GNU extension types, ObjCObjectPointerType, but those seem orthogonal to this patch. Looks great! I'd wait for someone else's approval as well, as I try my best to pick up the thread.

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
2633

I think a few words might be nice here. It may not be obvious to everyone that the binding is never a reference (https://eel.is/c++draft/dcl.struct.bind#note-1).

This revision is now accepted and ready to land.Jun 28 2022, 5:31 AM
isuckatcs updated this revision to Diff 440622.Jun 28 2022, 7:42 AM

Renamed the main function

isuckatcs marked an inline comment as done.Jun 28 2022, 7:43 AM
xazax.hun accepted this revision.Jun 28 2022, 9:57 AM
xazax.hun added inline comments.
clang/test/Analysis/structured_bindings.cpp
26

I think we could have a test case where we modify the value of i through x and check that the value of i changed to make sure they actually point to the same memory location, not just happen to have same value.

isuckatcs marked an inline comment as done.

Updated testcase

NoQ accepted this revision.Jun 28 2022, 3:47 PM

LGTM!

Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 4:01 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript