re PR middle-end/37882 (Bitfield miscompilation)

PR middle-end/37882
	* fold-const.c (build_range_type): For 1 .. signed_max
	range call build_nonstandard_inter_type if signed_type_for
	returned a type with bigger precision.

	* gcc.c-torture/execute/pr37882.c: New test.

From-SVN: r141303
This commit is contained in:
Jakub Jelinek 2008-10-22 20:21:55 +02:00 committed by Jakub Jelinek
parent 58ddc179d4
commit 972afb5819
4 changed files with 34 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2008-10-22 Jakub Jelinek <jakub@redhat.com>
PR middle-end/37882
* fold-const.c (build_range_type): For 1 .. signed_max
range call build_nonstandard_inter_type if signed_type_for
returned a type with bigger precision.
2008-10-22 Richard Guenther <rguenther@suse.de>
* tree.def (COMPLEX_TYPE): Constrain element type.

View File

@ -4503,7 +4503,12 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high)
{
if (TYPE_UNSIGNED (etype))
{
etype = signed_type_for (etype);
tree signed_etype = signed_type_for (etype);
if (TYPE_PRECISION (signed_etype) != TYPE_PRECISION (etype))
etype
= build_nonstandard_integer_type (TYPE_PRECISION (etype), 0);
else
etype = signed_etype;
exp = fold_convert (etype, exp);
}
return fold_build2 (GT_EXPR, type, exp,

View File

@ -1,3 +1,8 @@
2008-10-22 Jakub Jelinek <jakub@redhat.com>
PR middle-end/37882
* gcc.c-torture/execute/pr37882.c: New test.
2008-10-22 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/30949

View File

@ -0,0 +1,16 @@
/* PR middle-end/37882 */
struct S
{
int a : 21;
unsigned char b : 3;
} s;
int
main ()
{
s.b = 4;
if (s.b > 0 && s.b < 4)
__builtin_abort ();
return 0;
}