You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following program calling a consteval function causes code to be emitted to compute the result of maxFoo() at runtime, when one would expect it to be computed at compile-time:
After playing around and debugging Clang for a bit, I am fairly confident that this is not a bug per-se, but only an important QOI issue. In particular, I think Clang behaves correctly with respect to the Standard, which only says about immediate functions (http://eel.is/c++draft/expr.const#13):
> [...] An expression or conversion is an immediate invocation if
> it is a potentially-evaluated explicit or implicit invocation of
> an immediate function and is not in an immediate function context.
> An immediate invocation shall be a constant expression.
This doesn't talk about codegen, since the Standard doesn't have such a notion. Also, Clang does treat maxFoo() as a constant expression, and in fact the front-end even calculates the result properly in an APValue -- so Clang is correct as far as the Standard is concerned.
However, the code generation appears to never be passed that knowledge, and as a result it can sometimes fail to fold the immediate call, depending on optimization levels. Since the intent of consteval was specifically to make sure that no code is generated for such calls, I would argue this is an important QOI issue (if we're being pedantic), and straight up a bug (as far as 99% of users are concerned).
The text was updated successfully, but these errors were encountered:
This may not technically be a bug, but it is a serious deviation from the intent, and this is one of the primary reasons why Clang does not claim to support consteval yet.
Extended Description
The following program calling a consteval function causes code to be emitted to compute the result of maxFoo() at runtime, when one would expect it to be computed at compile-time:
Here's a few interesting observations:
maxFoo()
equivalently but in a single expression.consteval
is used or not (which leads me to think this is a codegen issue, not a front-end issue).Godbolt link: https://godbolt.org/z/MA9U8b
After playing around and debugging Clang for a bit, I am fairly confident that this is not a bug per-se, but only an important QOI issue. In particular, I think Clang behaves correctly with respect to the Standard, which only says about immediate functions (http://eel.is/c++draft/expr.const#13):
This doesn't talk about codegen, since the Standard doesn't have such a notion. Also, Clang does treat
maxFoo()
as a constant expression, and in fact the front-end even calculates the result properly in an APValue -- so Clang is correct as far as the Standard is concerned.However, the code generation appears to never be passed that knowledge, and as a result it can sometimes fail to fold the immediate call, depending on optimization levels. Since the intent of consteval was specifically to make sure that no code is generated for such calls, I would argue this is an important QOI issue (if we're being pedantic), and straight up a bug (as far as 99% of users are concerned).
The text was updated successfully, but these errors were encountered: