On Thu, Dec 03, 2015 at 06:11:42PM +0000, Joseph Myers wrote: > On Thu, 3 Dec 2015, Marek Polacek wrote: > > > This ought to fix the fallout from PR c/68162 fix. Here the problem is that > > grokdeclarator created a wrong type for PARM_DECL "p". It created this decl > > with type "const int[<unknown>] *" while it should be "const int *". > > > > I think the problem is that we weren't using TREE_TYPE on orig_qual_type and > > thus c_build_qualified_type and subsequent c_build_pointer_type might create > > a bogus type. So when we're transfering const-ness of an array into that of > > type pointed to, use TREE_TYPE not only of "type", but even of the orig qual > > type. > > I think you also need to decrement orig_qual_indirect, which counts the > number of levels of array type derivation from orig_qual_type.
Thus: Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-12-03 Marek Polacek <pola...@redhat.com> PR c/68668 * c-decl.c (grokdeclarator): When creating a PARM_DECL of ARRAY_TYPE, use TREE_TYPE of orig_qual_type. Decrement ORIG_QUAL_INDIRECT. * gcc.dg/pr68668.c: New test. diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 9ad8219..25bd1e0 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -6417,6 +6417,11 @@ grokdeclarator (const struct c_declarator *declarator, { /* Transfer const-ness of array into that of type pointed to. */ type = TREE_TYPE (type); + if (orig_qual_type != NULL_TREE) + { + orig_qual_type = TREE_TYPE (orig_qual_type); + orig_qual_indirect--; + } if (type_quals) type = c_build_qualified_type (type, type_quals, orig_qual_type, orig_qual_indirect); diff --git gcc/testsuite/gcc.dg/pr68668.c gcc/testsuite/gcc.dg/pr68668.c index e69de29..d144fb6 100644 --- gcc/testsuite/gcc.dg/pr68668.c +++ gcc/testsuite/gcc.dg/pr68668.c @@ -0,0 +1,10 @@ +/* PR c/68668 */ +/* { dg-do compile } */ + +typedef const int T[]; + +int +fn1 (T p) +{ + return p[0]; +} Marek