summaryrefslogtreecommitdiff
path: root/gcc/c-typeck.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-06-05 13:54:41 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2010-06-05 13:54:41 +0100
commitf2c1da78929f644fdd6cd556769f1ecbe1614cf1 (patch)
tree6a1083c9a3ed75f534e40143e61b6ec996cb7901 /gcc/c-typeck.c
parente68edbf6bcedca8428a96fc94fa25dab97b68860 (diff)
downloadgcc-f2c1da78929f644fdd6cd556769f1ecbe1614cf1.tar.gz
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
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r--gcc/c-typeck.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 39965d527b0..5a291de497f 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;