Commit d0c5c9b1 by Roger Sayle Committed by Roger Sayle

re PR middle-end/16693 (Bitwise AND is lost when used within a cast to an enum…

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
parent 700686fa
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> 2004-08-25 Mark Mitchell <mark@codesourcery.com>
PR c++/17155 PR c++/17155
......
...@@ -9373,7 +9373,14 @@ finish_enum (tree enumtype) ...@@ -9373,7 +9373,14 @@ finish_enum (tree enumtype)
underlying type in the range bmin to bmax, where bmin and bmax are, underlying type in the range bmin to bmax, where bmin and bmax are,
respectively, the smallest and largest values of the smallest bit- respectively, the smallest and largest values of the smallest bit-
field that can store emin and emax. */ 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); set_min_and_max_values_for_integral_type (enumtype, precision, unsignedp);
/* [dcl.enum] /* [dcl.enum]
......
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> 2004-08-25 Ziemowit Laski <zlaski@apple.com>
* objc.dg/proto-lossage-4.m: New test. * objc.dg/proto-lossage-4.m: New test.
......
// 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;
}
// 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;
}
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment