This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[committed] Remove unnecessary null checks from genattrtab.c
- From: Richard Sandiford <richard dot sandiford at arm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 16 Jul 2015 14:16:56 +0100
- Subject: [committed] Remove unnecessary null checks from genattrtab.c
- Authentication-results: sourceware.org; auth=none
check_attr_value and make_canonical have some checks for null attr arguments,
but all callers would segfault if the argument really were null.
This is preparing for some improvements to the source location tracking
in gen*.
Series bBootstrapped & regression-tested on x86_64-linux-gnu. I built gcc
before and after the series for one target per CPU directory and checked
that the output was the same (except for some filename fixes later in
the series.) Applied.
Thanks,
Richard
gcc/
* genattrtab.c (check_attr_value): Remove handling of null attrs.
(make_canonical): Likewise.
Index: gcc/genattrtab.c
===================================================================
--- gcc/genattrtab.c 2015-07-05 22:19:53.407810340 +0100
+++ gcc/genattrtab.c 2015-07-06 21:42:39.666899334 +0100
@@ -899,7 +899,7 @@ check_attr_test (rtx exp, int is_const,
/* Given an expression, ensure that it is validly formed and that all named
attribute values are valid for the given attribute. Issue a fatal error
- if not. If no attribute is specified, assume a numeric attribute.
+ if not.
Return a perhaps modified replacement expression for the value. */
@@ -913,7 +913,7 @@ check_attr_value (rtx exp, struct attr_d
switch (GET_CODE (exp))
{
case CONST_INT:
- if (attr && ! attr->is_numeric)
+ if (!attr->is_numeric)
{
error_with_line (attr->lineno,
"CONST_INT not valid for non-numeric attribute %s",
@@ -934,15 +934,15 @@ check_attr_value (rtx exp, struct attr_d
if (! strcmp (XSTR (exp, 0), "*"))
break;
- if (attr == 0 || attr->is_numeric)
+ if (attr->is_numeric)
{
p = XSTR (exp, 0);
for (; *p; p++)
if (! ISDIGIT (*p))
{
- error_with_line (attr ? attr->lineno : 0,
+ error_with_line (attr->lineno,
"non-numeric value for numeric attribute %s",
- attr ? attr->name : "internal");
+ attr->name);
break;
}
break;
@@ -956,13 +956,12 @@ check_attr_value (rtx exp, struct attr_d
if (av == NULL)
error_with_line (attr->lineno,
"unknown value `%s' for `%s' attribute",
- XSTR (exp, 0), attr ? attr->name : "internal");
+ XSTR (exp, 0), attr->name);
break;
case IF_THEN_ELSE:
- XEXP (exp, 0) = check_attr_test (XEXP (exp, 0),
- attr ? attr->is_const : 0,
- attr ? attr->lineno : 0);
+ XEXP (exp, 0) = check_attr_test (XEXP (exp, 0), attr->is_const,
+ attr->lineno);
XEXP (exp, 1) = check_attr_value (XEXP (exp, 1), attr);
XEXP (exp, 2) = check_attr_value (XEXP (exp, 2), attr);
break;
@@ -972,7 +971,7 @@ check_attr_value (rtx exp, struct attr_d
case MULT:
case DIV:
case MOD:
- if (attr && !attr->is_numeric)
+ if (!attr->is_numeric)
{
error_with_line (attr->lineno,
"invalid operation `%s' for non-numeric"
@@ -1007,8 +1006,8 @@ check_attr_value (rtx exp, struct attr_d
for (i = 0; i < XVECLEN (exp, 0); i += 2)
{
XVECEXP (exp, 0, i) = check_attr_test (XVECEXP (exp, 0, i),
- attr ? attr->is_const : 0,
- attr ? attr->lineno : 0);
+ attr->is_const,
+ attr->lineno);
XVECEXP (exp, 0, i + 1)
= check_attr_value (XVECEXP (exp, 0, i + 1), attr);
}
@@ -1020,15 +1019,13 @@ check_attr_value (rtx exp, struct attr_d
{
struct attr_desc *attr2 = find_attr (&XSTR (exp, 0), 0);
if (attr2 == NULL)
- error_with_line (attr ? attr->lineno : 0,
- "unknown attribute `%s' in ATTR",
+ error_with_line (attr->lineno, "unknown attribute `%s' in ATTR",
XSTR (exp, 0));
- else if (attr && attr->is_const && ! attr2->is_const)
+ else if (attr->is_const && ! attr2->is_const)
error_with_line (attr->lineno,
"non-constant attribute `%s' referenced from `%s'",
XSTR (exp, 0), attr->name);
- else if (attr
- && attr->is_numeric != attr2->is_numeric)
+ else if (attr->is_numeric != attr2->is_numeric)
error_with_line (attr->lineno,
"numeric attribute mismatch calling `%s' from `%s'",
XSTR (exp, 0), attr->name);
@@ -1042,7 +1039,7 @@ check_attr_value (rtx exp, struct attr_d
return attr_rtx (SYMBOL_REF, XSTR (exp, 0));
default:
- error_with_line (attr ? attr->lineno : 0,
+ error_with_line (attr->lineno,
"invalid operation `%s' for attribute value",
GET_RTX_NAME (GET_CODE (exp)));
break;
@@ -1199,7 +1196,7 @@ make_canonical (struct attr_desc *attr,
case CONST_STRING:
if (! strcmp (XSTR (exp, 0), "*"))
{
- if (attr == 0 || attr->default_val == 0)
+ if (attr->default_val == 0)
fatal ("(attr_value \"*\") used in invalid context");
exp = attr->default_val->value;
}