diff options
author | Joseph Myers <joseph@codesourcery.com> | 2010-06-05 13:54:41 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2010-06-05 13:54:41 +0100 |
commit | f2c1da78929f644fdd6cd556769f1ecbe1614cf1 (patch) | |
tree | 6a1083c9a3ed75f534e40143e61b6ec996cb7901 | |
parent | e68edbf6bcedca8428a96fc94fa25dab97b68860 (diff) | |
download | gcc-f2c1da78929f644fdd6cd556769f1ecbe1614cf1.zip gcc-f2c1da78929f644fdd6cd556769f1ecbe1614cf1.tar.gz gcc-f2c1da78929f644fdd6cd556769f1ecbe1614cf1.tar.bz2 |
re PR c/44322 (Bogus warning when assigning pointer-to-array with both "const" and "restrict")
PR c/44322
* c-typeck.c (build_unary_op): Merge qualifiers into pointer
target type for ADDR_EXPR; require no changes to qualifiers except
for function types.
* c-tree.h (c_build_type_variant): Remove.
testsuite:
* gcc.dg/c99-restrict-4.c: New test.
From-SVN: r160312
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-tree.h | 5 | ||||
-rw-r--r-- | gcc/c-typeck.c | 22 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/c99-restrict-4.c | 17 |
5 files changed, 46 insertions, 11 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e492b28..8dc548d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2010-06-05 Joseph Myers <joseph@codesourcery.com> + + PR c/44322 + * c-typeck.c (build_unary_op): Merge qualifiers into pointer + target type for ADDR_EXPR; require no changes to qualifiers except + for function types. + * c-tree.h (c_build_type_variant): Remove. + 2010-06-05 Segher Boessenkool <segher@kernel.crashing.org> genautomata.c (get_excl_set): Do work per element, not per char. diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 30b5274..1921e19 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -490,11 +490,6 @@ extern bool c_warn_unused_global_decl (const_tree); extern void c_initialize_diagnostics (diagnostic_context *); extern bool c_vla_unspec_p (tree x, tree fn); -#define c_build_type_variant(TYPE, CONST_P, VOLATILE_P) \ - c_build_qualified_type ((TYPE), \ - ((CONST_P) ? TYPE_QUAL_CONST : 0) | \ - ((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0)) - /* in c-typeck.c */ extern bool in_late_binary_op; extern int in_alignof; diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 39965d5..5a291de 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3744,14 +3744,24 @@ build_unary_op (location_t location, argtype = TREE_TYPE (arg); /* If the lvalue is const or volatile, merge that into the type - to which the address will point. Note that you can't get a - restricted pointer by taking the address of something, so we - only have to deal with `const' and `volatile' here. */ + to which the address will point. This should only be needed + for function types. */ if ((DECL_P (arg) || REFERENCE_CLASS_P (arg)) && (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))) - argtype = c_build_type_variant (argtype, - TREE_READONLY (arg), - TREE_THIS_VOLATILE (arg)); + { + int orig_quals = TYPE_QUALS (strip_array_types (argtype)); + int quals = orig_quals; + + if (TREE_READONLY (arg)) + quals |= TYPE_QUAL_CONST; + if (TREE_THIS_VOLATILE (arg)) + quals |= TYPE_QUAL_VOLATILE; + + gcc_assert (quals == orig_quals + || TREE_CODE (argtype) == FUNCTION_TYPE); + + argtype = c_build_qualified_type (argtype, quals); + } if (!c_mark_addressable (arg)) return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index accf2e3..041f762 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-06-05 Joseph Myers <joseph@codesourcery.com> + + PR c/44322 + * gcc.dg/c99-restrict-4.c: New test. + 2010-06-04 Magnus Fromreide <magfr@lysator.liu.se> * g++.dg/cpp0x/nullptr01.C: Test nullptr_t variable. diff --git a/gcc/testsuite/gcc.dg/c99-restrict-4.c b/gcc/testsuite/gcc.dg/c99-restrict-4.c new file mode 100644 index 0000000..5852d0a --- /dev/null +++ b/gcc/testsuite/gcc.dg/c99-restrict-4.c @@ -0,0 +1,17 @@ +/* Qualifiers lost when taking the address of a const restrict object. + PR 44322. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ +void * restrict const a[2]; +void * restrict const (*p2)[2]; + +void foo(void) { + p2 = &a; +} + +void * restrict volatile b[2]; +void * restrict volatile (*q2)[2]; + +void bar(void) { + q2 = &b; +} |