This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Pass CallExpr to builtin functions
ClosedPublic

Authored by tbaeder on Jul 17 2023, 10:55 PM.

Details

Summary
For some builtins, we need to do quite a bit of type checking ourselves,
so pass the call expression along. This way we can inspect arguments,
expected return value, etc.

As discussed with @aaron.ballman on Discord, reject non-StringLiteral inputs from __builtin_isnan().

Diff Detail

Event Timeline

tbaeder created this revision.Jul 17 2023, 10:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 10:55 PM
tbaeder requested review of this revision.Jul 17 2023, 10:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 10:55 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added inline comments.Jul 18 2023, 12:38 PM
clang/lib/AST/Interp/InterpBuiltin.cpp
78–79

Hmmm, I think I missed a situation when we were talking about this. Consider: https://godbolt.org/z/14dz5MMPj

I think the current interpreter is wrong to reject that code (I think the GCC behavior is correct). If you remove the constexpr from the declaration of Nan2, it compiles fine.

WDYT?

clang/test/AST/Interp/builtin-functions.cpp
44 ↗(On Diff #541323)

I mentioned this on another review, but I think the current interpreter is wrong to reject this because that lambda is constexpr-suitable.

http://eel.is/c++draft/expr.prim.lambda#closure-5
http://eel.is/c++draft/dcl.constexpr#3

tbaeder updated this revision to Diff 541834.Jul 18 2023, 9:11 PM
tbaeder marked an inline comment as done.
This revision is now accepted and ready to land.Jul 26 2023, 10:22 AM
This revision was landed with ongoing or failed builds.Aug 17 2023, 1:21 AM
This revision was automatically updated to reflect the committed changes.