Skip to content

Commit

Permalink
PR c++/81607
Browse files Browse the repository at this point in the history
	* cp-gimplify.c (cp_fold): If folding exposed a branch of
	a COND_EXPR, convert it to the original type of the COND_EXPR, if
	they differ.		   

	* g++.dg/other/bitfield6.C: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@250948 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
mpolacek committed Aug 8, 2017
1 parent 30a8669 commit ec72e2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions gcc/cp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2017-08-08 Marek Polacek <[email protected]>

PR c++/81607
* cp-gimplify.c (cp_fold): If folding exposed a branch of
a COND_EXPR, convert it to the original type of the COND_EXPR, if
they differ.

2017-08-08 Martin Liska <[email protected]>

* call.c: Include header files.
Expand Down
6 changes: 3 additions & 3 deletions gcc/cp/cp-gimplify.c
Original file line number Diff line number Diff line change
Expand Up @@ -2316,9 +2316,9 @@ cp_fold (tree x)

/* A COND_EXPR might have incompatible types in branches if one or both
arms are bitfields. If folding exposed such a branch, fix it up. */
if (TREE_CODE (x) != code)
if (tree type = is_bitfield_expr_with_lowered_type (x))
x = fold_convert (type, x);
if (TREE_CODE (x) != code
&& !useless_type_conversion_p (TREE_TYPE (org_x), TREE_TYPE (x)))
x = fold_convert (TREE_TYPE (org_x), x);

break;

Expand Down
5 changes: 5 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-08-08 Marek Polacek <[email protected]>

PR c++/81607
* g++.dg/other/bitfield6.C: New test.

2017-08-07 Michael Meissner <[email protected]>

PR target/81593
Expand Down
9 changes: 9 additions & 0 deletions gcc/testsuite/g++.dg/other/bitfield6.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// PR c++/81607

int a;

struct b {
long c : 32;
} d;

char f = (903092 ? int(d.c) : 0) << a;

0 comments on commit ec72e2f

Please sign in to comment.