[llvm-commits] [llvm] r156714 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/macro-rept-err1.s test/MC/A

PaX Team pageexec at freemail.hu
Thu Jul 19 13:09:01 PDT 2012


On 17 Jul 2012 at 17:36, Zhang, Andy wrote:

Hi Andy,

> Hi PaX,
> 
> There is a problem in this patch when parsing expressions. 
> 
> >+    if (ParenLevel == 0 && !MA.empty() && !isDarwin &&
> >+        Lexer.getLoc().getPointer() - MA.back().getEndLoc().getPointer() != 1)
> 
> The argument parsing thinks that "b + c" are three arguments.
> 
> Try the following test case:
> .macro test1 a
> .globl "\a"
> .endmacro
> 	
> test1 b + c

i believe this is some undefined/unintended behaviour in GNU as (at least i couldn't
find it described anywhere in its code or documentation). to see the problem, test
this one:

------------------
.macro test1 a b c
.byte \a
.byte \b
.byte \c
.endm

test1 b + c x y
test1 b - c
test1 b -c x
test1 b * c
test1 b / c x y
------------------

$ as -vahlm a.s
GNU assembler version 2.22 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.22
a.s: Assembler messages:
a.s:8: Warning: Unary operator - ignored because bad operand follows
a.s:8: Warning: zero assumed for missing expression
a.s:10: Error: bad expression
GAS LISTING a.s                         page 1


   1                    .macro test1 a b c
   2                    .byte \a
   3                    .byte \b
   4                    .byte \c
   5                    .endm
   6
   7                    test1 b + c x y
   7 ???? 00            > .byte b+c
   7 ???? 00            > .byte x
   7 ???? 00            > .byte y
   8                    test1 b - c
   8 ???? 00            > .byte b
   8 ???? 00            > .byte -
****  Warning:zero assumed for missing expression
   8 ???? 00            > .byte c
   9                    test1 b -c x
   9 ???? 00            > .byte b
   9 ???? 00            > .byte -c
   9 ???? 00            > .byte x
  10                    test1 b * c
  10 ???? 00            > .byte b
  10 ???? 00            > .byte *
****  Error:bad expression
  10 ???? 00            > .byte c
  11                    test1 b / c x y
  11 ???? 00            > .byte b/c
  11 ???? 00            > .byte x
  11 ???? 00            > .byte y

as you can see, GNU as doesn't treat the various arithmetic operators in a
consistent way, and given the purpose of whitespace separated macro arguments,
i consider the handling of +,-,/ above an error (well, undefined/unintended)
and went for the consistent behaviour in integrated-as instead (i.e., treat
all whitespace as argument separators).

> Any idea why exprs.s is only being tested for Darwin?

given the above issues, the way exprs.s is written, it's not in gas syntax
(you can try GNU as on it btw ;).

cheers,
  PaX Team




More information about the llvm-commits mailing list