Skip to content

Commit aee4925

Browse files
committed
Recommit: Compress formatting of array type names (int [4] -> int[4])
Based on post-commit review discussion on 2bd8493 with Richard Smith. Other uses of forcing HasEmptyPlaceHolder to false seem OK to me - they're all around pointer/reference types where the pointer/reference token will appear at the rightmost side of the left side of the type name, so they make nested types (eg: the "int" in "int *") behave as though there is a non-empty placeholder (because the "*" is essentially the placeholder as far as the "int" is concerned). This was originally committed in 277623f Reverted in f9ad1d1 due to breakages outside of clang - lldb seems to have some strange/strong dependence on "char [N]" versus "char[N]" when printing strings (not due to that name appearing in DWARF, but probably due to using clang to stringify type names) that'll need to be addressed, plus a few other odds and ends in other subprojects (clang-tools-extra, compiler-rt, etc).
1 parent 626f044 commit aee4925

File tree

191 files changed

+605
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+605
-607
lines changed

clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ TEST_F(LSPTest, Diagnostics) {
131131
EXPECT_THAT(Client.diagnostics("foo.cpp"),
132132
llvm::ValueIs(testing::ElementsAre(
133133
DiagMessage("Cannot initialize a variable of type 'int' with "
134-
"an lvalue of type 'const char [3]'"))));
134+
"an lvalue of type 'const char[3]'"))));
135135

136136
Client.didClose("foo.cpp");
137137
EXPECT_THAT(Client.diagnostics("foo.cpp"), llvm::ValueIs(testing::IsEmpty()));

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ o]]();
181181
Diag(Test.range("unk"), "use of undeclared identifier 'unknown'"),
182182
Diag(Test.range("type"),
183183
"cannot initialize a variable of type 'double' with an lvalue "
184-
"of type 'const char [4]'"),
184+
"of type 'const char[4]'"),
185185
Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
186186
Diag(Test.range("nomembernamespace"),
187187
"no member named 'test' in namespace 'test'"),

clang-tools-extra/clangd/unittests/HoverTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ class Foo {})cpp";
899899
[](HoverInfo &HI) {
900900
HI.Name = "expression";
901901
HI.Kind = index::SymbolKind::Unknown;
902-
HI.Type = "int [10]";
902+
HI.Type = "int[10]";
903903
HI.Value = "{1}";
904904
}}};
905905
for (const auto &Case : Cases) {

clang/bindings/python/tests/cindex/test_type.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ def test_type_spelling(self):
175175
self.assertIsNotNone(i)
176176
self.assertIsNotNone(x)
177177
self.assertIsNotNone(v)
178-
self.assertEqual(c.type.spelling, "int [5]")
179-
self.assertEqual(i.type.spelling, "int []")
178+
self.assertEqual(c.type.spelling, "int[5]")
179+
self.assertEqual(i.type.spelling, "int[]")
180180
self.assertEqual(x.type.spelling, "int")
181-
self.assertEqual(v.type.spelling, "int [x]")
181+
self.assertEqual(v.type.spelling, "int[x]")
182182

183183
def test_typekind_spelling(self):
184184
"""Ensure TypeKind.spelling works."""

clang/lib/AST/TypePrinter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ void TypePrinter::printMemberPointerAfter(const MemberPointerType *T,
503503
void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
504504
raw_ostream &OS) {
505505
IncludeStrongLifetimeRAII Strong(Policy);
506-
SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
507506
printBefore(T->getElementType(), OS);
508507
}
509508

@@ -526,7 +525,6 @@ void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
526525
void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T,
527526
raw_ostream &OS) {
528527
IncludeStrongLifetimeRAII Strong(Policy);
529-
SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
530528
printBefore(T->getElementType(), OS);
531529
}
532530

@@ -539,7 +537,6 @@ void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T,
539537
void TypePrinter::printVariableArrayBefore(const VariableArrayType *T,
540538
raw_ostream &OS) {
541539
IncludeStrongLifetimeRAII Strong(Policy);
542-
SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
543540
printBefore(T->getElementType(), OS);
544541
}
545542

@@ -586,7 +583,6 @@ void TypePrinter::printDependentSizedArrayBefore(
586583
const DependentSizedArrayType *T,
587584
raw_ostream &OS) {
588585
IncludeStrongLifetimeRAII Strong(Policy);
589-
SaveAndRestore<bool> NonEmptyPH(HasEmptyPlaceHolder, false);
590586
printBefore(T->getElementType(), OS);
591587
}
592588

clang/test/ARCMT/cxx-checking.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
struct FlexibleArrayMember0 {
8282
int length;
83-
id array[]; // expected-error{{flexible array member 'array' of type '__strong id []' with non-trivial destruction}}
83+
id array[]; // expected-error{{flexible array member 'array' of type '__strong id[]' with non-trivial destruction}}
8484
};
8585

8686
struct FlexibleArrayMember1 {

clang/test/AST/ast-dump-APValue-arithmetic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ void Test() {
3636
// CHECK-NEXT: | |-value: ComplexFloat 3.141500e+00 + 4.200000e+01i
3737

3838
constexpr _Complex int ArrayOfComplexInt[10] = {ComplexInt, ComplexInt, ComplexInt, ComplexInt};
39-
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexInt 'const _Complex int [10]' constexpr cinit
39+
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexInt 'const _Complex int[10]' constexpr cinit
4040
// CHECK-NEXT: | |-value: Array size=10
4141
// CHECK-NEXT: | | |-elements: ComplexInt 42 + 24i, ComplexInt 42 + 24i, ComplexInt 42 + 24i, ComplexInt 42 + 24i
4242
// CHECK-NEXT: | | `-filler: 6 x ComplexInt 0 + 0i
4343

4444
constexpr _Complex float ArrayOfComplexFloat[10] = {ComplexFloat, ComplexFloat, ComplexInt, ComplexInt};
45-
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexFloat 'const _Complex float [10]' constexpr cinit
45+
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} ArrayOfComplexFloat 'const _Complex float[10]' constexpr cinit
4646
// CHECK-NEXT: |-value: Array size=10
4747
// 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
4848
// CHECK-NEXT: | `-filler: 6 x ComplexFloat 0.000000e+00 + 0.000000e+00i

clang/test/AST/ast-dump-APValue-array.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void Test() {
4343
constexpr float arr_f[3][5] = {
4444
{1, 2, 3, 4, 5},
4545
};
46-
// CHECK: | `-VarDecl {{.*}} <line:{{.*}}, line:{{.*}}> line:{{.*}} arr_f 'const float [3][5]' constexpr cinit
46+
// CHECK: | `-VarDecl {{.*}} <line:{{.*}}, line:{{.*}}> line:{{.*}} arr_f 'const float[3][5]' constexpr cinit
4747
// CHECK-NEXT: | |-value: Array size=3
4848
// CHECK-NEXT: | | |-element: Array size=5
4949
// CHECK-NEXT: | | | |-elements: Float 1.000000e+00, Float 2.000000e+00, Float 3.000000e+00, Float 4.000000e+00
@@ -52,7 +52,7 @@ void Test() {
5252
// CHECK-NEXT: | | `-filler: 5 x Float 0.000000e+00
5353

5454
constexpr S0 arr_s0[2] = {{1, 2}, {3, 4}};
55-
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s0 'const S0 [2]' constexpr cinit
55+
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s0 'const S0[2]' constexpr cinit
5656
// CHECK-NEXT: | |-value: Array size=2
5757
// CHECK-NEXT: | | |-element: Struct
5858
// CHECK-NEXT: | | | `-field: Array size=2
@@ -62,12 +62,12 @@ void Test() {
6262
// CHECK-NEXT: | | `-elements: Int 3, Int 4
6363

6464
constexpr U0 arr_u0[2] = {{.i = 42}, {.f = 3.1415f}};
65-
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_u0 'const U0 [2]' constexpr cinit
65+
// CHECK: | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_u0 'const U0[2]' constexpr cinit
6666
// CHECK-NEXT: | |-value: Array size=2
6767
// CHECK-NEXT: | | `-elements: Union .i Int 42, Union .f Float 3.141500e+00
6868

6969
constexpr S1 arr_s1[2] = {};
70-
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s1 'const S1 [2]' constexpr cinit
70+
// CHECK: `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} arr_s1 'const S1[2]' constexpr cinit
7171
// CHECK-NEXT: |-value: Array size=2
7272
// CHECK-NEXT: | |-element: Struct
7373
// CHECK-NEXT: | | |-field: Struct

clang/test/AST/ast-dump-array.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void testArrayInitExpr()
1313
int a[10];
1414
auto l = [a]{
1515
};
16-
// CHECK: |-ArrayInitLoopExpr 0x{{[^ ]*}} <col:15> 'int [10]'
16+
// CHECK: |-ArrayInitLoopExpr 0x{{[^ ]*}} <col:15> 'int[10]'
1717
// CHECK: | `-ArrayInitIndexExpr 0x{{[^ ]*}} <<invalid sloc>> 'unsigned long'
1818
}
1919

@@ -22,7 +22,7 @@ class array {
2222
T data[Size];
2323

2424
using array_T_size = T[Size];
25-
// CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'T [Size]' dependent <col:25, col:30>
25+
// CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'T[Size]' dependent <col:25, col:30>
2626
using const_array_T_size = const T[Size];
27-
// CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'const T [Size]' dependent <col:37, col:42>
27+
// CHECK: `-DependentSizedArrayType 0x{{[^ ]*}} 'const T[Size]' dependent <col:37, col:42>
2828
};

clang/test/AST/ast-dump-color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Invalid {
3232
//CHECK: {{^}}[[GREEN:.\[0;1;32m]]TranslationUnitDecl[[RESET:.\[0m]][[Yellow:.\[0;33m]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]<invalid sloc>[[RESET]]> [[Yellow]]<invalid sloc>[[RESET]]{{$}}
3333
//CHECK: {{^}}[[Blue:.\[0;34m]]|-[[RESET]][[GREEN]]TypedefDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]<invalid sloc>[[RESET]]> [[Yellow]]<invalid sloc>[[RESET]] implicit[[CYAN:.\[0;1;36m]] __int128_t[[RESET]] [[Green:.\[0;32m]]'__int128'[[RESET]]{{$}}
3434
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]TypedefDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]<invalid sloc>[[RESET]]> [[Yellow]]<invalid sloc>[[RESET]] implicit[[CYAN]] __uint128_t[[RESET]] [[Green]]'unsigned __int128'[[RESET]]{{$}}
35-
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]TypedefDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]<invalid sloc>[[RESET]]> [[Yellow]]<invalid sloc>[[RESET]] implicit[[CYAN]] __builtin_va_list[[RESET]] [[Green]]'__va_list_tag [1]'[[RESET]]{{$}}
35+
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]TypedefDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]<invalid sloc>[[RESET]]> [[Yellow]]<invalid sloc>[[RESET]] implicit[[CYAN]] __builtin_va_list[[RESET]] [[Green]]'__va_list_tag[1]'[[RESET]]{{$}}
3636
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]VarDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]{{.*}}ast-dump-color.cpp:6:1[[RESET]], [[Yellow]]col:5[[RESET]]> [[Yellow]]col:5[[RESET]][[CYAN]] Test[[RESET]] [[Green]]'int'[[RESET]]
3737
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[BLUE:.\[0;1;34m]]UnusedAttr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:25[[RESET]]> unused{{$}}
3838
//CHECK: {{^}}[[Blue]]| `-[[RESET]][[Blue]]FullComment[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:4:4[[RESET]], [[Yellow]]line:5:8[[RESET]]>{{$}}

0 commit comments

Comments
 (0)