[clang] [Clang] [C23] Fix typeof_unqual for qualified array types (PR #92767)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu May 30 13:18:45 PDT 2024


================
@@ -92,3 +92,43 @@ extern __attribute__((address_space(0))) int type_attr_test_2;          // expec
 void invalid_param_fn(__attribute__((address_space(1))) int i); // expected-error {{parameter may not be qualified with an address space}}
 typeof(invalid_param_fn) invalid_param_1;
 typeof_unqual(invalid_param_fn) invalid_param_2;
+
+// Ensure restrict is stripped
+extern int *restrict p1;
+extern int *p2;
+extern typeof(p1) p1;
+extern typeof_unqual(p1) p2;
+
+// Ensure array qualifications are removed
+extern const int aci[2];
+extern const int acii[2][2];
+extern int ai[2];
+extern int aii[2][2];
+extern typeof(aci) aci;
+extern typeof_unqual(aci) ai;
+extern typeof(acii) acii;
+extern typeof_unqual(acii) aii;
+
+extern int *restrict arpi[2];
+extern int *restrict arpii[2][2];
+extern int *api[2];
+extern int *apii[2][2];
+extern typeof(arpi) arpi;
+extern typeof_unqual(arpi) api;
+extern typeof(arpii) arpii;
+extern typeof_unqual(arpii) apii;
+
+extern int _Atomic aAi[2];
+extern int _Atomic aAii[2][2];
+extern typeof(aAi) aAi;
+extern typeof_unqual(aAi) ai;
+extern typeof(aAii) aAii;
+extern typeof_unqual(aAii) aii;
----------------
AaronBallman wrote:

I think this is a more complicated situation, perhaps. `_Atomic` as a type qualifier (as with `_Atomic type`) is excluded in terms of arrays and elements being identically qualified (see footnote 42, which says "This does not apply to the _Atomic qualifier.") so the array is not atomic to begin with. So `typeof_unqual` would strip the non-existent qualifiers from the array in this case but leave them alone in the element type. However, `_Atomic` as a type specifier (as with `_Atomic(type)`) is an atomic-qualified type and so it would be stripped in that case (see footnote 146 which also reminds us that `_Atomic(type-name)` is an atomic-qualified type).

So I think the behavior of this case is correct but we need another test for `_Atomic(int)`.

https://github.com/llvm/llvm-project/pull/92767


More information about the cfe-commits mailing list