<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 14, 2021 at 10:04 AM Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, 13 Sept 2021 at 19:24, David Blaikie via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: David Blaikie<br>
Date: 2021-09-13T19:17:05-07:00<br>
New Revision: 2bd84938470bf2e337801faafb8a67710f46429d<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/2bd84938470bf2e337801faafb8a67710f46429d.diff</a><br>
<br>
LOG: Improve type printing of const arrays to normalize array-of-const and const-array<br>
<br>
Since these map to the same effective type - render them the same/in the<br>
more legible way (const x[n]).<br></blockquote><div><br></div><div>Nice!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Added: <br>
<br>
<br>
Modified: <br>
clang/lib/AST/TypePrinter.cpp<br>
clang/test/ARCMT/<a href="http://cxx-checking.mm" rel="noreferrer" target="_blank">cxx-checking.mm</a><br>
clang/test/AST/ast-dump-APValue-arithmetic.cpp<br>
clang/test/AST/ast-dump-APValue-array.cpp<br>
clang/test/CXX/basic/basic.types/p10.cpp<br>
clang/test/Sema/assign.c<br>
clang/test/Sema/typedef-retain.c<br>
clang/test/SemaCXX/reinterpret-cast.cpp<br>
clang/test/SemaCXX/static-assert-cxx17.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp<br>
index aef1e4f3f4953..251db97c7db08 100644<br>
--- a/clang/lib/AST/TypePrinter.cpp<br>
+++ b/clang/lib/AST/TypePrinter.cpp<br>
@@ -200,11 +200,12 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,<br>
// type expands to a simple string.<br>
bool CanPrefixQualifiers = false;<br>
NeedARCStrongQualifier = false;<br>
- Type::TypeClass TC = T->getTypeClass();<br>
+ const Type *UnderlyingType = T;<br>
if (const auto *AT = dyn_cast<AutoType>(T))<br>
- TC = AT->desugar()->getTypeClass();<br>
+ UnderlyingType = AT->desugar().getTypePtr();<br>
if (const auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T))<br>
- TC = Subst->getReplacementType()->getTypeClass();<br>
+ UnderlyingType = Subst->getReplacementType().getTypePtr();<br>
+ Type::TypeClass TC = UnderlyingType->getTypeClass();<br>
<br>
switch (TC) {<br>
case Type::Auto:<br>
@@ -243,6 +244,9 @@ bool TypePrinter::canPrefixQualifiers(const Type *T,<br>
<br>
case Type::ConstantArray:<br>
case Type::IncompleteArray:<br>
+ return canPrefixQualifiers(<br>
+ cast<ArrayType>(UnderlyingType)->getElementType().getTypePtr(),<br>
+ NeedARCStrongQualifier);<br>
case Type::VariableArray:<br>
case Type::DependentSizedArray:<br></blockquote><div><br></div><div>Can we give these two cases the same treatment?</div></div></div></blockquote><div><br>Handled the DependentSizedArray in <a href="https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00">https://github.com/llvm/llvm-project/commit/40acc0adad59ac39e9a7a02fcd93161298500c00</a><br><br>But per the comment in that commit I wasn't able to reproduce the problem with a variable array - though we could include it in the handling on principle/for consistency, even without a test/etc. Perhaps there's a way to test/provoke the behavior you might know that I couldn't figure out?<br><br>Details from the commit:<br><br>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>The VariableArray case I couldn't figure out how to test/provoke - you</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>can't write/form a variable array in any context other than a local</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>variable that I know of, and in that case `const int x[n]` is the</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>normalized form already (array-of-const) and you can't use typedefs</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>(since you can't typedef int[n] with variable 'n') to force the</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>const-array AST that would produce the undesirable type printing "int</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>const [n]".</span></p><br>Oh, also - another quirk of array type printing that I'd be up for addressing if you've got an opinion on it:<br><br>"int [n]" is printed with a space between the "int" and array.<br>"int *const[n]" is printed without a space before the array (though both have a space after "int")<br><br>ClangFormat formats these as "int[n]" and "int *const[n]" - with * left/right depending on ClangFormat's heuristics/configuration.<br><br>Reckon we should remove the space in "int[n]"?<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
NeedARCStrongQualifier = true; </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
diff --git a/clang/test/ARCMT/<a href="http://cxx-checking.mm" rel="noreferrer" target="_blank">cxx-checking.mm</a> b/clang/test/ARCMT/<a href="http://cxx-checking.mm" rel="noreferrer" target="_blank">cxx-checking.mm</a><br>
index 952f3cdcbb79c..d6441def09b40 100644<br>
--- a/clang/test/ARCMT/<a href="http://cxx-checking.mm" rel="noreferrer" target="_blank">cxx-checking.mm</a><br>
+++ b/clang/test/ARCMT/<a href="http://cxx-checking.mm" rel="noreferrer" target="_blank">cxx-checking.mm</a><br>
@@ -80,7 +80,7 @@<br>
<br>
struct FlexibleArrayMember0 {<br>
int length;<br>
- id array[]; // expected-error{{flexible array member 'array' of type 'id __strong[]' with non-trivial destruction}}<br>
+ id array[]; // expected-error{{flexible array member 'array' of type '__strong id []' with non-trivial destruction}}<br>
};<br>
<br>
struct FlexibleArrayMember1 {<br>
<br>
diff --git a/clang/test/AST/ast-dump-APValue-arithmetic.cpp b/clang/test/AST/ast-dump-APValue-arithmetic.cpp<br>
index 835d8c8108346..e51c1cee04cfe 100644<br>
--- a/clang/test/AST/ast-dump-APValue-arithmetic.cpp<br>
+++ b/clang/test/AST/ast-dump-APValue-arithmetic.cpp<br>
@@ -36,13 +36,13 @@ void Test() {<br>
// CHECK-NEXT: | |-value: ComplexFloat 3.141500e+00 + 4.200000e+01i<br>
<br>
constexpr _Complex int ArrayOfComplexInt[10] = {ComplexInt, ComplexInt, ComplexInt, ComplexInt};<br>
- // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexInt '_Complex int const[10]' constexpr cinit<br>
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexInt 'const _Complex int [10]' constexpr cinit<br>
// CHECK-NEXT: | |-value: Array size=10<br>
// CHECK-NEXT: | | |-elements: ComplexInt 42 + 24i, ComplexInt 42 + 24i, ComplexInt 42 + 24i, ComplexInt 42 + 24i<br>
// CHECK-NEXT: | | `-filler: 6 x ComplexInt 0 + 0i<br>
<br>
constexpr _Complex float ArrayOfComplexFloat[10] = {ComplexFloat, ComplexFloat, ComplexInt, ComplexInt};<br>
- // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexFloat '_Complex float const[10]' constexpr cinit<br>
+ // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexFloat 'const _Complex float [10]' constexpr cinit<br>
// CHECK-NEXT: |-value: Array size=10<br>
// CHECK-NEXT: | |-elements: ComplexFloat 3.141500e+00 + 4.200000e+01i, ComplexFloat 3.141500e+00 + 4.200000e+01i, ComplexFloat 4.200000e+01 + 2.400000e+01i, ComplexFloat 4.200000e+01 + 2.400000e+01i<br>
// CHECK-NEXT: | `-filler: 6 x ComplexFloat 0.000000e+00 + 0.000000e+00i<br>
<br>
diff --git a/clang/test/AST/ast-dump-APValue-array.cpp b/clang/test/AST/ast-dump-APValue-array.cpp<br>
index f9b38ec332a5b..72e519208ac56 100644<br>
--- a/clang/test/AST/ast-dump-APValue-array.cpp<br>
+++ b/clang/test/AST/ast-dump-APValue-array.cpp<br>
@@ -43,7 +43,7 @@ void Test() {<br>
constexpr float arr_f[3][5] = {<br>
{1, 2, 3, 4, 5},<br>
};<br>
- // CHECK: | `-VarDecl {{.*}} <line:{{.*}}, line:{{.*}}> line:{{.*}} arr_f 'float const[3][5]' constexpr cinit<br>
+ // CHECK: | `-VarDecl {{.*}} <line:{{.*}}, line:{{.*}}> line:{{.*}} arr_f 'const float [3][5]' constexpr cinit<br>
// CHECK-NEXT: | |-value: Array size=3<br>
// CHECK-NEXT: | | |-element: Array size=5<br>
// CHECK-NEXT: | | | |-elements: Float 1.000000e+00, Float 2.000000e+00, Float 3.000000e+00, Float 4.000000e+00<br>
@@ -52,7 +52,7 @@ void Test() {<br>
// CHECK-NEXT: | | `-filler: 5 x Float 0.000000e+00<br>
<br>
constexpr S0 arr_s0[2] = {{1, 2}, {3, 4}};<br>
- // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s0 'S0 const[2]' constexpr cinit<br>
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s0 'const S0 [2]' constexpr cinit<br>
// CHECK-NEXT: | |-value: Array size=2<br>
// CHECK-NEXT: | | |-element: Struct<br>
// CHECK-NEXT: | | | `-field: Array size=2<br>
@@ -62,12 +62,12 @@ void Test() {<br>
// CHECK-NEXT: | | `-elements: Int 3, Int 4<br>
<br>
constexpr U0 arr_u0[2] = {{.i = 42}, {.f = 3.1415f}};<br>
- // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_u0 'U0 const[2]' constexpr cinit<br>
+ // CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_u0 'const U0 [2]' constexpr cinit<br>
// CHECK-NEXT: | |-value: Array size=2<br>
// CHECK-NEXT: | | `-elements: Union .i Int 42, Union .f Float 3.141500e+00<br>
<br>
constexpr S1 arr_s1[2] = {};<br>
- // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s1 'S1 const[2]' constexpr cinit<br>
+ // CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s1 'const S1 [2]' constexpr cinit<br>
// CHECK-NEXT: |-value: Array size=2<br>
// CHECK-NEXT: | |-element: Struct<br>
// CHECK-NEXT: | | |-field: Struct<br>
<br>
diff --git a/clang/test/CXX/basic/basic.types/p10.cpp b/clang/test/CXX/basic/basic.types/p10.cpp<br>
index aac07c76bed2e..eae0c6513ac24 100644<br>
--- a/clang/test/CXX/basic/basic.types/p10.cpp<br>
+++ b/clang/test/CXX/basic/basic.types/p10.cpp<br>
@@ -32,7 +32,7 @@ struct Incomplete; // expected-note 2{{forward declaration of 'Incomplete'}}<br>
template<class T> struct ClassTemp {};<br>
<br>
constexpr Incomplete incomplete = {}; // expected-error {{constexpr variable cannot have non-literal type 'const Incomplete'}} expected-note {{incomplete type 'const Incomplete' is not a literal type}}<br>
-constexpr Incomplete incomplete2[] = {}; // expected-error {{constexpr variable cannot have non-literal type 'Incomplete const[]'}} expected-note {{incomplete type 'Incomplete const[]' is not a literal type}}<br>
+constexpr Incomplete incomplete2[] = {}; // expected-error {{constexpr variable cannot have non-literal type 'const Incomplete []'}} expected-note {{incomplete type 'const Incomplete []' is not a literal type}}<br>
constexpr ClassTemp<int> classtemplate = {};<br>
constexpr ClassTemp<int> classtemplate2[] = {};<br>
<br>
<br>
diff --git a/clang/test/Sema/assign.c b/clang/test/Sema/assign.c<br>
index 3edd5d4feaf2e..d65f9bf26547e 100644<br>
--- a/clang/test/Sema/assign.c<br>
+++ b/clang/test/Sema/assign.c<br>
@@ -13,7 +13,7 @@ typedef int arr[10];<br>
void test3() {<br>
const arr b; // expected-note {{variable 'b' declared const here}}<br>
const int b2[10]; // expected-note {{variable 'b2' declared const here}}<br>
- b[4] = 1; // expected-error {{cannot assign to variable 'b' with const-qualified type 'const arr' (aka 'int const[10]')}}<br>
+ b[4] = 1; // expected-error {{cannot assign to variable 'b' with const-qualified type 'const arr' (aka 'const int [10]')}}<br>
b2[4] = 1; // expected-error {{cannot assign to variable 'b2' with const-qualified type 'const int [10]'}}<br>
}<br>
<br>
<br>
diff --git a/clang/test/Sema/typedef-retain.c b/clang/test/Sema/typedef-retain.c<br>
index 70e2abc1da5b8..d4358bce5ee5b 100644<br>
--- a/clang/test/Sema/typedef-retain.c<br>
+++ b/clang/test/Sema/typedef-retain.c<br>
@@ -17,7 +17,7 @@ typedef int a[5];<br>
void test3() {<br>
typedef const a b;<br>
b r; // expected-note {{variable 'r' declared const here}}<br>
- r[0] = 10; // expected-error {{cannot assign to variable 'r' with const-qualified type 'b' (aka 'int const[5]')}}<br>
+ r[0] = 10; // expected-error {{cannot assign to variable 'r' with const-qualified type 'b' (aka 'const int [5]')}}<br>
}<br>
<br>
int test4(const a y) {<br>
<br>
diff --git a/clang/test/SemaCXX/reinterpret-cast.cpp b/clang/test/SemaCXX/reinterpret-cast.cpp<br>
index 6a4bc91665448..f427af1efbafc 100644<br>
--- a/clang/test/SemaCXX/reinterpret-cast.cpp<br>
+++ b/clang/test/SemaCXX/reinterpret-cast.cpp<br>
@@ -132,7 +132,7 @@ void const_arrays() {<br>
const STRING *s;<br>
const char *c;<br>
<br>
- (void)reinterpret_cast<char *>(s); // expected-error {{reinterpret_cast from 'const STRING *' (aka 'char const (*)[10]') to 'char *' casts away qualifiers}}<br>
+ (void)reinterpret_cast<char *>(s); // expected-error {{reinterpret_cast from 'const STRING *' (aka 'const char (*)[10]') to 'char *' casts away qualifiers}}<br>
(void)reinterpret_cast<const STRING *>(c);<br>
}<br>
<br>
<br>
diff --git a/clang/test/SemaCXX/static-assert-cxx17.cpp b/clang/test/SemaCXX/static-assert-cxx17.cpp<br>
index fe02f8f29965f..d5601839bdd3e 100644<br>
--- a/clang/test/SemaCXX/static-assert-cxx17.cpp<br>
+++ b/clang/test/SemaCXX/static-assert-cxx17.cpp<br>
@@ -94,7 +94,7 @@ void foo6() {<br>
static_assert(static_cast<const X<typename T::T> *>(nullptr));<br>
// expected-error@-1{{static_assert failed due to requirement 'static_cast<const X<int> *>(nullptr)'}}<br>
static_assert((const X<typename T::T>[]){} == nullptr);<br>
- // expected-error@-1{{static_assert failed due to requirement '(X<int> const[0]){} == nullptr'}}<br>
+ // expected-error@-1{{static_assert failed due to requirement '(const X<int> [0]){} == nullptr'}}<br>
static_assert(sizeof(X<decltype(X<typename T::T>().X<typename T::T>::~X())>) == 0);<br>
// expected-error@-1{{static_assert failed due to requirement 'sizeof(X<void>) == 0'}}<br>
static_assert(constexpr_return_false<typename T::T, typename T::U>());<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>
</blockquote></div></div>