Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH,sim/sh] lvalue casts
@ 2005-05-02 15:18 Ralf Corsepius
  2005-06-17  3:13 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Ralf Corsepius @ 2005-05-02 15:18 UTC (permalink / raw)
  To: GDB Patches

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

Hi,

gcc-4.0.0 chokes on with an "invalid lvalue" error on the code generated
by sh/gencode.c (gdb-CVS mainline).

The patch below seems to fix this issue for me.

AFAIS, the "(unsigned int) R[]" cast are just superfluous.

Ralf


[-- Attachment #2: sim-sh-rc-20050502.diff --]
[-- Type: text/x-patch, Size: 701 bytes --]

2005-05-02  Ralf Corsepius <ralf.corsepius@rtems.org>

	* gencode.c (divu R0,<REG_N>): Remove lvalue casts to please gcc4.


Index: gencode.c
===================================================================
RCS file: /cvs/src/src/sim/sh/gencode.c,v
retrieving revision 1.31
diff -u -r1.31 gencode.c
--- gencode.c	14 Apr 2005 20:16:06 -0000	1.31
+++ gencode.c	2 May 2005 15:10:03 -0000
@@ -215,7 +215,7 @@
     "RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
     "if (R0 == 0)",
     "  R[n] = 0xffffffff;",
-    "else (unsigned int) R[n] = (unsigned int) R[n] / (unsigned int) R0;",
+    "else R[n] = R[n] / (unsigned int) R0;",
     "L (n);",
   },
   { "n", "0n", "mulr R0,<REG_N>", "0100nnnn10000000",

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH,sim/sh] lvalue casts
  2005-05-02 15:18 [PATCH,sim/sh] lvalue casts Ralf Corsepius
@ 2005-06-17  3:13 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2005-06-17  3:13 UTC (permalink / raw)
  To: Ralf Corsepius; +Cc: GDB Patches

On Mon, May 02, 2005 at 05:18:22PM +0200, Ralf Corsepius wrote:
> Hi,
> 
> gcc-4.0.0 chokes on with an "invalid lvalue" error on the code generated
> by sh/gencode.c (gdb-CVS mainline).
> 
> The patch below seems to fix this issue for me.
> 
> AFAIS, the "(unsigned int) R[]" cast are just superfluous.

Sorry about the delay.

> 2005-05-02  Ralf Corsepius <ralf.corsepius@rtems.org>
> 
> 	* gencode.c (divu R0,<REG_N>): Remove lvalue casts to please gcc4.
> 
> 
> Index: gencode.c
> ===================================================================
> RCS file: /cvs/src/src/sim/sh/gencode.c,v
> retrieving revision 1.31
> diff -u -r1.31 gencode.c
> --- gencode.c	14 Apr 2005 20:16:06 -0000	1.31
> +++ gencode.c	2 May 2005 15:10:03 -0000
> @@ -215,7 +215,7 @@
>      "RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
>      "if (R0 == 0)",
>      "  R[n] = 0xffffffff;",
> -    "else (unsigned int) R[n] = (unsigned int) R[n] / (unsigned int) R0;",
> +    "else R[n] = R[n] / (unsigned int) R0;",
>      "L (n);",
>    },

The second cast definitely can go; int will be promoted to unsigned int
automatically, and that's a well defined conversion.  However, the
other half is dodgier:

       [#3] Otherwise, the new type is signed and the value  cannot
       be  represented  in it; either the result is implementation-
       defined or an implementation-defined signal is raised.

So for 0xffffffff / 1u, the result is implementation-defined. 
Unfortunate.  We'll just have to propogate the assumption that
the implementation uses the sensible definition... I've committed the
below.  Now I can build GDB for sh-elf using gcc 4.0, though not with
-Werror yet.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

2005-06-16  Daniel Jacobowitz  <dan@codesourcery.com>

	* gencode.c (tab): Avoid lvalue casts.  Suggested by
	Ralf Corsepius <ralf.corsepius@rtems.org>.

Index: gencode.c
===================================================================
RCS file: /cvs/src/src/sim/sh/gencode.c,v
retrieving revision 1.31
diff -u -p -r1.31 gencode.c
--- gencode.c	14 Apr 2005 20:16:06 -0000	1.31
+++ gencode.c	17 Jun 2005 03:06:38 -0000
@@ -215,7 +215,9 @@ op tab[] =
     "RAISE_EXCEPTION_IF_IN_DELAY_SLOT ();",
     "if (R0 == 0)",
     "  R[n] = 0xffffffff;",
-    "else (unsigned int) R[n] = (unsigned int) R[n] / (unsigned int) R0;",
+    "/* FIXME: The result may be implementation-defined if it is outside */",
+    "/* the range of signed int (i.e. if R[n] was negative and R0 == 1).  */",
+    "else R[n] = R[n] / (unsigned int) R0;",
     "L (n);",
   },
   { "n", "0n", "mulr R0,<REG_N>", "0100nnnn10000000",


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-06-17  3:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-02 15:18 [PATCH,sim/sh] lvalue casts Ralf Corsepius
2005-06-17  3:13 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox