]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/33193 (slopiness in __real/__imag)
authorNathan Froyd <froydnj@codesourcery.com>
Thu, 18 Nov 2010 16:24:56 +0000 (16:24 +0000)
committerNathan Froyd <froydnj@gcc.gnu.org>
Thu, 18 Nov 2010 16:24:56 +0000 (16:24 +0000)
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.

From-SVN: r166909

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/c-semantics.c
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr33193.c [new file with mode: 0644]

index 7aa714c802f27d308697d0df5d6af5dbf100a42b..53750914b661e7a8ca0e69e6c127ab2da3e1686b 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-18  Nathan Froyd  <froydnj@codesourcery.com>
+
+       PR c/33193
+       * c-typeck.c (build_unary_op): Call build_real_imag_expr for
+       REALPART_EXPR and IMAGPART_EXPR.
+
 2010-11-18  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/46172
index 81e636c28f507a4c12713ae200d1693f5ea0c29b..86fbd1335106e49e6024a9796438437158ebbc05 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-18  Nathan Froyd  <froydnj@codesourcery.com>
+
+       PR c/33193
+       * c-common.h (build_real_imag_expr): Declare.
+       * c-semantics.c (build_real_imag_expr): Define.
+
 2010-11-17  Joseph Myers  <joseph@codesourcery.com>
 
        * c-opts.c (c_common_parse_file): Take no arguments.
index 76842d2ded1b921e59bcdfa4f0d83e121c780463..3de32cf6ddaa5f182edfc0c07ac70d2be0d958dd 100644 (file)
@@ -822,6 +822,7 @@ extern void warn_for_omitted_condop (location_t, tree);
 extern tree do_case (location_t, tree, tree);
 extern tree build_stmt (location_t, enum tree_code, ...);
 extern tree build_case_label (location_t, tree, tree, tree);
+extern tree build_real_imag_expr (location_t, enum tree_code, tree);
 
 /* These functions must be defined by each front-end which implements
    a variant of the C language.  They are used in c-common.c.  */
index 0eccd5189e4b0c8ab17b5466bb50d4aaafcba89a..d26d8718021b96e1ebf08800113b5833d54011da 100644 (file)
@@ -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;
+}
index 2bfa97be68e6b238f9741b9e79b1945151fdf0da..9aca720fd71a38965276cfcde6577620d799e9f4 100644 (file)
@@ -3561,26 +3561,10 @@ build_unary_op (location_t location,
       goto return_build_unary_op;
 
     case REALPART_EXPR:
-      if (TREE_CODE (arg) == COMPLEX_CST)
-       ret = TREE_REALPART (arg);
-      else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
-       ret = fold_build1_loc (location,
-                              REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
-      else
-       ret = arg;
-      if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
-       eptype = TREE_TYPE (eptype);
-      goto return_build_unary_op;
-
     case IMAGPART_EXPR:
-      if (TREE_CODE (arg) == COMPLEX_CST)
-       ret = TREE_IMAGPART (arg);
-      else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
-       ret = fold_build1_loc (location,
-                              IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
-      else
-       ret = omit_one_operand_loc (location, TREE_TYPE (arg),
-                               integer_zero_node, arg);
+      ret = build_real_imag_expr (location, code, arg);
+      if (ret == error_mark_node)
+       return error_mark_node;
       if (eptype && TREE_CODE (eptype) == COMPLEX_TYPE)
        eptype = TREE_TYPE (eptype);
       goto return_build_unary_op;
index 8c76af67bcd39e0188bd577fccb854ec7d912aa9..6f9bb075f288394dc81cde483b2f5064a474505b 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-18  Nathan Froyd  <froydnj@codesourcery.com>
+
+       PR c/33193
+       * typeck.c (cp_build_unary_op): Call build_real_imag_expr for
+       REALPART_EXPR and IMAGPART_EXPR.
+
 2010-11-16  Jason Merrill  <jason@redhat.com>
 
        * call.c (convert_like_real): Don't make a temp for copy-list-init.
index 92a7d9ed6deabde68bb3be89314d7ad84a4983de..df31d875dca0a149ebc64fb38dbac3627effea28 100644 (file)
@@ -5098,26 +5098,12 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
       break;
 
     case REALPART_EXPR:
-      if (TREE_CODE (arg) == COMPLEX_CST)
-       return TREE_REALPART (arg);
-      else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
-       {
-         arg = build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
-         return fold_if_not_in_template (arg);
-       }
-      else
-       return arg;
-
     case IMAGPART_EXPR:
-      if (TREE_CODE (arg) == COMPLEX_CST)
-       return TREE_IMAGPART (arg);
-      else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
-       {
-         arg = build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg);
-         return fold_if_not_in_template (arg);
-       }
+      arg = build_real_imag_expr (input_location, code, arg);
+      if (arg == error_mark_node)
+       return arg;
       else
-       return cp_convert (TREE_TYPE (arg), integer_zero_node);
+       return fold_if_not_in_template (arg);
 
     case PREINCREMENT_EXPR:
     case POSTINCREMENT_EXPR:
index 9eace4d767ac603097db15dba562108cdf65a29b..a5b14f964a37bb41fc4ee69e8a239a7b9aae60b5 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-18  Nathan Froyd  <froydnj@codesourcery.com>
+
+       PR c/33193
+       * c-c++-common/pr33193.c: New test.
+
 2010-11-18  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/46172
diff --git a/gcc/testsuite/c-c++-common/pr33193.c b/gcc/testsuite/c-c++-common/pr33193.c
new file mode 100644 (file)
index 0000000..2d19298
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR c/33193 */
+/* { dg-do compile } */
+
+struct a {float x, y; };
+
+float f(struct a b)
+{
+  /* The error messages here are different between C and C++, so just
+     make sure we get an error.  */
+  float x = __real b;          /* { dg-error "" } */
+  float y = __imag b;          /* { dg-error "" } */
+  return x / y;
+}
+int f1(int *b)
+{
+  float x = __imag b;          /* { dg-error "wrong type argument" } */
+  float y = __real b;          /* { dg-error "wrong type argument" } */
+  return x - y;
+}