This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Handle global composite temporaries
ClosedPublic

Authored by tbaeder on Feb 21 2023, 1:21 AM.

Details

Summary
We only did this for primitive temporaries.

Unfortunately, the existing Pointer::toAPValue() won't do here, since
we're expected to set an rvalue on the LifetimeExtendedTemporaryDecl.

Diff Detail

Event Timeline

tbaeder created this revision.Feb 21 2023, 1:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 1:21 AM
tbaeder requested review of this revision.Feb 21 2023, 1:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 1:21 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thinking about this some more, the new Pointer::toRValue() is probably just the same thing we're already doing in EvalEmitter::emtiRetValue().

I think it mostly makes sense but I want Aaron to also look at it.

clang/lib/AST/Interp/Pointer.cpp
10

Are all these headers really needed for the change below?

tbaeder added inline comments.Jun 1 2023, 3:02 AM
clang/lib/AST/Interp/Pointer.cpp
10

We access .toAPValue() on all of them in the TYPE_SWITCH below, so yes.

aaron.ballman added inline comments.Aug 17 2023, 11:57 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
852

Should this still happen even if TempDecl is null? It looks like getLifetimeExtendedTemporaryDecl() can return a null pointer, but perhaps there's a reason we can't get that result here?

clang/lib/AST/Interp/Pointer.cpp
235–237

Pointer to a field? That means, I would like tests that involve bit-fields. :-)

236
241
clang/lib/AST/Interp/Record.h
90

It might make sense to add an assert to both getBase() functions to verify that I is within a valid range.

tbaeder added inline comments.Aug 18 2023, 12:58 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
852

AFAIK it never returns null if the storage duration is SD_Static, but that's just based on what I was seeing. Could add an assertion to be sure.

clang/lib/AST/Interp/Pointer.cpp
236

const Pointer & instead? :)

tbaeder updated this revision to Diff 551435.Aug 18 2023, 2:08 AM
tbaeder marked 6 inline comments as done.
This revision is now accepted and ready to land.Aug 18 2023, 5:50 AM
This revision was landed with ongoing or failed builds.Aug 20 2023, 2:18 AM
This revision was automatically updated to reflect the committed changes.