[hackers] [scc] Give a meanful error message when non scalar are used || Roberto E. Vargas Caballero
commit ebd1bfd80b0716ec72b256c6b65c01e9f8d8e2f1
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Jan 8 10:40:55 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Jan 8 10:49:29 2016 +0100
Give a meanful error message when non scalar are used
There are contexts, mainly conditions, where only scalar are required,
and the code was giving a very confusing message error related to
comparision, instead of giving this new error (taken from gcc) which
shows to the use what is the problem.
diff --git a/cc1/cc1.h b/cc1/cc1.h
index a3c32ec..391b995 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -44,6 +44,7 @@ struct type {
bool printed : 1; /* the type already was printed */
bool integer : 1; /* this type is INT or enum */
bool arith : 1; /* this type is INT, ENUM, FLOAT */
+ bool aggreg : 1; /* this type is struct or union */
size_t size; /* sizeof the type */
size_t align; /* align of the type */
Type *type; /* base type */
diff --git a/cc1/expr.c b/cc1/expr.c
index 39e9096..f211e39 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -410,6 +410,10 @@ static Node *
exp2cond(Node *np, char neg)
{
np = decay(np);
+ if (np->type->aggreg) {
+ errorp("used struct/union type value where scalar is required");
+ np = constnode(zero);
+ }
if (isnodecmp(np->op))
return (neg) ? negate(np) : np;
return compare((neg) ? OEQ : ONE, np, constnode(zero));
diff --git a/cc1/types.c b/cc1/types.c
index 491a5fd..5fda300 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -465,9 +465,10 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
type.printed = 1;
type.integer = 1;
type.arith = 1;
- /* PASSTROUGH */
+ goto no_defined;
case STRUCT:
case UNION:
+ type.aggreg = 1;
no_defined:
type.defined = 0;
break;
Received on Fri Jan 08 2016 - 13:13:59 CET
This archive was generated by hypermail 2.3.0
: Fri Jan 08 2016 - 13:24:57 CET