diff mbox

C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)

Message ID 20151207170117.GN3175@redhat.com
State New
Headers show

Commit Message

Marek Polacek Dec. 7, 2015, 5:01 p.m. UTC
On Mon, Dec 07, 2015 at 04:05:11PM +0000, Joseph Myers wrote:
> On Mon, 7 Dec 2015, Marek Polacek wrote:
> 
> > +		if (orig_qual_indirect != 0)
> > +		  orig_qual_type = TREE_TYPE (orig_qual_type);
> > +		else
> > +		  orig_qual_indirect--;
> 
> For optimal results for debug info, I think that should be == 0 (i.e. 
> preserve orig_qual_type, which may be a typedef, if possible - if the 
> parameter is an array of orig_qual_type), rather than != 0.

I'm confused now.  If orig_qual_indirect != 0, it is indirect, right?
Earlier you said:
"if orig_qual_indirect is indirect, in that case you 
may get better results from changing orig_qual_type without decrementing 
orig_qual_indirect."
Isn't that something else than this version with == 0?

Anyway, here's the version with == 0.  Thanks,

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-12-07  Marek Polacek  <polacek@redhat.com>

	PR c/68668
	* c-decl.c (grokdeclarator): If ORIG_QUAL_INDIRECT is indirect, use
	TREE_TYPE of ORIG_QUAL_TYPE, otherwise decrement ORIG_QUAL_INDIRECT.

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


	Marek

Comments

Joseph Myers Dec. 7, 2015, 5:44 p.m. UTC | #1
On Mon, 7 Dec 2015, Marek Polacek wrote:

> Anyway, here's the version with == 0.  Thanks,
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> 2015-12-07  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c/68668
> 	* c-decl.c (grokdeclarator): If ORIG_QUAL_INDIRECT is indirect, use
> 	TREE_TYPE of ORIG_QUAL_TYPE, otherwise decrement ORIG_QUAL_INDIRECT.
> 
> 	* gcc.dg/pr68668.c: New test.

OK.
diff mbox

Patch

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 9ad8219..6a85514 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -6417,6 +6417,13 @@  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)
+	      {
+		if (orig_qual_indirect == 0)
+		  orig_qual_type = TREE_TYPE (orig_qual_type);
+		else
+		  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..d013aa9 100644
--- gcc/testsuite/gcc.dg/pr68668.c
+++ gcc/testsuite/gcc.dg/pr68668.c
@@ -0,0 +1,53 @@ 
+/* PR c/68668 */
+/* { dg-do compile } */
+
+typedef const int T[];
+typedef const int U[1];
+
+int
+fn1 (T p)
+{
+  return p[0];
+}
+
+int
+fn2 (U p[2])
+{
+  return p[0][0];
+}
+
+int
+fn3 (U p[2][3])
+{
+  return p[0][0][0];
+}
+
+int
+fn4 (U *p)
+{
+  return p[0][0];
+}
+
+int
+fn5 (U (*p)[1])
+{
+  return (*p)[0][0];
+}
+
+int
+fn6 (U (*p)[1][2])
+{
+  return (*p)[0][0][0];
+}
+
+int
+fn7 (U **p)
+{
+  return p[0][0][0];
+}
+
+int
+fn8 (U (**p)[1])
+{
+  return (*p)[0][0][0];
+}