[all-commits] [llvm/llvm-project] 1adef2: [TableGen] Use guarded assert in constexpr functions
Krzysztof Parzyszek via All-commits
all-commits at lists.llvm.org
Tue Apr 28 14:10:27 PDT 2026
Branch: refs/heads/users/kparzysz/constexpr-unreachable
Home: https://github.com/llvm/llvm-project
Commit: 1adef29fdfc6a9bb3165cb8870512a0534269788
https://github.com/llvm/llvm-project/commit/1adef29fdfc6a9bb3165cb8870512a0534269788
Author: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: 2026-04-28 (Tue, 28 Apr 2026)
Changed paths:
M llvm/test/TableGen/directive1.td
M llvm/test/TableGen/directive2.td
M llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
Log Message:
-----------
[TableGen] Use guarded assert in constexpr functions
The constexpr functions in question take a scoped enum as an argument
and a switch statement returns a value for each value of the enum.
These are all legal statements in a constexpr function in C++14.
Under constexpr rules, the evaluation of a constexpr function cannot
lead to an evaluation of any prohibited forms of expressions. An
evaluation of the functions being discussed with a valid argument
will terminate at the switch, and an code that follows will not be
evaluated.
Using "llvm_unreachable" after the switch should be ok as long as
the expansion of the llvm_unreachable macro does not contain any
statements not allowed to appear in a constexpr function.
At the same time, GCC before v9 did not tolerate any unguarded calls
to non-constexpr functions after the switch.
To avoid using "llvm_unreachable", which can have multiple expansions,
use an assert with an explicit condition that the underlying value of
the argument lies between the minimum and maximum values of the enum.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list