public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: <binutils@sourceware.org>
Subject: [PATCH] gas: require an operand to .startof.()/.sizeof.()
Date: Tue, 21 Feb 2017 10:15:00 -0000	[thread overview]
Message-ID: <58AC213E020000780013C307@prv-mh.provo.novell.com> (raw)

gas/
2017-02-21  Jan Beulich  <jbeulich@suse.com>

	* expr.c (operand): Handle missing operand to .startof.() and
	.sizeof.().
	* testsuite/gas/all/err-sizeof.s: New.

--- 2017-02-21/gas/expr.c
+++ 2017-02-21/gas/expr.c
@@ -1154,6 +1154,10 @@ operand (expressionS *expressionP, enum
 		   || 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
 	      ++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
 	      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);
--- 2017-02-21/gas/testsuite/gas/all/err-sizeof.s
+++ 2017-02-21/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 }



             reply	other threads:[~2017-02-21 10:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 10:15 Jan Beulich [this message]
2017-02-22  6:48 ` Alan Modra
2017-02-22 13:23 ` Hans-Peter Nilsson
2017-02-22 16:31 Nick Clifton
2017-02-22 17:12 ` Jan Beulich
2017-02-23 10:20 ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58AC213E020000780013C307@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).