aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-09-18 13:28:51 +0200
committerEugen Wissner <belka@caraus.de>2026-09-18 13:28:51 +0200
commitea8d4c933fc0a449920f453d0ddff1ba9e8a99a6 (patch)
tree87265b3552ae4a3c7372bb48ae988b547b44bbdb
parentdc9d03915c4b169fec749081b45d56f722105813 (diff)
downloadelna-ea8d4c933fc0a449920f453d0ddff1ba9e8a99a6.tar.gz
Handle assert(false) as unreachable, skip assert(true)
-rw-r--r--gcc/gcc/elna-generic.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc
index f4cb3c3..1853e60 100644
--- a/gcc/gcc/elna-generic.cc
+++ b/gcc/gcc/elna-generic.cc
@@ -70,25 +70,30 @@ namespace elna::gcc
vec_safe_address(argument_trees));
}
+ // The literal spelling chooses the code generation, so the programmer can ask for
+ // unreachability or for no code at all. A condition that merely folds to a constant
+ // is asserted like any other.
void generic_visitor::build_assert_builtin(location_t call_location,
const std::vector<boot::expression *>& arguments)
{
- arguments.at(0)->accept(this);
- tree constant_expression = extract_constant(this->current_expression);
+ boot::literal_expression *const literal = arguments.at(0)->is_literal();
+ const boot::literal<bool> *const condition = literal == nullptr ? nullptr : literal->is_a<bool>();
- if (constant_expression == boolean_false_node)
+ if (condition != nullptr && !condition->value)
{
this->current_expression = call_built_in(call_location, "__builtin_unreachable", void_type_node);
}
- else if (constant_expression != boolean_true_node)
+ else if (condition != nullptr)
{
- tree assert_expression = call_built_in(call_location, "__builtin_trap", void_type_node);
- this->current_expression = build3(COND_EXPR, void_type_node, this->current_expression,
- NULL_TREE, assert_expression);
+ this->current_expression = NULL_TREE;
}
else
{
- this->current_expression = NULL_TREE;
+ arguments.at(0)->accept(this);
+
+ tree assert_expression = call_built_in(call_location, "__builtin_trap", void_type_node);
+ this->current_expression = build3(COND_EXPR, void_type_node, this->current_expression,
+ NULL_TREE, assert_expression);
}
}