From b0c53498a383cd5915786b0c321da48054e122ef Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Wed, 22 Feb 2017 10:37:52 +0100 Subject: [PATCH] gas: require an operand to .startof.()/.sizeof.() --- gas/ChangeLog | 6 ++++++ gas/expr.c | 22 ++++++++++++++++++++++ gas/testsuite/gas/all/err-sizeof.s | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 gas/testsuite/gas/all/err-sizeof.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 9f7ce60e85f..652bd047db9 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,9 @@ +2017-02-21 Jan Beulich + + * expr.c (operand): Handle missing operand to .startof.() and + .sizeof.(). + * testsuite/gas/all/err-sizeof.s: New. + 2017-02-20 Alan Modra PR 21118 diff --git a/gas/expr.c b/gas/expr.c index c6685add270..6fc707b8a59 100644 --- a/gas/expr.c +++ b/gas/expr.c @@ -1154,6 +1154,10 @@ operand (expressionS *expressionP, enum expr_mode mode) || input_line_pointer[1] == 'T'); input_line_pointer += start ? 8 : 7; SKIP_WHITESPACE (); + + /* Cover for the as_bad () invocations below. */ + expressionP->X_op = O_absent; + if (*input_line_pointer != '(') as_bad (_("syntax error in .startof. or .sizeof.")); else @@ -1163,6 +1167,16 @@ operand (expressionS *expressionP, enum expr_mode mode) ++input_line_pointer; SKIP_WHITESPACE (); c = get_symbol_name (& name); + if (! *name) + { + as_bad (_("expected symbol name")); + (void) restore_line_pointer (c); + if (c != ')') + ignore_rest_of_line (); + else + ++input_line_pointer; + break; + } buf = concat (start ? ".startof." : ".sizeof.", name, (char *) NULL); @@ -1306,6 +1320,14 @@ operand (expressionS *expressionP, enum expr_mode mode) SKIP_WHITESPACE_AFTER_NAME (); c = get_symbol_name (& name); + if (! *name) + { + as_bad (_("expected symbol name")); + expressionP->X_op = O_absent; + (void) restore_line_pointer (c); + ignore_rest_of_line (); + break; + } buf = concat (start ? ".startof." : ".sizeof.", name, (char *) NULL); diff --git a/gas/testsuite/gas/all/err-sizeof.s b/gas/testsuite/gas/all/err-sizeof.s new file mode 100644 index 00000000000..4ddb5bdd5d8 --- /dev/null +++ b/gas/testsuite/gas/all/err-sizeof.s @@ -0,0 +1,21 @@ +;# .sizeof. and .startof. operator diagnostics +;# { dg-do assemble } + .long .sizeof.(a b) ;# { dg-error "Error: syntax error" } + .long .startof.(x y) ;# { dg-error "Error: syntax error" } + .long .sizeof.(a+b) ;# { dg-error "Error: syntax error" } + .long .startof.(x-y) ;# { dg-error "Error: syntax error" } + .long .sizeof.("a+b") + .long .startof.("x-y") + .long .sizeof.() ;# { dg-error "Error: expected symbol name" } + .long .startof.() ;# { dg-error "Error: expected symbol name" } +;# We don't really care about these, but I didn't find a way to discard +;# them, and I also don't want to use dg-excess-errors here. +;# { dg-error "junk at end" "" { target *-*-* } 3 } +;# { dg-error "junk at end" "junk" { target *-*-* } 4 } +;# { dg-error "junk at end" "junk" { target *-*-* } 5 } +;# { dg-error "UND" "undefined" { target *-*-* } 5 } +;# { dg-error "junk at end" "junk" { target *-*-* } 6 } +;# { dg-error "UND" "undefined" { target *-*-* } 6 } +;# { dg-error "too complex" "too complex" { target powerpc*-*-* } 6 } +;# { dg-warning "zero assumed" "missing" { target *-*-* } 9 } +;# { dg-warning "zero assumed" "missing" { target *-*-* } 10 } -- 2.30.2