mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-06 07:28:44 +08:00
Improve handling of REPT pseudo op with a negative count.
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.
This commit is contained in:
@ -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>
|
2017-10-19 Palmer Dabbelt <palmer@dabbelt.com>
|
||||||
|
|
||||||
* config/tc-riscv.c (md_apply_fix): Mark
|
* config/tc-riscv.c (md_apply_fix): Mark
|
||||||
|
@ -560,7 +560,7 @@ rx_list (int ignore ATTRIBUTE_UNUSED)
|
|||||||
static void
|
static void
|
||||||
rx_rept (int ignore ATTRIBUTE_UNUSED)
|
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");
|
do_repeat_with_expander (count, "MREPEAT", "ENDR", "..MACREP");
|
||||||
}
|
}
|
||||||
|
@ -2031,7 +2031,7 @@ tic54x_loop (int count)
|
|||||||
if (!is_end_of_line[(int) *input_line_pointer])
|
if (!is_end_of_line[(int) *input_line_pointer])
|
||||||
count = get_absolute_expression ();
|
count = get_absolute_expression ();
|
||||||
|
|
||||||
do_repeat (count, "LOOP", "ENDLOOP");
|
do_repeat ((size_t) count, "LOOP", "ENDLOOP");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normally, endloop gets eaten by the preceding loop. */
|
/* Normally, endloop gets eaten by the preceding loop. */
|
||||||
|
@ -6392,6 +6392,9 @@ is equivalent to assembling
|
|||||||
.long 0
|
.long 0
|
||||||
@end example
|
@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
|
@node Sbttl
|
||||||
@section @code{.sbttl "@var{subheading}"}
|
@section @code{.sbttl "@var{subheading}"}
|
||||||
|
|
||||||
|
22
gas/read.c
22
gas/read.c
@ -3106,9 +3106,9 @@ s_bad_end (int endr)
|
|||||||
void
|
void
|
||||||
s_rept (int ignore ATTRIBUTE_UNUSED)
|
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");
|
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. */
|
different directives to be used as the start/end keys. */
|
||||||
|
|
||||||
void
|
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 one;
|
||||||
sb many;
|
sb many;
|
||||||
|
|
||||||
|
if (((ssize_t) count) < 0)
|
||||||
|
{
|
||||||
|
as_bad (_("negative count for %s - ignored"), start);
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
sb_new (&one);
|
sb_new (&one);
|
||||||
if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
|
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. */
|
block is replaced by the iteration count. */
|
||||||
|
|
||||||
void
|
void
|
||||||
do_repeat_with_expander (int count,
|
do_repeat_with_expander (size_t count,
|
||||||
const char * start,
|
const char * start,
|
||||||
const char * end,
|
const char * end,
|
||||||
const char * expander)
|
const char * expander)
|
||||||
@ -3152,6 +3158,12 @@ do_repeat_with_expander (int count,
|
|||||||
sb one;
|
sb one;
|
||||||
sb many;
|
sb many;
|
||||||
|
|
||||||
|
if (((ssize_t) count) < 0)
|
||||||
|
{
|
||||||
|
as_bad (_("negative count for %s - ignored"), start);
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
sb_new (&one);
|
sb_new (&one);
|
||||||
if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
|
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_build (& processed, one.len);
|
||||||
sb_add_sb (& processed, & one);
|
sb_add_sb (& processed, & one);
|
||||||
sub = strstr (processed.ptr, expander);
|
sub = strstr (processed.ptr, expander);
|
||||||
len = sprintf (sub, "%d", count);
|
len = sprintf (sub, "%lu", (unsigned long) count);
|
||||||
gas_assert (len < 8);
|
gas_assert (len < 8);
|
||||||
strcpy (sub + len, sub + 8);
|
strcpy (sub + len, sub + 8);
|
||||||
processed.len -= (8 - len);
|
processed.len -= (8 - len);
|
||||||
|
@ -146,8 +146,8 @@ extern void stabs_generate_asm_file (void);
|
|||||||
extern void stabs_generate_asm_lineno (void);
|
extern void stabs_generate_asm_lineno (void);
|
||||||
extern void stabs_generate_asm_func (const char *, const char *);
|
extern void stabs_generate_asm_func (const char *, const char *);
|
||||||
extern void stabs_generate_asm_endfunc (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 (size_t, const char *, const char *);
|
||||||
extern void do_repeat_with_expander (int, const char *, 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 end_repeat (int);
|
||||||
extern void do_parse_cons_expression (expressionS *, int);
|
extern void do_parse_cons_expression (expressionS *, int);
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
.*: Assembler messages:
|
.*: Assembler messages:
|
||||||
.*:1: Warning: \.endm .* \.macro
|
.*:1: Warning: \.endm .* \.macro
|
||||||
.*:2: Warning: \.endr .* (\.rept|\.irpc?).*(\.rept|\.irpc?).*(\.rept|\.irpc?)
|
.*:2: Warning: \.endr .* (\.rept|\.irpc?).*(\.rept|\.irpc?).*(\.rept|\.irpc?)
|
||||||
|
.*:3: Error: negative count for REPT - ignored
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
.endm
|
.endm
|
||||||
.endr
|
.endr
|
||||||
|
.rept -1
|
||||||
|
.endr
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user