aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/d-convert.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-06-26 09:57:21 -0700
committerIan Lance Taylor <iant@golang.org>2023-06-26 09:57:21 -0700
commitaa1e672b5d99102b03eb5fb9c51609c45f62bff7 (patch)
tree886212591b1c9d127eaaf234a4a2e22452ea384a /gcc/d/d-convert.cc
parent97e31a0a2a2d2273687fcdb4e5416aab1a2186e1 (diff)
parent3a39a31b8ae9c6465434aefa657f7fcc86f905c0 (diff)
downloadgcc-devel/gccgo.zip
gcc-devel/gccgo.tar.gz
gcc-devel/gccgo.tar.bz2
Merge from trunk revision 3a39a31b8ae9c6465434aefa657f7fcc86f905c0.devel/gccgo
Diffstat (limited to 'gcc/d/d-convert.cc')
-rw-r--r--gcc/d/d-convert.cc31
1 files changed, 19 insertions, 12 deletions
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index cdbd69c..2b9d8e7 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -619,7 +619,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
return result ? result : convert (build_ctype (totype), exp);
}
-/* Return a TREE represenwation of EXPR, whose type has been converted from
+/* Return a TREE representation of EXPR, whose type has been converted from
* ETYPE to TOTYPE, and is being used in an rvalue context. */
tree
@@ -634,20 +634,27 @@ convert_for_rvalue (tree expr, Type *etype, Type *totype)
{
/* If casting from bool, the result is either 0 or 1, any other value
violates @safe code, so enforce that it is never invalid. */
- if (CONSTANT_CLASS_P (expr))
- result = d_truthvalue_conversion (expr);
- else
+ for (tree ref = expr; TREE_CODE (ref) == COMPONENT_REF;
+ ref = TREE_OPERAND (ref, 0))
{
- /* Reinterpret the boolean as an integer and test the first bit.
- The generated code should end up being equivalent to:
+ /* If the expression is a field that's part of a union, reinterpret
+ the boolean as an integer and test the first bit. The generated
+ code should end up being equivalent to:
*cast(ubyte *)&expr & 1; */
- machine_mode bool_mode = TYPE_MODE (TREE_TYPE (expr));
- tree mtype = lang_hooks.types.type_for_mode (bool_mode, 1);
- result = fold_build2 (BIT_AND_EXPR, mtype,
- build_vconvert (mtype, expr),
- build_one_cst (mtype));
+ if (TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == UNION_TYPE)
+ {
+ machine_mode bool_mode = TYPE_MODE (TREE_TYPE (expr));
+ tree mtype = lang_hooks.types.type_for_mode (bool_mode, 1);
+ result = fold_build2 (BIT_AND_EXPR, mtype,
+ build_vconvert (mtype, expr),
+ build_one_cst (mtype));
+ break;
+ }
}
+ if (result == NULL_TREE)
+ result = d_truthvalue_conversion (expr);
+
result = convert (build_ctype (tbtype), result);
}
@@ -844,7 +851,7 @@ convert_for_condition (tree expr, Type *type)
break;
default:
- result = expr;
+ result = convert_for_rvalue (expr, type, type);
break;
}