]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Improve handling of REPT pseudo op with a negative count.
authorNick Clifton <nickc@redhat.com>
Fri, 20 Oct 2017 10:45:19 +0000 (11:45 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 20 Oct 2017 10:45:19 +0000 (11:45 +0100)
PR 22324
* read.c (s_rept): Use size_t type for count parameter.
(do_repeat): Change type of count parameter to size_t.
Issue an error is the count parameter is negative.
(do_repeat_with_expression): Likewise.
* read.h: Update prototypes for do_repeat and
do_repeat_with_expression.
* doc/as.texinfo (Rept): Document that a zero count is allowed but
negative counts are not.
* config/tc-rx.c (rx_rept): Use size_t type for count parameter.
* config/tc-tic54x.c (tic54x_loop): Cast count parameter to size_t
type.
* testsuite/gas/macros/end.s: Add a test using a negative repeat
count.
* testsuite/gas/macros/end.l: Add expected error message.

gas/ChangeLog
gas/config/tc-rx.c
gas/config/tc-tic54x.c
gas/doc/as.texinfo
gas/read.c
gas/read.h
gas/testsuite/gas/macros/end.l
gas/testsuite/gas/macros/end.s

index 5e55e940fef0269e8e7f17d77b6cc134f543307d..b0c7184c23df1a0cf4aaf56d93bab8b7b1bef3d5 100644 (file)
@@ -1,3 +1,21 @@
+2017-10-20  Nick Clifton  <nickc@redhat.com>
+
+       PR 22324
+       * read.c (s_rept): Use size_t type for count parameter.
+       (do_repeat): Change type of count parameter to size_t.
+       Issue an error is the count parameter is negative.
+       (do_repeat_with_expression): Likewise.
+       * read.h: Update prototypes for do_repeat and
+       do_repeat_with_expression.
+       * doc/as.texinfo (Rept): Document that a zero count is allowed but
+       negative counts are not.
+       * config/tc-rx.c (rx_rept): Use size_t type for count parameter.
+       * config/tc-tic54x.c (tic54x_loop): Cast count parameter to size_t
+       type.
+       * testsuite/gas/macros/end.s: Add a test using a negative repeat
+       count.
+       * testsuite/gas/macros/end.l: Add expected error message.
+
 2017-10-19  Palmer Dabbelt  <palmer@dabbelt.com>
 
        * config/tc-riscv.c (md_apply_fix): Mark
index ba826c7b298c4804f03e832d346f8358b0deb4ce..1cd3675ae09bc06737419387618e8e346b74ae3e 100644 (file)
@@ -560,7 +560,7 @@ rx_list (int ignore ATTRIBUTE_UNUSED)
 static void
 rx_rept (int ignore ATTRIBUTE_UNUSED)
 {
-  int count = get_absolute_expression ();
+  size_t count = get_absolute_expression ();
 
   do_repeat_with_expander (count, "MREPEAT", "ENDR", "..MACREP");
 }
index cbc4a19906ad5392e37cc98fde6fa58ac6d140b8..f7dc0f53cc01ad44747ec8860012b173be77d01c 100644 (file)
@@ -2031,7 +2031,7 @@ tic54x_loop (int count)
   if (!is_end_of_line[(int) *input_line_pointer])
     count = get_absolute_expression ();
 
-  do_repeat (count, "LOOP", "ENDLOOP");
+  do_repeat ((size_t) count, "LOOP", "ENDLOOP");
 }
 
 /* Normally, endloop gets eaten by the preceding loop.  */
index 8c125fd7d6ac9cdcfa4daa6720828ba2541c672a..9485d68652a3fffd0f1d2785b719fc0b731fd0be 100644 (file)
@@ -6392,6 +6392,9 @@ is equivalent to assembling
         .long   0
 @end example
 
+A count of zero is allowed, but nothing is generated.  Negative counts are not
+allowed and if encountered will be treated as if they were zero.
+
 @node Sbttl
 @section @code{.sbttl "@var{subheading}"}
 
index 1643c5cdcf15d7a7c0c03af32c89e29567ecbf82..9f2909f797976955a89dd9dd8f36742e83daff26 100644 (file)
@@ -3106,9 +3106,9 @@ s_bad_end (int endr)
 void
 s_rept (int ignore ATTRIBUTE_UNUSED)
 {
-  int count;
+  size_t count;
 
-  count = get_absolute_expression ();
+  count = (size_t) get_absolute_expression ();
 
   do_repeat (count, "REPT", "ENDR");
 }
@@ -3117,11 +3117,17 @@ s_rept (int ignore ATTRIBUTE_UNUSED)
    different directives to be used as the start/end keys.  */
 
 void
-do_repeat (int count, const char *start, const char *end)
+do_repeat (size_t count, const char *start, const char *end)
 {
   sb one;
   sb many;
 
+  if (((ssize_t) count) < 0)
+    {
+      as_bad (_("negative count for %s - ignored"), start);
+      count = 0;
+    }
+
   sb_new (&one);
   if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
     {
@@ -3144,7 +3150,7 @@ do_repeat (int count, const char *start, const char *end)
    block is replaced by the iteration count.  */
 
 void
-do_repeat_with_expander (int count,
+do_repeat_with_expander (size_t count,
                         const char * start,
                         const char * end,
                         const char * expander)
@@ -3152,6 +3158,12 @@ do_repeat_with_expander (int count,
   sb one;
   sb many;
 
+  if (((ssize_t) count) < 0)
+    {
+      as_bad (_("negative count for %s - ignored"), start);
+      count = 0;
+    }
+
   sb_new (&one);
   if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
     {
@@ -3172,7 +3184,7 @@ do_repeat_with_expander (int count,
          sb_build (& processed, one.len);
          sb_add_sb (& processed, & one);
          sub = strstr (processed.ptr, expander);
-         len = sprintf (sub, "%d", count);
+         len = sprintf (sub, "%lu", (unsigned long) count);
          gas_assert (len < 8);
          strcpy (sub + len, sub + 8);
          processed.len -= (8 - len);
index e83118fd69cb59102ca172523db98abe92f5cc85..f16455d428863de58990882a6820e9c40084be0e 100644 (file)
@@ -146,8 +146,8 @@ extern void stabs_generate_asm_file (void);
 extern void stabs_generate_asm_lineno (void);
 extern void stabs_generate_asm_func (const char *, const char *);
 extern void stabs_generate_asm_endfunc (const char *, const char *);
-extern void do_repeat (int,const char *,const char *);
-extern void do_repeat_with_expander (int, const char *, const char *, const char *);
+extern void do_repeat (size_t, const char *, const char *);
+extern void do_repeat_with_expander (size_t, const char *, const char *, const char *);
 extern void end_repeat (int);
 extern void do_parse_cons_expression (expressionS *, int);
 
index 1675ff818367f7a7c5c9582bf47cfecb063a9276..ff5d45213db519f5c1564000e4d1b438df586fd7 100644 (file)
@@ -1,3 +1,4 @@
 .*: Assembler messages:
 .*:1: Warning: \.endm .* \.macro
 .*:2: Warning: \.endr .* (\.rept|\.irpc?).*(\.rept|\.irpc?).*(\.rept|\.irpc?)
+.*:3: Error: negative count for REPT - ignored
index 3a136c604ab40e08a67bbae2508b7883d805175e..300b0551e94e4904299cc12205b87e040accb210 100644 (file)
@@ -1,2 +1,5 @@
        .endm
        .endr
+       .rept -1
+       .endr
+