This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
gas:Reject ++ and --
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: binutils at sources dot redhat dot com
- Date: Wed, 17 Mar 2004 16:23:37 +0000
- Subject: gas:Reject ++ and --
- Organization: Codesourcery LLC
Hi,
the attached patch causes gas to not interpret ++ and -- as two
+ or - operators in a row. The current behaviour is to allow
'a ++ b' as if it was 'a + (+b)' and '++ a' as if '+(+a)'. The problem
I was having was a port which had an addressing mode syntax of the form
reg++[reg]
and desiring to process this as
<expr> "++[" <expr> "]"
but the expression evaluator ate the '++' as two '+' operators and
then barfed.
Regardless of those issues, the current '++' and '--' behaviour surprises
at least some programmers (me and my users :)
built and tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2004-03-17 Nathan Sidwell <nathan@codesourcery.com>
* expr.c (operand): Reject ++ and --.
(operator): Likewise.
Index: gas/expr.c
===================================================================
RCS file: /home/icera/Repository/binutils/gas/expr.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 expr.c
*** gas/expr.c 20 Jan 2004 19:23:53 -0000 1.1
--- gas/expr.c 17 Mar 2004 12:37:08 -0000
*************** operand (expressionP)
*** 1045,1050 ****
--- 1045,1053 ----
break;
case '+':
+ /* Do not accept ++e as +(+e) */
+ if (input_line_pointer[1] == '+')
+ goto target_op;
(void) operand (expressionP);
break;
*************** operand (expressionP)
*** 1062,1067 ****
--- 1065,1074 ----
case '!':
case '-':
{
+ /* Do not accept --e as -(-e) */
+ if (c == '-' && input_line_pointer[1] == '-')
+ goto target_op;
+
operand (expressionP);
if (expressionP->X_op == O_constant)
{
*************** operand (expressionP)
*** 1313,1318 ****
--- 1320,1326 ----
}
else
{
+ target_op:
/* Let the target try to parse it. Success is indicated by changing
the X_op field to something other than O_absent and pointing
input_line_pointer past the expression. If it can't parse the
*************** operator (num_chars)
*** 1566,1571 ****
--- 1574,1586 ----
{
default:
return op_encoding[c];
+
+ case '+':
+ case '-':
+ /* Do not allow a++b and a--b to be a + (+b) and a - (-b) */
+ if (input_line_pointer[1] != c)
+ return op_encoding[c];
+ return O_illegal;
case '<':
switch (input_line_pointer[1])