diff options
author | froydnj <froydnj@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-18 16:24:56 +0000 |
---|---|---|
committer | froydnj <froydnj@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-18 16:24:56 +0000 |
commit | 0b5fc5d69deab98a94d77800646ccd870daaaf26 (patch) | |
tree | 45ef94c714a23d36859dc3c9c965f946052c1cbc /gcc/c-family/c-semantics.c | |
parent | 1cf1c684b4582ba7ef4a96050bb7e4d98c0b2ffa (diff) | |
download | gcc-0b5fc5d69deab98a94d77800646ccd870daaaf26.tar.gz |
gcc/
PR c/33193
* c-typeck.c (build_unary_op): Call build_real_imag_expr for
REALPART_EXPR and IMAGPART_EXPR.
gcc/c-family/
PR c/33193
* c-common.h (build_real_imag_expr): Declare.
* c-semantics.c (build_real_imag_expr): Define.
gcc/cp/
PR c/33193
* typeck.c (cp_build_unary_op): Call build_real_imag_expr for
REALPART_EXPR and IMAGPART_EXPR.
gcc/testsuite/
PR c/33193
* c-c++-common/pr33193.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166909 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family/c-semantics.c')
-rw-r--r-- | gcc/c-family/c-semantics.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/c-family/c-semantics.c b/gcc/c-family/c-semantics.c index 0eccd5189e4..d26d8718021 100644 --- a/gcc/c-family/c-semantics.c +++ b/gcc/c-family/c-semantics.c @@ -140,3 +140,35 @@ build_case_label (location_t loc, { return build_stmt (loc, CASE_LABEL_EXPR, low_value, high_value, label_decl); } + +/* Build a REALPART_EXPR or IMAGPART_EXPR, according to CODE, from ARG. */ + +tree +build_real_imag_expr (location_t location, enum tree_code code, tree arg) +{ + tree ret; + tree arg_type = TREE_TYPE (arg); + + gcc_assert (code == REALPART_EXPR || code == IMAGPART_EXPR); + + if (TREE_CODE (arg_type) == COMPLEX_TYPE) + { + ret = build1 (code, TREE_TYPE (TREE_TYPE (arg)), arg); + SET_EXPR_LOCATION (ret, location); + } + else if (INTEGRAL_TYPE_P (arg_type) || SCALAR_FLOAT_TYPE_P (arg_type)) + { + ret = (code == REALPART_EXPR + ? arg + : omit_one_operand_loc (location, arg_type, + integer_zero_node, arg)); + } + else + { + error_at (location, "wrong type argument to %s", + code == REALPART_EXPR ? "__real" : "__imag"); + ret = error_mark_node; + } + + return ret; +} |