This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]: Don't apply default conversions to C switch expressions

On Mon, 10 Dec 2001, Roger Sayle wrote:

> From my reading of the draft C99 rationale document, section on
> page 84 states that "case labels are first converted to the type of the
> controlling expression of the switch, then checked for equality with
> other labels."  I believe that in the switch statement, "switch (x)",
> the type of the controlling expression is the type of x, possibly an
> "unsigned char" or a enumaral type.

Use the standard, not the Rationale. clearly states that "The
integer promotions are performed on the controlling expression.".

> GNU C compiler currently calls "default_conversion" in "c_start_case"
> which promotes these types to integers, which I believe is incorrect
> according to the above document.  This patch removes the call to
> "default_conversion" and thereby, I believe, fixes PR c/4475.  This
> is a regression from 2.95.

There is in fact a bug present: the subsequent call to get_unwidened.  I
previously sent a similar patch, which didn't remove the call to
default_conversion, in an attempt to fix c/2454, but didn't apply it since
it didn't fix that problem at all optimization levels - there seemed still
to be an optimization bug present causing the testcase I included to fail
at -O2, -Os, -O3.  No-one familiar with the optimizers answered my request
to look at that part of the problem.  Perhaps I should re-test and apply
the patch anyway, since it does still fix a bug, albeit partly.

Joseph S. Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]