c-common.c (expand_tree_builtin): Ensure creal and cimag functions do not return...
authorJoseph Myers <jsm@polyomino.org.uk>
Mon, 20 Oct 2003 22:03:34 +0000 (23:03 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 20 Oct 2003 22:03:34 +0000 (23:03 +0100)
* c-common.c (expand_tree_builtin): Ensure creal and cimag
functions do not return lvalues.

testsuite:
* gcc.dg/builtins-28.c: New test.

From-SVN: r72727

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-28.c [new file with mode: 0644]

index 4b914ee..7e707d7 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-20  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       * c-common.c (expand_tree_builtin): Ensure creal and cimag
+       functions do not return lvalues.
+
 2003-10-20  Jason Merrill  <jason@redhat.com>
 
        PR c/12553
index 96186d8..1d32d96 100644 (file)
@@ -3752,14 +3752,16 @@ expand_tree_builtin (tree function, tree params, tree coerced_params)
     case BUILT_IN_CREALL:
       if (coerced_params == 0)
        return integer_zero_node;
-      return build_unary_op (REALPART_EXPR, TREE_VALUE (coerced_params), 0);
+      return non_lvalue (build_unary_op (REALPART_EXPR,
+                                        TREE_VALUE (coerced_params), 0));
 
     case BUILT_IN_CIMAG:
     case BUILT_IN_CIMAGF:
     case BUILT_IN_CIMAGL:
       if (coerced_params == 0)
        return integer_zero_node;
-      return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
+      return non_lvalue (build_unary_op (IMAGPART_EXPR,
+                                        TREE_VALUE (coerced_params), 0));
 
     case BUILT_IN_ISGREATER:
       return expand_unordered_cmp (function, params, UNLE_EXPR, LE_EXPR);
index 20bac33..a4509eb 100644 (file)
@@ -1,3 +1,7 @@
+2003-10-20  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       * gcc.dg/builtins-28.c: New test.
+
 2003-10-20  Jan Hubicka  <jh@suse.cz>
 
        * testsuite/g++.dg/opt/inline4.C: Do not use min-inline-insns
diff --git a/gcc/testsuite/gcc.dg/builtins-28.c b/gcc/testsuite/gcc.dg/builtins-28.c
new file mode 100644 (file)
index 0000000..bd76d6b
--- /dev/null
@@ -0,0 +1,27 @@
+/* Test that creal and cimag built-in functions do not return lvalues.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern float crealf (float _Complex);
+extern double creal (double _Complex);
+extern long double creall (long double _Complex);
+
+extern float cimagf (float _Complex);
+extern double cimag (double _Complex);
+extern long double cimagl (long double _Complex);
+
+float _Complex fc;
+double _Complex dc;
+long double _Complex ldc;
+
+void
+foo (void)
+{
+  crealf (fc) = 0; /* { dg-error "lvalue" "crealf not lvalue" } */
+  cimagf (fc) = 0; /* { dg-error "lvalue" "cimagf not lvalue" } */
+  creal (dc) = 0; /* { dg-error "lvalue" "creal not lvalue" } */
+  cimag (dc) = 0; /* { dg-error "lvalue" "cimag not lvalue" } */
+  creall (ldc) = 0; /* { dg-error "lvalue" "creall not lvalue" } */
+  cimagl (ldc) = 0; /* { dg-error "lvalue" "cimagl not lvalue" } */
+}