return NULL;
/* Only these cv-qualifiers are currently handled. */
- cv_quals &= (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
+ cv_quals &= (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT);
+
+ /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
+ tag modifier (and not an attribute) old consumers won't be able
+ to handle it. */
+ if (dwarf_version < 3)
+ cv_quals &= ~TYPE_QUAL_RESTRICT;
/* See if we already have the appropriately qualified variant of
this type. */
else
{
int dquals = TYPE_QUALS_NO_ADDR_SPACE (dtype);
- dquals &= (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
+ dquals &= (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT);
if ((dquals & ~cv_quals) != TYPE_UNQUALIFIED
|| (cv_quals == dquals && DECL_ORIGINAL_TYPE (name) != type))
/* cv-unqualified version of named type. Just use
mod_scope = scope_die_for (type, context_die);
if ((cv_quals & TYPE_QUAL_CONST)
- /* If both const_type and volatile_type, prefer the path
- which leads to a qualified type. */
- && (!(cv_quals & TYPE_QUAL_VOLATILE)
- || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
- || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
+ /* If there are multiple type modifiers, prefer a path which
+ leads to a qualified type. */
+ && (((cv_quals & ~TYPE_QUAL_CONST) == TYPE_UNQUALIFIED)
+ || get_qualified_type (type, cv_quals) == NULL_TREE
+ || (get_qualified_type (type, cv_quals & ~TYPE_QUAL_CONST)
+ != NULL_TREE)))
{
mod_type_die = new_die (DW_TAG_const_type, mod_scope, type);
sub_die = modified_type_die (type, cv_quals & ~TYPE_QUAL_CONST,
context_die);
}
- else if (cv_quals & TYPE_QUAL_VOLATILE)
+ else if ((cv_quals & TYPE_QUAL_VOLATILE)
+ && (((cv_quals & ~TYPE_QUAL_VOLATILE) == TYPE_UNQUALIFIED)
+ || get_qualified_type (type, cv_quals) == NULL_TREE
+ || (get_qualified_type (type, cv_quals & ~TYPE_QUAL_VOLATILE)
+ != NULL_TREE)))
{
mod_type_die = new_die (DW_TAG_volatile_type, mod_scope, type);
sub_die = modified_type_die (type, cv_quals & ~TYPE_QUAL_VOLATILE,
context_die);
}
+ else if (cv_quals & TYPE_QUAL_RESTRICT)
+ {
+ mod_type_die = new_die (DW_TAG_restrict_type, mod_scope, type);
+ sub_die = modified_type_die (type, cv_quals & ~TYPE_QUAL_RESTRICT,
+ context_die);
+ }
else if (code == POINTER_TYPE)
{
mod_type_die = new_die (DW_TAG_pointer_type, mod_scope, type);
--- /dev/null
+/* debuginfo tests for combinations of const, volatile, restrict pointers. */
+/* { dg-do run } */
+/* { dg-options "-std=c99 -gdwarf-3" } */
+
+int *ip;
+const int *cip;
+int * restrict irp;
+int * const icp;
+const int * restrict cirp;
+int * const restrict icrp;
+const int * const restrict cicrp;
+
+int * const volatile restrict cvirp;
+const volatile int * restrict pcvir;
+
+static __attribute__((noclone, noinline)) void *
+cpy (void * restrict s1, const void * restrict s2, unsigned int n)
+{
+ char *t1 = s1;
+ const char *t2 = s2;
+ while(n-- > 0)
+ *t1++ = *t2++;
+ return s1;
+}
+
+int
+main (int argc, char **argv)
+{
+ void *foo = 0;
+ if (argc > 16)
+ foo = cpy (argv[0], argv[1], argc);
+
+ return foo != 0;
+}
+
+/* { dg-final { gdb-test 30 "type:ip" "int *" } } */
+/* { dg-final { gdb-test 30 "type:cip" "const int *" } } */
+/* { dg-final { gdb-test 30 "type:irp" "int * restrict" } } */
+/* { dg-final { gdb-test 30 "type:icp" "int * const" } } */
+/* { dg-final { gdb-test 30 "type:cirp" "const int * restrict" } } */
+/* { dg-final { gdb-test 30 "type:icrp" "int * const restrict" } } */
+/* { dg-final { gdb-test 30 "type:cicrp" "const int * const restrict" } } */
+
+/* { dg-final { gdb-test 30 "type:cvirp" "int * const volatile restrict" } } */
+/* { dg-final { gdb-test 30 "type:pcvir" "const volatile int * restrict" } } */
+
+/* { dg-final { gdb-test 30 "type:main" "int (int, char **)" } } */
+/* { dg-final { gdb-test 30 "type:cpy" "void *(void * restrict, const void * restrict, unsigned int)" } } */