This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Record item types in InterpStack
ClosedPublic

Authored by tbaeder on Sep 15 2022, 7:11 AM.

Details

Summary

Since I've run into this a few times now...

When push()ing something on the stack, we need to later pop() the correct type of value, otherwise we run into problems.

This s just an idea and I've disabled it if NDEBUG is defined. The current tests all still work though, which is good.

Diff Detail

Event Timeline

tbaeder created this revision.Sep 15 2022, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 7:11 AM
tbaeder requested review of this revision.Sep 15 2022, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 7:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Can you clarify what the intent of this patch is? Perhaps I'm just being slow today, but I don't really get the intent here.

clang/lib/AST/Interp/InterpStack.h
133

Each of these ALSO need to be 'if constexpr' I think.

159

llvm_unreachable?

Can you clarify what the intent of this patch is? Perhaps I'm just being slow today, but I don't really get the intent here.

Consider:

push<Pointer>(...);
(lots of stuff)
pop<int>();

currently this would just work and give you an integer, but they value wouldn't make any sense. This patch would assert here since the value on the stack is not an integer, it's a pointer.
It basically adds a bit of type-safety back.

tbaeder updated this revision to Diff 460654.Sep 15 2022, 11:39 PM
tbaeder marked 2 inline comments as done.

Do you think std::is_same_v will be even better?

Do you think std::is_same_v will be even better?

I don't really have a preference.

tbaeder updated this revision to Diff 460689.Sep 16 2022, 2:50 AM
tbaeder updated this revision to Diff 460697.Sep 16 2022, 3:54 AM
erichkeane accepted this revision.Sep 16 2022, 6:21 AM

is_same_v would be an improvement, but otherwise I think this is fine.

clang/lib/AST/Interp/InterpStack.h
137

Side note: Having Integral's 2nd template parameter be a bool here is a bad design decision IMO. It should probably be an enum, so that we can just do:

Integral<8, Signed> or Integral<8, Unsigned> kinda thing.

This revision is now accepted and ready to land.Sep 16 2022, 6:21 AM
This revision was landed with ongoing or failed builds.Sep 29 2022, 3:51 AM
This revision was automatically updated to reflect the committed changes.