re PR middle-end/16693 (Bitwise AND is lost when used within a cast to an enum of the same precision)

PR middle-end/16693
	PR tree-optimization/16372
	* decl.c (finish_enum): Make the precision of the enumerated type
	the same width as the underlying integer type.

	* g++.dg/opt/pr16372-1.C: New test case.
	* g++.dg/opt/pr16693-1.C: New test case.
	* g++.dg/opt/pr16693-2.C: New test case.

From-SVN: r86576
This commit is contained in:
Roger Sayle 2004-08-25 20:51:02 +00:00 committed by Roger Sayle
parent 700686faf4
commit d0c5c9b14d
6 changed files with 86 additions and 1 deletions

View file

@ -1,3 +1,10 @@
2004-08-25 Roger Sayle <roger@eyesopen.com>
PR middle-end/16693
PR tree-optimization/16372
* decl.c (finish_enum): Make the precision of the enumerated type
the same width as the underlying integer type.
2004-08-25 Mark Mitchell <mark@codesourcery.com>
PR c++/17155

View file

@ -9373,7 +9373,14 @@ finish_enum (tree enumtype)
underlying type in the range bmin to bmax, where bmin and bmax are,
respectively, the smallest and largest values of the smallest bit-
field that can store emin and emax. */
TYPE_PRECISION (enumtype) = precision;
/* The middle-end currently assumes that types with TYPE_PRECISION
narrower than their underlying type are suitably zero or sign
extended to fill their mode. g++ doesn't make these guarantees.
Until the middle-end can represent such paradoxical types, we
set the TYPE_PRECISON to the width of the underlying type. */
TYPE_PRECISION (enumtype) = TYPE_PRECISION (underlying_type);
set_min_and_max_values_for_integral_type (enumtype, precision, unsignedp);
/* [dcl.enum]

View file

@ -1,3 +1,11 @@
2004-08-25 Roger Sayle <roger@eyesopen.com>
PR middle-end/16693
PR tree-optimization/16372
* g++.dg/opt/pr16372-1.C: New test case.
* g++.dg/opt/pr16693-1.C: New test case.
* g++.dg/opt/pr16693-2.C: New test case.
2004-08-25 Ziemowit Laski <zlaski@apple.com>
* objc.dg/proto-lossage-4.m: New test.

View file

@ -0,0 +1,17 @@
// PR tree-optimization/16372
// { dg-do run }
// { dg-options "-O1" }
extern "C" void abort();
enum number {ZERO, ONE, TWO, THREE, FOUR, FIVE};
int main() {
number n = FIVE;
if((n == ONE) || (n == TWO) || (n == THREE)) {
abort ();
}
return 0;
}

View file

@ -0,0 +1,25 @@
// PR middle-end/16693
// { dg-do run }
// { dg-options "-O2" }
extern "C" void abort();
unsigned short ret6666(int) {
return 0x66;
}
typedef enum {
a = 0x0, b = 0x1, c = 0x2, d = 0x3, e = 0x4, f = 0x5,
g = 0x6, h = 0x7, i = 0x8, j = 0x9, k = 0xa, l = 0xb,
m = 0xc, n = 0xd, o = 0xe, p = 0xf
} Test_Enum;
int main(void) {
unsigned char r1;
r1 = static_cast<Test_Enum>(0xf & ret6666(44));
if(r1 != 0x6)
abort();
return 0;
}

View file

@ -0,0 +1,21 @@
// PR middle-end/16693
// { dg-do run }
// { dg-options "-O2" }
extern "C" void abort();
char foo()
{
return 0x10;
}
enum E { e = 0x0f };
int main()
{
char c = (char)(E)(e & foo());
if (c != 0)
abort();
return 0;
}