Patchwork Fix PR55570

login
register
mail settings
Submitter Marek Polacek
Date Dec. 3, 2012, 12:36 p.m.
Message ID <20121203123628.GK10621@redhat.com>
Download mbox | patch
Permalink /patch/203340/
State New
Headers show

Comments

Marek Polacek - Dec. 3, 2012, 12:36 p.m.
We segfaulted on attached testcase, because we were accessing
->typed.type field via TREE_TYPE, but IDENTIFIER_NODEs don't contain
->typed element at all.  Fixed by switching the expressions in 
a condition, so we always first check that we're operating on
INTEGER_CST.
Regtested/bootstrapped on x86_64-linux, ok for trunk and 4.7 branch?

2012-12-03  Marek Polacek  <polacek@redhat.com>

	PR c/55570
	* c-common.c (check_user_alignment):

	* gcc.dg/pr55570.c: New test.


	Marek
Jakub Jelinek - Dec. 3, 2012, 12:50 p.m.
On Mon, Dec 03, 2012 at 01:36:28PM +0100, Marek Polacek wrote:
> We segfaulted on attached testcase, because we were accessing
> ->typed.type field via TREE_TYPE, but IDENTIFIER_NODEs don't contain
> ->typed element at all.  Fixed by switching the expressions in 
> a condition, so we always first check that we're operating on
> INTEGER_CST.
> Regtested/bootstrapped on x86_64-linux, ok for trunk and 4.7 branch?
> 
> 2012-12-03  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/55570
> 	* c-common.c (check_user_alignment):

Missing descrption of the change above, I'd say
Swap order of tests, check TREE_CODE first.
or similar.

Ok with that change.

	Jakub

Patch

--- gcc/c-family/c-common.c.mp	2012-12-03 13:07:58.233832299 +0100
+++ gcc/c-family/c-common.c	2012-12-03 13:08:55.395259841 +0100
@@ -7261,8 +7261,8 @@  check_user_alignment (const_tree align,
 {
   int i;
 
-  if (!INTEGRAL_TYPE_P (TREE_TYPE (align))
-      || TREE_CODE (align) != INTEGER_CST)
+  if (TREE_CODE (align) != INTEGER_CST
+      || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
     {
       error ("requested alignment is not an integer constant");
       return -1;
--- gcc/testsuite/gcc.dg/pr55570.c.mp	2012-12-03 13:06:02.298558986 +0100
+++ gcc/testsuite/gcc.dg/pr55570.c	2012-12-03 13:05:39.200504521 +0100
@@ -0,0 +1,4 @@ 
+/* PR c/55570 */
+/* { dg-do compile } */
+
+char array[16] __attribute__((aligned (SOME_NOT_DEFINED_MACRO))); /* { dg-error "requested alignment is not an integer constant" } */