forked from Imagelibrary/binutils-gdb
[gdb/symtab] Remove dead code in parse_macro_definition
In parse_macro_definition, there's a loop:
...
for (p = body; *p; p++)
if (*p == ' ' || *p == '(')
break;
...
whose post-condition is:
...
gdb_assert (*p == ' ' || *p == '(' || *p == '\0');
...
Consequently, in the following:
...
if (*p == ' ' || *p == '\0')
<BODY1>
else if (*p == '(')
<BODY2>
else
<BODY3>
...
BODY3 is dead code.
Remove it, and get rid of unnecessary indentation by using an early-exit:
....
if (*p == ' ' || *p == '\0')
{
<BODY1>
return;
}
gdb_assert (*p == '(');
<BODY2>
...
Tested on aarch64-linux.
Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
@@ -154,88 +154,83 @@ parse_macro_definition (struct macro_source_file *file, int line,
|
||||
}
|
||||
|
||||
macro_define_object (file, line, name.c_str (), replacement);
|
||||
return;
|
||||
}
|
||||
else if (*p == '(')
|
||||
{
|
||||
/* It's a function-like macro. */
|
||||
std::string name (body, p - body);
|
||||
int argc = 0;
|
||||
int argv_size = 1;
|
||||
char **argv = XNEWVEC (char *, argv_size);
|
||||
|
||||
p++;
|
||||
/* It's a function-like macro. */
|
||||
gdb_assert (*p == '(');
|
||||
std::string name (body, p - body);
|
||||
int argc = 0;
|
||||
int argv_size = 1;
|
||||
char **argv = XNEWVEC (char *, argv_size);
|
||||
|
||||
p++;
|
||||
|
||||
p = consume_improper_spaces (p, body);
|
||||
|
||||
/* Parse the formal argument list. */
|
||||
while (*p && *p != ')')
|
||||
{
|
||||
/* Find the extent of the current argument name. */
|
||||
const char *arg_start = p;
|
||||
|
||||
while (*p && *p != ',' && *p != ')' && *p != ' ')
|
||||
p++;
|
||||
|
||||
if (! *p || p == arg_start)
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
else
|
||||
{
|
||||
/* Make sure argv has room for the new argument. */
|
||||
if (argc >= argv_size)
|
||||
{
|
||||
argv_size *= 2;
|
||||
argv = XRESIZEVEC (char *, argv, argv_size);
|
||||
}
|
||||
|
||||
argv[argc++] = savestring (arg_start, p - arg_start);
|
||||
}
|
||||
|
||||
p = consume_improper_spaces (p, body);
|
||||
|
||||
/* Parse the formal argument list. */
|
||||
while (*p && *p != ')')
|
||||
{
|
||||
/* Find the extent of the current argument name. */
|
||||
const char *arg_start = p;
|
||||
|
||||
while (*p && *p != ',' && *p != ')' && *p != ' ')
|
||||
p++;
|
||||
|
||||
if (! *p || p == arg_start)
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
else
|
||||
{
|
||||
/* Make sure argv has room for the new argument. */
|
||||
if (argc >= argv_size)
|
||||
{
|
||||
argv_size *= 2;
|
||||
argv = XRESIZEVEC (char *, argv, argv_size);
|
||||
}
|
||||
|
||||
argv[argc++] = savestring (arg_start, p - arg_start);
|
||||
}
|
||||
|
||||
p = consume_improper_spaces (p, body);
|
||||
|
||||
/* Consume the comma, if present. */
|
||||
if (*p == ',')
|
||||
{
|
||||
p++;
|
||||
|
||||
p = consume_improper_spaces (p, body);
|
||||
}
|
||||
}
|
||||
|
||||
if (*p == ')')
|
||||
/* Consume the comma, if present. */
|
||||
if (*p == ',')
|
||||
{
|
||||
p++;
|
||||
|
||||
if (*p == ' ')
|
||||
/* Perfectly formed definition, no complaints. */
|
||||
macro_define_function (file, line, name.c_str (),
|
||||
argc, (const char **) argv,
|
||||
p + 1);
|
||||
else if (*p == '\0')
|
||||
{
|
||||
/* Complain, but do define it. */
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
macro_define_function (file, line, name.c_str (),
|
||||
argc, (const char **) argv,
|
||||
p);
|
||||
}
|
||||
else
|
||||
/* Just complain. */
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
p = consume_improper_spaces (p, body);
|
||||
}
|
||||
}
|
||||
|
||||
if (*p == ')')
|
||||
{
|
||||
p++;
|
||||
|
||||
if (*p == ' ')
|
||||
/* Perfectly formed definition, no complaints. */
|
||||
macro_define_function (file, line, name.c_str (),
|
||||
argc, (const char **) argv,
|
||||
p + 1);
|
||||
else if (*p == '\0')
|
||||
{
|
||||
/* Complain, but do define it. */
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
macro_define_function (file, line, name.c_str (),
|
||||
argc, (const char **) argv,
|
||||
p);
|
||||
}
|
||||
else
|
||||
/* Just complain. */
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
xfree (argv[i]);
|
||||
}
|
||||
xfree (argv);
|
||||
}
|
||||
else
|
||||
/* Just complain. */
|
||||
dwarf2_macro_malformed_definition_complaint (body);
|
||||
|
||||
for (int i = 0; i < argc; i++)
|
||||
xfree (argv[i]);
|
||||
|
||||
xfree (argv);
|
||||
}
|
||||
|
||||
/* Skip some bytes from BYTES according to the form given in FORM.
|
||||
|
||||
Reference in New Issue
Block a user