Commit 85b58ca5 by Joseph Myers Committed by Joseph Myers

re PR c/12165 (Typedef'ed variables ignore typedef's const qualifier)

	PR c/12165
	* c-decl.c (grokdeclarator): Take type qualifiers of typedefed
	array type from the array element type.

testsuite:
	* gcc.dg/array-quals-1.c, gcc.dg/c90-idem-qual-3.c,
	gcc.dg/c99-idem-qual-3.c: New tests.

From-SVN: r75514
parent 51dc0a0a
2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/12165
* c-decl.c (grokdeclarator): Take type qualifiers of typedefed
array type from the array element type.
2004-01-07 Alan Modra <amodra@bigpond.net.au> 2004-01-07 Alan Modra <amodra@bigpond.net.au>
* config/rs6000/rs6000.c (rs6000_dbx_register_number): New function. * config/rs6000/rs6000.c (rs6000_dbx_register_number): New function.
......
/* Process declarations and variables for C compiler. /* Process declarations and variables for C compiler.
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003 Free Software Foundation, Inc. 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GCC. This file is part of GCC.
...@@ -3349,6 +3349,7 @@ grokdeclarator (tree declarator, tree declspecs, ...@@ -3349,6 +3349,7 @@ grokdeclarator (tree declarator, tree declspecs,
int array_parm_static = 0; int array_parm_static = 0;
tree returned_attrs = NULL_TREE; tree returned_attrs = NULL_TREE;
bool bitfield = width != NULL; bool bitfield = width != NULL;
tree element_type;
if (decl_context == FUNCDEF) if (decl_context == FUNCDEF)
funcdef_flag = 1, decl_context = NORMAL; funcdef_flag = 1, decl_context = NORMAL;
...@@ -3694,10 +3695,19 @@ grokdeclarator (tree declarator, tree declspecs, ...@@ -3694,10 +3695,19 @@ grokdeclarator (tree declarator, tree declspecs,
two ways a declaration can become qualified. One is something two ways a declaration can become qualified. One is something
like `const int i' where the `const' is explicit. Another is like `const int i' where the `const' is explicit. Another is
something like `typedef const int CI; CI i' where the type of the something like `typedef const int CI; CI i' where the type of the
declaration contains the `const'. */ declaration contains the `const'. A third possibility is that
constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type); there is a type qualifier on the element type of a typedefed
restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type); array type, in which case we should extract that qualifier so
volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type); that c_apply_type_quals_to_decls receives the full list of
qualifiers to work with (C90 is not entirely clear about whether
duplicate qualifiers should be diagnosed in this case, but it
seems most appropriate to do so). */
element_type = strip_array_types (type);
constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (element_type);
restrictp
= !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (element_type);
volatilep
= !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (element_type);
inlinep = !! (specbits & (1 << (int) RID_INLINE)); inlinep = !! (specbits & (1 << (int) RID_INLINE));
if (constp > 1 && ! flag_isoc99) if (constp > 1 && ! flag_isoc99)
pedwarn ("duplicate `const'"); pedwarn ("duplicate `const'");
......
2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/12165
* gcc.dg/array-quals-1.c, gcc.dg/c90-idem-qual-3.c,
gcc.dg/c99-idem-qual-3.c: New tests.
2004-01-07 Alan Modra <amodra@bigpond.net.au> 2004-01-07 Alan Modra <amodra@bigpond.net.au>
* gcc.dg/winline-7.c: Don't cast void * to int. * gcc.dg/winline-7.c: Don't cast void * to int.
......
/* Test for various combinations of const, arrays and typedefs:
should never actually get const on the final array type, but
all should end up in a read-only section. PR c/12165. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-final { scan-assembler-not "\\.data" } } */
static const int a[2] = { 1, 2 };
const int a1[2] = { 1, 2 };
typedef const int ci;
static ci b[2] = { 3, 4 };
ci b1[2] = { 3, 4 };
typedef int ia[2];
static const ia c = { 5, 6 };
const ia c1 = { 5, 6 };
typedef const int cia[2];
static cia d = { 7, 8 };
cia d1 = { 7, 8 };
static cia e[2] = { { 1, 2 }, { 3, 4 } };
cia e1[2] = { { 1, 2 }, { 3, 4 } };
void *const p = &a;
void *const q = &b;
void *const r = &c;
void *const s = &d;
void *const t = &e;
void *const p1 = &a1;
void *const q1 = &b1;
void *const r1 = &c1;
void *const s1 = &d1;
void *const t1 = &e1;
/* Test for idempotent type qualifiers: in C99 only. Test duplicate
type qualifiers with array element types. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
typedef const int cia[2];
const cia a; /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "duplicate" "duplicate type qualifier error" { target *-*-* } 8 } */
const cia b[2]; /* { dg-bogus "warning" "warning in place of error" } */
/* { dg-error "duplicate" "duplicate type qualifier error" { target *-*-* } 10 } */
/* Test for idempotent type qualifiers: in C99 only. Test duplicate
type qualifiers with array element types. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
typedef const int cia[2];
const cia a; /* { dg-bogus "duplicate" "duplicate type qualifier warning" } */
const cia b[2]; /* { dg-bogus "duplicate" "duplicate type qualifier warning" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment