This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Sema] Do not evaluate value-dependent immediate invocations
ClosedPublic

Authored by Izaron on Feb 9 2022, 1:38 PM.

Details

Summary

Value-dependent ConstantExprs are not meant to be evaluated.
There is an assert in Expr::EvaluateAsConstantExpr that ensures this condition.
But before this patch the method was called without prior check.

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

Diff Detail

Event Timeline

Izaron requested review of this revision.Feb 9 2022, 1:38 PM
Izaron created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2022, 1:38 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Izaron added a comment.Feb 9 2022, 1:48 PM

The assert that I mentioned in the summary: https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L14969
(Although asserts are deleted in release builds, one can check the violation by llvm::errs() << isValueDependent() << "\n"; in the method)

I think I have found the right place to check the condition, right after creating the ConstantExpr object.

P.S. If this review is eventually approved, kindly please merge the commit on my behalf =) As I don't have merge access. My name is Evgeny Shulgin and email is izaronplatz@gmail.com. Sorry for inconvenience!

This looks like the right fix to me but I would prefer @aaron.ballman or @erichkeane to have the final say.

clang/lib/Sema/SemaExpr.cpp
16820–16823

I'd say something like

/ Value-dependent constant expressionS should not be immediately
evaluated until they are instantiated.

Izaron updated this revision to Diff 407449.Feb 10 2022, 2:55 AM

Fix comment

Izaron marked an inline comment as done.Feb 10 2022, 2:55 AM
Izaron added inline comments.
clang/lib/Sema/SemaExpr.cpp
16820–16823

Sure, thanks! I'm bad at writing comments =)

Izaron marked an inline comment as done.Feb 10 2022, 2:56 AM
erichkeane accepted this revision.Feb 10 2022, 6:06 AM

1 nit, but otherwise I'm happy with this.

clang/test/SemaCXX/cxx2a-consteval.cpp
616

A quick comment on this test as to why it has no diagnostics would be nice.

This revision is now accepted and ready to land.Feb 10 2022, 6:06 AM
Izaron updated this revision to Diff 407564.Feb 10 2022, 9:10 AM

Add test comments

Izaron marked an inline comment as done.Feb 10 2022, 9:10 AM

A friendly ping =) Seems like I don't have write access, so unfortunately I have to ask people to merge commits on my behalf. Let me copy-paste the usual comment of my reviews:

P.S. If this review is eventually approved, kindly please merge the commit on my behalf =) As I don't have merge access. My name is Evgeny Shulgin and email is izaronplatz@gmail.com. Sorry for inconvenience!

A friendly ping =) Seems like I don't have write access, so unfortunately I have to ask people to merge commits on my behalf. Let me copy-paste the usual comment of my reviews:

I landed your change.
Thanks for the patch!