This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
creal should not return an lvalue
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 20 Oct 2003 23:00:01 +0100 (BST)
- Subject: creal should not return an lvalue
The GCC operators __real__ and __imag__ return lvalues when their argument
is an lvalue, but the creal and cimag built-in functions shouldn't; a
recent thread on comp.std.c drew attention to this bug. Fixed thus.
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline.
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 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/builtins-28.c: New test.
--- GCC/gcc/c-common.c.orig 2003-10-15 08:05:45.000000000 +0000
+++ GCC/gcc/c-common.c 2003-10-20 13:43:20.000000000 +0000
@@ -3740,14 +3740,16 @@ expand_tree_builtin (tree function, tree
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);
--- GCC/gcc/testsuite/gcc.dg/builtins-28.c 2002-08-26 16:21:36.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/builtins-28.c 2003-10-20 14:53:38.000000000 +0000
@@ -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" } */
+}
--
Joseph S. Myers
jsm@polyomino.org.uk