This is the mail archive of the gcc-patches@gcc.gnu.org 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 6.8.4.2 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.  6.8.4.2#5 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.

http://gcc.gnu.org/ml/gcc-patches/2001-06/msg00294.html

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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