[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 20 09:17:17 PDT 2024
================
@@ -4368,8 +4363,19 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
if (!visitDeclStmt(CondDecl))
return false;
- if (!this->visitBool(IS->getCond()))
- return false;
+ // Compile condition.
+ if (IS->isNonNegatedConsteval()) {
+ if (!this->emitIsConstantContext(IS))
+ return false;
+ } else if (IS->isNegatedConsteval()) {
+ if (!this->emitIsConstantContext(IS))
+ return false;
+ if (!this->emitInv(IS))
+ return false;
+ } else {
+ if (!this->visitBool(IS->getCond()))
+ return false;
+ }
----------------
cor3ntin wrote:
the whole point of `if consteval` is to allow a runtime evaluation to do thing that would not be valid in constant context, such as asm or simd or reinterpret cast or crazy vendor extensions.
so
```cpp
constexpr void f() {
if !consteval {
// copy a volatile vla with simd and execute a gpu kernel
}
}
```
is intended to always work.
I don't think it would be reasonable to delay adoption of the new interpreter until we support _all_ the features of clang in the bytecode.
So this approach is probably not viable.
If you really want to create bytecode for both branches, you need to have an escape hatch so that if the non-consteval branch cannot produce bytecode, we still can support the consteval branch without error
https://github.com/llvm/llvm-project/pull/104707
More information about the cfe-commits
mailing list