This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Handle mixed floating/integral compound assign operators
ClosedPublic

Authored by tbaeder on Aug 10 2023, 3:03 AM.

Details

Summary

Add a new emitPrimCast helper function and use that when evaluating floating compound operators.

Diff Detail

Event Timeline

tbaeder created this revision.Aug 10 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2023, 3:03 AM
tbaeder requested review of this revision.Aug 10 2023, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2023, 3:03 AM
tbaeder updated this revision to Diff 548985.Aug 10 2023, 5:07 AM
cor3ntin added inline comments.Aug 17 2023, 12:29 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
2676

Might as well leave a comment here too, for symmetry

tbaeder updated this revision to Diff 551132.Aug 17 2023, 7:39 AM
tbaeder marked an inline comment as done.
aaron.ballman added inline comments.Aug 17 2023, 12:07 PM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
2654
2659–2664

Should we be early returning if we're casting from float->float like we do for int->int?

2667

It weirds me out that isIntegralType() returns false for a boolean type; that is an integral type as well: http://eel.is/c++draft/basic.types#basic.fundamental-11

clang/test/AST/Interp/floats.cpp
106

Is it intentional that this is returning a float but then comparing below as an integer?

tbaeder marked an inline comment as done.Aug 18 2023, 1:57 AM
tbaeder added inline comments.
clang/lib/AST/Interp/ByteCodeExprGen.cpp
2659–2664

Heh, I was thinking the exact same thing when writing this, but

a) That means we also have to pass a QualTyp FromQT
b) I don't think we'd ever run into this problem since the AST would have to contain such a cast from/to the same floating type.

2667

I don't think there's a good reason for it to return false for bools; before this patch, the function is only used for an assertion in Neg().

clang/test/AST/Interp/floats.cpp
106

Kinda? What we compare against doesn't really matter for the compound assignment in the function, does it?

tbaeder updated this revision to Diff 551434.Aug 18 2023, 1:58 AM
aaron.ballman accepted this revision.Aug 18 2023, 5:53 AM

LGTM with a testing nit.

clang/lib/AST/Interp/ByteCodeExprGen.cpp
2659–2664

Okay, that seems reasonable to me. We can always revisit later if we find it on a hot path for some reason.

2667

Sounds like a good NFC change to make as a follow-up.

clang/test/AST/Interp/floats.cpp
106

Heh, that's why I was surprised -- it seems like odd type mismatches that are unrelated to the patch. If that's not what's being tested, might as well match the types up better so the test coverage is more clear.

This revision is now accepted and ready to land.Aug 18 2023, 5:53 AM
This revision was landed with ongoing or failed builds.Sep 5 2023, 3:16 AM
This revision was automatically updated to reflect the committed changes.