This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Implement IntegralToBoolean casts
ClosedPublic

Authored by tbaeder on Aug 26 2022, 6:41 AM.

Details

Summary

Redo how we do IntegralCasts and implement IntegralToBoolean casts using the already existing cast op.

Diff Detail

Event Timeline

tbaeder created this revision.Aug 26 2022, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 6:41 AM
Herald added a subscriber: inglorion. · View Herald Transcript
tbaeder requested review of this revision.Aug 26 2022, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 6:41 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
erichkeane accepted this revision.Aug 26 2022, 6:44 AM
erichkeane added inline comments.
clang/lib/AST/Interp/Opcodes.td
433

Not sure how this works... but is this ONLY int-32 to bool and vice versa? The implementation of any of the other integrals should be trivial.

This revision is now accepted and ready to land.Aug 26 2022, 6:44 AM
tbaeder added inline comments.Aug 26 2022, 6:46 AM
clang/lib/AST/Interp/Opcodes.td
433

Yes exactly, the primitive types are:

def Bool : Type;
def Sint8 : Type;
def Uint8 : Type;
def Sint16 : Type;
def Uint16 : Type;
def Sint32 : Type;
def Uint32 : Type;
def Sint64 : Type;
def Uint64 : Type;
def Ptr : Type;
erichkeane added inline comments.Aug 26 2022, 6:47 AM
clang/lib/AST/Interp/Opcodes.td
433

So why not fill them in here as well?

tbaeder added inline comments.Aug 26 2022, 6:54 AM
clang/lib/AST/Interp/Opcodes.td
433

I think I can add Uint32 as well, but for the others I can't write tests yet since I don't have their literals implemented yet.

tbaeder updated this revision to Diff 455897.Aug 26 2022, 7:01 AM
erichkeane added inline comments.Aug 26 2022, 7:02 AM
clang/lib/AST/Interp/Opcodes.td
433

Got it, thanks!

shafik added inline comments.Aug 26 2022, 5:16 PM
clang/lib/AST/Interp/Boolean.h
90

This should work for floating_point as well.

91

Why the != 0 shouldn't these all implicitly convert to bool with appropriate values?

tbaeder marked an inline comment as done.Aug 26 2022, 9:56 PM
tbaeder added inline comments.
clang/lib/AST/Interp/Boolean.h
90

We don't do floating point values yet.

91

Not 100% sure why this was used, it was there before so I left it in.

This revision was landed with ongoing or failed builds.Sep 7 2022, 10:31 PM
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.