diff mbox

[C/C++] Fix mode attribute handling (PR c++/79641)

Message ID 20170221164019.GS1849@tucnak
State New
Headers show

Commit Message

Jakub Jelinek Feb. 21, 2017, 4:40 p.m. UTC
Hi!

On the following testcase, we have TYPE_READONLY integer type
before handling the mode attribute and transform it into
a signed char type (without TYPE_READONLY), which causes ICE in the FE,
because it isn't const anymore.

Fixed by making sure we have the same quals as before applying the mode
attribute.  Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2017-02-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79641
	* c-attribs.c (handle_mode_attribute): Use build_qualified_type to
	preserve quals.

	* c-c++-common/pr79641.c: New test.


	Jakub

Comments

Jeff Law Feb. 21, 2017, 4:52 p.m. UTC | #1
On 02/21/2017 09:40 AM, Jakub Jelinek wrote:
> Hi!
>
> On the following testcase, we have TYPE_READONLY integer type
> before handling the mode attribute and transform it into
> a signed char type (without TYPE_READONLY), which causes ICE in the FE,
> because it isn't const anymore.
>
> Fixed by making sure we have the same quals as before applying the mode
> attribute.  Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2017-02-21  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR c++/79641
> 	* c-attribs.c (handle_mode_attribute): Use build_qualified_type to
> 	preserve quals.
>
> 	* c-c++-common/pr79641.c: New test.
OK.
jeff
diff mbox

Patch

--- gcc/c-family/c-attribs.c.jj	2017-01-01 12:45:46.000000000 +0100
+++ gcc/c-family/c-attribs.c	2017-02-21 12:38:10.105547005 +0100
@@ -1430,7 +1430,7 @@  handle_mode_attribute (tree *node, tree
 	  return NULL_TREE;
 	}
 
-      *node = typefm;
+      *node = build_qualified_type (typefm, TYPE_QUALS (type));
     }
 
   return NULL_TREE;
--- gcc/testsuite/c-c++-common/pr79641.c.jj	2017-02-21 12:43:24.246466684 +0100
+++ gcc/testsuite/c-c++-common/pr79641.c	2017-02-21 12:43:18.132546096 +0100
@@ -0,0 +1,4 @@ 
+/* PR c++/79641 */
+/* { dg-do compile } */
+
+const int __attribute__((__mode__ (__QI__))) i = 0;