This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix consteval initializers of temporaries
ClosedPublic

Authored by Fznamznon on Mar 24 2023, 4:03 AM.

Details

Summary

When a potential immediate invocation is met, it is immediately wrapped by a
ConstantExpr. There is also a TreeTransform that removes this ConstantExpr
wrapper when corresponding expression evaluation context is popped.
So, in case initializer was an immediate invocation, CXXTemporaryObjectExpr
was wrapped by a ConstantExpr, and that caused additional unnecessary
CXXFunctionalCastExpr to be added, which later confused the TreeTransform
that rebuilds immediate invocations, so it was adding unnecessary
constructor call.

Fixes https://github.com/llvm/llvm-project/issues/60286

Diff Detail

Event Timeline

Fznamznon created this revision.Mar 24 2023, 4:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 4:03 AM
Fznamznon requested review of this revision.Mar 24 2023, 4:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2023, 4:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman accepted this revision.Mar 24 2023, 6:39 AM

The changes LGTM (though I had a small nit), but you should add a release note when landing.

clang/lib/Sema/SemaExprCXX.cpp
1593–1595

This will need reformatting, but because we can use C++17 features, we can be slightly fancier here. :-)

NB: I think we don't need to use dyn_cast_or_null here or on the predicate above. We're calling isa<Whatever>(Inner) immediately below and that will assert if Inner was null, so it seems like we're already relying on Inner being nonnull.

This revision is now accepted and ready to land.Mar 24 2023, 6:39 AM
Fznamznon updated this revision to Diff 508082.Mar 24 2023, 7:12 AM

Apply the suggestion

Fznamznon added inline comments.Mar 24 2023, 7:13 AM
clang/lib/Sema/SemaExprCXX.cpp
1593–1595

That makes sense, thank you.
Although, I can't make CE const because Inner is not const.

aaron.ballman added inline comments.Mar 24 2023, 7:15 AM
clang/lib/Sema/SemaExprCXX.cpp
1593–1595

Ah, that's fine, no worries about the const then. That suggestion is mostly a reflex for me at this point. :-D

Fznamznon updated this revision to Diff 508524.Mar 27 2023, 1:34 AM

Rebase, maybe this will get "pre-commit" started

aaron.ballman accepted this revision.Mar 27 2023, 11:22 AM

LGTM! Precommit CI is still falling over because of the libcxx bot. That issue is being actively investigated, but we don't have an ETA on it being resolved. I think these changes are sufficiently safe to land and watch for post-commit failures.

This revision was automatically updated to reflect the committed changes.