This is an archive of the discontinued LLVM Phabricator instance.

[-Wunsafe-buffer-usage] Replace assert that declarations are always found
ClosedPublic

Authored by t-rasmud on Aug 3 2023, 11:06 AM.

Diff Detail

Event Timeline

t-rasmud created this revision.Aug 3 2023, 11:06 AM
Herald added a project: Restricted Project. · View Herald Transcript
t-rasmud requested review of this revision.Aug 3 2023, 11:06 AM

How about having some tests?

How about having some tests?

My understanding is that we are not sure of when this assert might be hit. This was probably hit when lambda captures were not handled but not anymore. We want to replace the assert with a debug note to catch cases when we can't find a VarDecl for a declaration statement. @NoQ Could you please confirm if my understanding is correct?

t-rasmud updated this revision to Diff 547868.Aug 7 2023, 11:24 AM

My understanding is that we are not sure of when this assert might be hit.

aha, I cannot think of an example either so I was curious. What you said makes sense to me.

NoQ added a comment.Aug 7 2023, 2:35 PM

I don't have any test cases in mind immediately. We could try our usual suspects such as globals and DecompositionDecls (they're subclass of VarDecl, unlike BindingDecl). But it could totally be that it dodges them because of other checks we already have.

But I agree that the assertion should be removed: we just no longer believe that it needs to hold!

clang/lib/Analysis/UnsafeBufferUsage.cpp
2058

Other notes start with small letter 😅

t-rasmud updated this revision to Diff 547999.Aug 7 2023, 5:11 PM
NoQ added a comment.Aug 7 2023, 5:33 PM

Oo I think I broke it! https://godbolt.org/z/7efM6TvxM

We needed to use the tuple mode of decomposition because it eagerly unpacks the tuple into, in our case, a raw pointer that we can try to analyze.

This, of course, makes it much harder to write the test because you'll need to mock <tuple>. Looks like we have some existing mocks in test/Analysis/uninit-structured-binding-tuple.cpp, they might help.

I suspect it'll be much easier to break this assertion once we start supporting std::array. So it's great that we're removing it.

NoQ accepted this revision.Aug 15 2023, 3:36 PM

Yeah nvm that's a different assertion and an unrelated crash. Which we'll also need to fix but not in this patch. LGTM then!

This revision is now accepted and ready to land.Aug 15 2023, 3:36 PM
This revision was landed with ongoing or failed builds.Aug 15 2023, 3:42 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 3:42 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript