ref: ebd1bfd80b0716ec72b256c6b65c01e9f8d8e2f1
parent: 45da2d1eff24fc3c0393d5ffbea087d1507b598c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jan 8 05:40:55 EST 2016
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.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -44,6 +44,7 @@
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 */
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -410,6 +410,10 @@
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));
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -465,9 +465,10 @@
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;