diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index feafc91d..7c267bb1 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -1261,6 +1261,51 @@ process_ctf_array_type(reader *rdr,
return result;
}
+/// Strip qualification from a qualified type, when it makes sense.
+///
+/// CTF constructs "const const char [N]" for "const char foo[N]"
+/// definition; This redundant types then causes bad diagnostics
+/// when it is compared with an DWARF IR.
+///
+/// This function thus strips the const qualifier from the type in
+/// that case. It might contain code to strip other cases like this
+/// in the future.
+///
+/// @param t the type to strip const qualification from.
+///
+/// @param rdr the @ref reader to use.
+///
+/// @return the stripped type or just return @p t.
+static decl_base_sptr
+maybe_strip_qualification(const qualified_type_def_sptr t,
+ reader *rdr)
+{
+ if (!t)
+ return t;
+
+ decl_base_sptr result = t;
+ type_base_sptr u = t->get_underlying_type();
+
+ if (is_array_type(u) || is_typedef_of_array(u))
+ {
+ array_type_def_sptr array = is_array_type(u);
+ ABG_ASSERT(array);
+ // We should not be editing types that are already canonicalized.
+ ABG_ASSERT(!array->get_canonical_type());
+ type_base_sptr element_type = array->get_element_type();
+
+ if (qualified_type_def_sptr qualified = is_qualified_type(element_type))
+ {
+ qualified_type_def::CV quals = qualified->get_cv_quals();
+ quals |= t->get_cv_quals();
+ qualified->set_cv_quals(quals);
+ result = is_decl(u);
+ }
+ }
+
+ return result;
+}
+
/// Build and return a qualified type libabigail IR.
///
/// @param rdr the read context.
@@ -1304,8 +1349,16 @@ process_ctf_qualified_type(reader *rdr,
result.reset(new qualified_type_def(utype, qualifiers, location()));
if (result)
{
- decl_base_sptr qualified_type_decl = get_type_declaration(result);
- add_decl_to_scope(qualified_type_decl, tunit->get_global_scope());
+ // Strip some potentially redundant type qualifiers from
+ // the qualified type we just built.
+ decl_base_sptr d = maybe_strip_qualification(is_qualified_type(result),
+ rdr);
+ if (!d)
+ d = get_type_declaration(result);
+ ABG_ASSERT(d);
+
+ add_decl_to_scope(d, tunit->get_global_scope());
+ result = is_type(d);
rdr->add_type(ctf_dictionary, ctf_type, result);
}
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index b89a4dd8..8d4a2b8f 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -710,6 +710,9 @@ test-read-ctf/test-bitfield.o \
test-read-ctf/test-bitfield-enum.abi \
test-read-ctf/test-bitfield-enum.c \
test-read-ctf/test-bitfield-enum.o \
+test-read-ctf/test-const-array.abi \
+test-read-ctf/test-const-array.c \
+test-read-ctf/test-const-array.o \
\
test-annotate/test0.abi \
test-annotate/test1.abi \
diff --git a/tests/data/test-read-ctf/test-const-array.abi b/tests/data/test-read-ctf/test-const-array.abi
new file mode 100644
index 00000000..bd60b098
--- /dev/null
+++ b/tests/data/test-read-ctf/test-const-array.abi
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/data/test-read-ctf/test-const-array.c b/tests/data/test-read-ctf/test-const-array.c
new file mode 100644
index 00000000..4ffecf87
--- /dev/null
+++ b/tests/data/test-read-ctf/test-const-array.c
@@ -0,0 +1,2 @@
+/* gcc -gctf -c test-const-array.c -o test-const-array.o */
+const char a[32];
diff --git a/tests/data/test-read-ctf/test-const-array.o b/tests/data/test-read-ctf/test-const-array.o
new file mode 100644
index 0000000000000000000000000000000000000000..b50e2fe5a7f7c86b3220c08782ee1d72035cc4d3
GIT binary patch
literal 1416
zcmbtU&2H2%5T3NlQhpA!LRAG4GACL=oNPFi1B$4i91sU2?sc+eH)__YY*#cVu1LM`
zNPQEY0bT%R5__|?Rz1K-
z(X#SrfWQcS(k-VC(4L^4qTWK?b4tG3Z%h{Pn`lTfipQM`W9pOlKCL^n(8dI2s7^B4
z6Uw>JP&aDE&XuWVN={j&EC@*E%|a$cTeL}|MOn+l=rXCRLKM|ZRCTQ6*ThO=O)?c$
zbZ)Grn8v03(nn>ZjE#lXqUELE_6B==bo7etAAkIOz$Pzw%2Sr5SvHxZhiqS7oJn0R
zq_Uzu=zGxl87kcil5oc8s+$R8lE}q$H#Z5@NAT-UhIZhHAE6P(B&(t|T(+y5rQxoPq9on|M)yQ_fB9#{xhu88~s=Q3*?49Y0I1zl<-4_*a>1N
zxBM{@2_<(x)T|2m%XP^$*iV?djT)Z+hvSFm
zqPt!df`weFUpfAJ2fpiYo=^WnBzI85Z%6qp*L0VH6$!`M#@agm6UUb;TyjJHU(J