aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c52
1 files changed, 48 insertions, 4 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 1ec3842010b..59dd407758d 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -330,7 +330,8 @@ combine_strings (strings)
= build_array_type (wide_flag ? wchar_type_node : char_type_node,
build_index_type (build_int_2 (nchars - 1, 0)));
- TREE_READONLY (value) = TREE_CONSTANT (value) = ! flag_writable_strings;
+ TREE_CONSTANT (value) = 1;
+ TREE_READONLY (value) = ! flag_writable_strings;
TREE_STATIC (value) = 1;
return value;
}
@@ -3205,11 +3206,54 @@ c_get_alias_set (t)
whose type is the same as one of the fields, recursively, but
we don't yet make any use of that information.) */
TYPE_ALIAS_SET (type) = 0;
+ else if (TREE_CODE (type) == POINTER_TYPE
+ || TREE_CODE (type) == REFERENCE_TYPE)
+ {
+ tree t;
+
+ /* Unfortunately, there is no canonical form of a pointer type.
+ In particular, if we have `typedef int I', then `int *', and
+ `I *' are different types. So, we have to pick a canonical
+ representative. We do this below.
+
+ Technically, this approach is actually more conservative that
+ it needs to be. In particular, `const int *' and `int *'
+ chould be in different alias sets, according to the C and C++
+ standard, since their types are not the same, and so,
+ technically, an `int **' and `const int **' cannot point at
+ the same thing.
+
+ But, the standard is wrong. In particular, this code is
+ legal C++:
+
+ int *ip;
+ int **ipp = &ip;
+ const int* const* cipp = &ip;
+
+ And, it doesn't make sense for that to be legal unless you
+ can dereference IPP and CIPP. So, we ignore cv-qualifiers on
+ the pointed-to types. This issue has been reported to the
+ C++ committee. */
+ t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
+ t = ((TREE_CODE (type) == POINTER_TYPE)
+ ? build_pointer_type (t) : build_reference_type (t));
+ if (t != type)
+ TYPE_ALIAS_SET (type) = c_get_alias_set (t);
+ }
if (!TYPE_ALIAS_SET_KNOWN_P (type))
- /* TYPE is something we haven't seen before. Put it in a new
- alias set. */
- TYPE_ALIAS_SET (type) = new_alias_set ();
+ {
+ /* Types that are not allocated on the permanent obstack are not
+ placed in the type hash table. Thus, there can be multiple
+ copies of identical types in local scopes. In the long run,
+ all types should be permanent. */
+ if (! TREE_PERMANENT (type))
+ TYPE_ALIAS_SET (type) = 0;
+ else
+ /* TYPE is something we haven't seen before. Put it in a new
+ alias set. */
+ TYPE_ALIAS_SET (type) = new_alias_set ();
+ }
return TYPE_ALIAS_SET (type);
}