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: [3.4 PATCH] PR 16693: TYPE_PRECISION of C++ enums


On Aug 24, 2004, at 10:39 PM, Roger Sayle wrote:
// http://gcc.gnu.org/ml/gcc/2004-08/msg01129.html
// { dg-do run }
// { dg-options "-O2" }

extern "C" void abort(void);

enum E { e = 0x0f };

void test(int n)
{
  enum E x, y;

  x = (E)0x10;
  y = (E)n;

  if (x != y)
    abort ();
}

int main()
{
  test(0x10);
  return 0;
}
Really this testcase is unspecified and such as really should
not be added to the testsuite ...

I think everyone would agree with me on that but then again this
is the same point at which where the problem comes into play.

Since we define the cast as the following (at least we did
before this patch and after the patch to implement DR377):
ands with the bit mask if the value is constant (even when
we can prove it is constant with optimizations, but only on
the mainline, not for 3.4.x)
otherwise it is the same value as the underling integer value

So if you compiled the above testcase with -O3 right now on the
mainline you will see that it passes.

I think this patch should not be applied to the mainline but
rather the middle-end (fold) should be fixed as it could cause
problems with other languages which define it types the same
way we (used to) define enums in C++.

-- Pinski


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