This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Start implementing builtin functions
ClosedPublic

Authored by tbaeder on Nov 5 2022, 5:13 AM.

Details

Summary

Another try at this.

This time, only implement __builtin_is_constant_evaluated().

Unfortunately I can't just use clang/test/SemaCXX/builtin-is-constant-evaluated.cpp because there are some other unsupported expressions in there.

Diff Detail

Event Timeline

tbaeder created this revision.Nov 5 2022, 5:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2022, 5:13 AM
tbaeder requested review of this revision.Nov 5 2022, 5:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2022, 5:13 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tschuett added inline comments.
clang/lib/AST/Interp/InterpBuiltin.cpp
14

You are allowed to use nested namespaces.

tbaeder updated this revision to Diff 473443.Nov 5 2022, 10:40 AM
erichkeane added inline comments.Nov 28 2022, 8:10 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
1374

This is an unrelated change, perhaps could be in an NFC commit.

clang/lib/AST/Interp/Interp.h
1354–1358

directly reads oddly here? Do you mean the 'immediately' definition of this?

1355

Rather than the 'if'/'else' pair, do we just want to immediately return on the failed builtin?

1357

What is going on here? Why is this not a leak?

tbaeder added inline comments.Nov 28 2022, 8:17 AM
clang/lib/AST/Interp/ByteCodeExprGen.cpp
1374

Right, sure

clang/lib/AST/Interp/Interp.h
1354–1358

Yes, that was the purpose. I can reword it.

1355

Sure, that's possible. I guess this ties into the question of whether to use a different opcode for builtin functions; but so far I have found builtin calls to be too similar to regular ones, esp. since they don't have a special AST node.

1357

The current frame is deleted when successfully returning the value of the function, this happens in the Ret (and RetVoid) function in Interp.cpp.

No opinion on whether that's the best way to do it though.

erichkeane added inline comments.Nov 28 2022, 8:19 AM
clang/lib/AST/Interp/Interp.h
1357

I really dont like doing it this way, I see we're doing it the same in 1366, but if we're expecting someone else to delete a unique-ptr, we should give them ownership of the whole unique-ptr. This mechanism is just obscuring the ownership semantics that unique_ptr is supposed to imply.

tbaeder added inline comments.Nov 28 2022, 8:22 AM
clang/lib/AST/Interp/Interp.h
1357

I blame @aaron.ballman :)

I'm gonna write it on my list and create a follow-up patch.

tbaeder updated this revision to Diff 479201.Dec 1 2022, 1:56 AM

Split CallBI out from Call, so we don't need special cases in CheckCallable etc. for builtin functions.

erichkeane accepted this revision.Dec 1 2022, 6:26 AM
This revision is now accepted and ready to land.Dec 1 2022, 6:26 AM
shafik added inline comments.Jan 11 2023, 10:03 PM
clang/lib/AST/Interp/Interp.h
1392

We don't have to update S.Current?

clang/lib/AST/Interp/InterpBuiltin.cpp
21

Why not just factor out Ret now?

tbaeder marked 2 inline comments as done.Jan 12 2023, 3:43 AM
tbaeder added inline comments.
clang/lib/AST/Interp/Interp.h
1392

Nope, Ret does that.

clang/lib/AST/Interp/InterpBuiltin.cpp
21

The two implementations are slightly different now and I wanted to see if they diverge more int he future. But I've factored them together as part of https://reviews.llvm.org/D141193

This revision was landed with ongoing or failed builds.Jan 25 2023, 5:08 AM
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.