This is an archive of the discontinued LLVM Phabricator instance.

Fix template instantiation of UDLs
ClosedPublic

Authored by aaron.ballman on Mar 28 2022, 7:49 AM.

Details

Reviewers
erichkeane
rsmith
cor3ntin
Group Reviewers
Restricted Project
Summary

Previously, we would instantiate the UDL by marking the function as referenced and potentially binding to a temporary; this skipped transforming the call when the UDL was dependent on a template parameter.

Now, we defer all the work to instantiating the call expression for the UDL. This ensures that constant evaluation occurs at compile time rather than deferring until runtime.

Fixes Issue 54578.

Diff Detail

Event Timeline

aaron.ballman created this revision.Mar 28 2022, 7:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 7:49 AM
aaron.ballman requested review of this revision.Mar 28 2022, 7:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2022, 7:49 AM
erichkeane added inline comments.Mar 28 2022, 7:54 AM
clang/lib/Sema/TreeTransform.h
10516

I THINK you have to do this by doing getDerived().TransformCallExpr(E).

cor3ntin accepted this revision.Mar 28 2022, 7:56 AM
cor3ntin added a subscriber: cor3ntin.

LGTM.

clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
28

I've used things like ghXXXX previously. for my own curiosity, is there a convention here?

This revision is now accepted and ready to land.Mar 28 2022, 7:56 AM
cor3ntin added inline comments.Mar 28 2022, 7:57 AM
clang/lib/Sema/TreeTransform.h
10516

Oh yes, good point

cor3ntin requested changes to this revision.Mar 28 2022, 7:57 AM
This revision now requires changes to proceed.Mar 28 2022, 7:57 AM
aaron.ballman added inline comments.Mar 28 2022, 8:05 AM
clang/lib/Sema/TreeTransform.h
10516

Hmmm, don't we want this level of transformation to kick in, not the derived? e.g., another approach would be to remove the definition of this function entirely so that the recursive AST visitor calls TransformCallExpr() instead?

clang/test/CodeGenCXX/cxx20-consteval-crash.cpp
28

I don't know if we've organically gotten a convention here yet or not. I've been using Issue for mine, but don't have a strong preference either.

erichkeane added inline comments.Mar 28 2022, 8:09 AM
clang/lib/Sema/TreeTransform.h
10516

No, the idea is that TreeTransform is inherited by other 'instantiator' types. IF those types do something special for CallExpr, we want this to ALSO do the same thing as CallExpr.

I was also thinking about removing the function altogether. I just couldn't remember if TreeTransform did that right :) I'd suggest that if possible.

aaron.ballman marked 3 inline comments as done.

Update based on review feedback

cor3ntin accepted this revision.Mar 28 2022, 11:26 AM
cor3ntin added inline comments.
clang/lib/Sema/TreeTransform.h
10516

I tried to remove the overload entirely, clang was deeply unhappy :)

This revision is now accepted and ready to land.Mar 28 2022, 11:26 AM
erichkeane accepted this revision.Mar 28 2022, 11:27 AM

Thanks for the reviews! I've commit in ca844ab01c3f9410ceca967c09f809400950beae.