diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-09-08 10:46:13 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-09-08 10:46:13 +0200 |
| commit | 72f0f9b9629013e83fc4346a35113e9eecae45b5 (patch) | |
| tree | 47779eda823f936e1c8d3e99dfc153901497c34f /gcc | |
| parent | 72f5e82196d95008ed12c12de6bdccf24361e106 (diff) | |
| download | elna-72f0f9b9629013e83fc4346a35113e9eecae45b5.tar.gz | |
Allow compile-time casts
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/gcc/elna-generic.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index 9bb1e89..45d8311 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "dumpfile.h" #include "stringpool.h" #include "fold-const.h" +#include "convert.h" #include "langhooks.h" namespace elna::gcc @@ -156,6 +157,30 @@ namespace elna::gcc this->current_expression = build_slice(cast_target, ptr, new_length); } + else if (TREE_CODE(cast_target) == BOOLEAN_TYPE + && TREE_CODE(TREE_TYPE(this->current_expression)) != BOOLEAN_TYPE) + { + // Converting would keep the least significant bit only, but every + // non-zero value stands for true. + tree zero = build_zero_cst(TREE_TYPE(this->current_expression)); + + this->current_expression = build2_loc(cast_location, NE_EXPR, cast_target, + this->current_expression, zero); + } + else if (SCALAR_FLOAT_TYPE_P(TREE_TYPE(this->current_expression)) + && INTEGRAL_TYPE_P(cast_target)) + { + // fold_convert cannot build the FIX_TRUNC_EXPR this conversion needs + // and asserts instead. + this->current_expression = convert_to_integer(cast_target, this->current_expression); + } + else if (SCALAR_FLOAT_TYPE_P(TREE_TYPE(this->current_expression)) + && POINTER_TYPE_P(cast_target)) + { + tree address = convert_to_integer(elna_word_type_node, this->current_expression); + + this->current_expression = fold_convert_loc(cast_location, cast_target, address); + } else { this->current_expression = fold_convert_loc(cast_location, cast_target, this->current_expression); |
