[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
This revision was automatically updated to reflect the committed changes. Closed by commit rL332314: [AST] Fix printing tag decl groups in decl contexts (authored by jdenny, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D45465?vs=146709=146727#toc Repository: rL LLVM https://reviews.llvm.org/D45465 Files: cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/test/Misc/ast-print-enum-decl.c cfe/trunk/test/Misc/ast-print-record-decl.c cfe/trunk/test/Sema/ast-print.c cfe/trunk/test/SemaCXX/ast-print.cpp Index: cfe/trunk/test/Misc/ast-print-enum-decl.c === --- cfe/trunk/test/Misc/ast-print-enum-decl.c +++ cfe/trunk/test/Misc/ast-print-enum-decl.c @@ -83,3 +83,23 @@ // PRINT-NEXT: enum T *p4; enum T *p4; } + +// Check that tag decl groups stay together in decl contexts. + +// PRINT-LABEL: enum DeclGroupAtFileScope { +// PRINT-NEXT:DeclGroupAtFileScope0 +// PRINT-NEXT: } *DeclGroupAtFileScopePtr; +enum DeclGroupAtFileScope { DeclGroupAtFileScope0 } *DeclGroupAtFileScopePtr; + +// PRINT-LABEL: struct DeclGroupInMemberList +struct DeclGroupInMemberList { + // PRINT-NEXT: enum T1 { + // PRINT-NEXT:T10 + // PRINT-NEXT: } *p0; + enum T1 { T10 } *p0; + // PRINT-NEXT: enum T2 { + // PRINT-NEXT:T20 + // PRINT-NEXT: } *p1, *p2; + enum T2 { T20 } *p1, *p2; + // PRINT-NEXT: }; +}; Index: cfe/trunk/test/Misc/ast-print-record-decl.c === --- cfe/trunk/test/Misc/ast-print-record-decl.c +++ cfe/trunk/test/Misc/ast-print-record-decl.c @@ -7,8 +7,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -19,7 +19,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \ +// RUN: -DBASES= %s // Repeat for union: // @@ -30,8 +31,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -42,7 +43,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \ +// RUN: -DBASES= %s // Repeat for C++ (BASES helps ensure we're printing as C++ not as C): // @@ -54,7 +56,7 @@ // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \ // RUN: > %t.cpp -// RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s --input-file %t.cpp // // Now check compiling and printing of the printed file. @@ -66,7 +68,7 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.cpp \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s // END. @@ -155,25 +157,33 @@ // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}} KW __attribute__((deprecated(""))) T *p0; - // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] { - // PRINT-NEXT: int i; - // PRINT-NEXT: [[KW]] T *p2; - // PRINT-NEXT: } *p1; - KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}} + // PRINT-NEXT: [[KW]] __attribute__((aligned(64))) T[[BASES]] { + // PRINT-NEXT:int i; + // PRINT-NEXT:[[KW]] T *p2; + // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3; + // PRINT-NEXT:[[KW]] T *p4; + // PRINT-NEXT: } *p1; + KW __attribute__((aligned(64))) T BASES { // expected-warning {{'T' is deprecated}} int i; KW T *p2; +// FIXME: For C++, T at p3 loses aligned and deprecated, perhaps because +// that RecordDecl isn't in the same redecl list. Perhaps the redecl lists +// are split here but not in C due to the different scoping rules in C++ +
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
jdenny added a comment. In https://reviews.llvm.org/D45465#1098710, @rsmith wrote: > Looks good, thanks. Thanks. > It strikes me that this will still lead to inconsistencies. For example, I > expect this: > > struct A { struct B *a, *b; struct B *c, *d; }; > > > ... to print as: > > struct A { > struct B *a, *b; > struct B *c; > struct B *d; > }; > > > ... where the first two are joined because their type owns a declaration of > `struct B`, and the second two are not joined because their type does not own > a declaration (it just has a reference to the already-existing declaration of > `struct B`). One (somewhat hacky) way to address this would be to compare the > starting source locations of a sequence of `DeclaratorDecl`s and group them > if it's the same. While it would be nice to fix that, I'm not as concerned because, AFAICT, that doesn't ever change the semantics. https://reviews.llvm.org/D45465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
rsmith accepted this revision. rsmith added a comment. This revision is now accepted and ready to land. Looks good, thanks. It strikes me that this will still lead to inconsistencies. For example, I expect this: struct A { struct B *a, *b; struct B *c, *d; }; ... to print as: struct A { struct B *a, *b; struct B *c; struct B *d; }; ... where the first two are joined because their type owns a declaration of `struct B`, and the second two are not joined because their type does not own a declaration (it just has a reference to the already-existing declaration of `struct B`). One (somewhat hacky) way to address this would be to compare the starting source locations of a sequence of `DeclaratorDecl`s and group them if it's the same. https://reviews.llvm.org/D45465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
jdenny updated this revision to Diff 146709. jdenny marked 2 inline comments as done. jdenny added a comment. Made the suggested change. Thanks! https://reviews.llvm.org/D45465 Files: lib/AST/DeclPrinter.cpp test/Misc/ast-print-enum-decl.c test/Misc/ast-print-record-decl.c test/Sema/ast-print.c test/SemaCXX/ast-print.cpp Index: test/SemaCXX/ast-print.cpp === --- test/SemaCXX/ast-print.cpp +++ test/SemaCXX/ast-print.cpp @@ -214,10 +214,13 @@ struct [[gnu::visibility("hidden")]] S; } -// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{}; +// CHECK: struct CXXFunctionalCastExprPrint { +// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{}; struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{}; -// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{}; +// CHECK: struct CXXTemporaryObjectExprPrint { +// CHECK-NEXT: CXXTemporaryObjectExprPrint(); +// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{}; struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{}; namespace PR24872 { Index: test/Sema/ast-print.c === --- test/Sema/ast-print.c +++ test/Sema/ast-print.c @@ -83,8 +83,7 @@ EnumWithAttributesFoo __attribute__((deprecated)), // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50 EnumWithAttributesBar __attribute__((unavailable)) = 50 - // CHECK-NEXT: }; - // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr; + // CHECK-NEXT: } *EnumWithAttributesPtr; } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}} // FIXME: If enum is forward-declared at file scope, attributes are lost. Index: test/Misc/ast-print-record-decl.c === --- test/Misc/ast-print-record-decl.c +++ test/Misc/ast-print-record-decl.c @@ -7,8 +7,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -19,7 +19,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \ +// RUN: -DBASES= %s // Repeat for union: // @@ -30,8 +31,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -42,7 +43,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \ +// RUN: -DBASES= %s // Repeat for C++ (BASES helps ensure we're printing as C++ not as C): // @@ -54,7 +56,7 @@ // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \ // RUN: > %t.cpp -// RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s --input-file %t.cpp // // Now check compiling and printing of the printed file. @@ -66,7 +68,7 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.cpp \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s // END. @@ -155,25 +157,33 @@ // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}} KW __attribute__((deprecated(""))) T *p0; - // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] { - // PRINT-NEXT: int i; - // PRINT-NEXT: [[KW]] T *p2; - // PRINT-NEXT: } *p1; - KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}} + // PRINT-NEXT: [[KW]] __attribute__((aligned(64))) T[[BASES]] { + // PRINT-NEXT:int i; + // PRINT-NEXT:[[KW]] T *p2; + // PRINT-NEXT:[[KW]]
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
rsmith added inline comments. Comment at: lib/AST/DeclPrinter.cpp:393-397 if (!BaseType.isNull() && isa(BaseType)) BaseType = cast(BaseType)->getNamedType(); if (!BaseType.isNull() && isa(BaseType) && - cast(BaseType)->getDecl() == Decls[0]) { + cast(BaseType) == + cast(Decls[0])->getTypeForDecl()) { I would think the right thing to check here is that the `ElaboratedType`'s `OwnedTagDecl` is `Decls[0]`. Currently, you also allow cases where it's merely a redeclaration of that same `TagDecl`, which will combine together declarations too often... Comment at: test/Misc/ast-print-record-decl.c:161-171 + // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3, *p4; + // PRINT-NEXT: } *p1; + KW __attribute__((aligned(64))) T BASES { // expected-warning {{'T' is deprecated}} int i; KW T *p2; +// FIXME: For C++, T at p3 loses aligned and deprecated, perhaps because +// that RecordDecl isn't in the same redecl list. Perhaps the redecl lists ... such as here, for example. Because the two `KW T` declarations redeclare the same `TagDecl`, they will get merged by `-ast-print`. https://reviews.llvm.org/D45465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
jdenny updated this revision to Diff 146668. jdenny added a comment. Rebased. Ping. https://reviews.llvm.org/D45465 Files: lib/AST/DeclPrinter.cpp test/Misc/ast-print-enum-decl.c test/Misc/ast-print-record-decl.c test/Sema/ast-print.c test/SemaCXX/ast-print.cpp Index: test/SemaCXX/ast-print.cpp === --- test/SemaCXX/ast-print.cpp +++ test/SemaCXX/ast-print.cpp @@ -214,10 +214,13 @@ struct [[gnu::visibility("hidden")]] S; } -// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{}; +// CHECK: struct CXXFunctionalCastExprPrint { +// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{}; struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{}; -// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{}; +// CHECK: struct CXXTemporaryObjectExprPrint { +// CHECK-NEXT: CXXTemporaryObjectExprPrint(); +// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{}; struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{}; namespace PR24872 { Index: test/Sema/ast-print.c === --- test/Sema/ast-print.c +++ test/Sema/ast-print.c @@ -83,8 +83,7 @@ EnumWithAttributesFoo __attribute__((deprecated)), // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50 EnumWithAttributesBar __attribute__((unavailable)) = 50 - // CHECK-NEXT: }; - // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr; + // CHECK-NEXT: } *EnumWithAttributesPtr; } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}} // FIXME: If enum is forward-declared at file scope, attributes are lost. Index: test/Misc/ast-print-record-decl.c === --- test/Misc/ast-print-record-decl.c +++ test/Misc/ast-print-record-decl.c @@ -6,8 +6,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -18,7 +18,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \ +// RUN: -DBASES= %s // Repeat for union: // @@ -28,8 +29,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -40,7 +41,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \ +// RUN: -DBASES= %s // Repeat for C++ (BASES helps ensure we're printing as C++ not as C): // @@ -52,7 +54,7 @@ // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \ // RUN: > %t.cpp -// RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s --input-file %t.cpp // // Now check compiling and printing of the printed file. @@ -64,7 +66,7 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.cpp \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s // END. @@ -153,25 +155,32 @@ // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}} KW __attribute__((deprecated(""))) T *p0; - // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] { - // PRINT-NEXT: int i; - // PRINT-NEXT: [[KW]] T *p2; - // PRINT-NEXT: } *p1; - KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}} + // PRINT-NEXT: [[KW]] __attribute__((aligned(64))) T[[BASES]] { + // PRINT-NEXT:int i; + // PRINT-NEXT:[[KW]] T *p2; + // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3, *p4; + // PRINT-NEXT: } *p1; + KW
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
jdenny updated this revision to Diff 142687. jdenny added a comment. Rebased onto a more recent master. https://reviews.llvm.org/D45465 Files: lib/AST/DeclPrinter.cpp test/Misc/ast-print-enum-decl.c test/Misc/ast-print-record-decl.c test/Sema/ast-print.c test/SemaCXX/ast-print.cpp Index: test/SemaCXX/ast-print.cpp === --- test/SemaCXX/ast-print.cpp +++ test/SemaCXX/ast-print.cpp @@ -214,10 +214,13 @@ struct [[gnu::visibility("hidden")]] S; } -// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{}; +// CHECK: struct CXXFunctionalCastExprPrint { +// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{}; struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{}; -// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{}; +// CHECK: struct CXXTemporaryObjectExprPrint { +// CHECK-NEXT: CXXTemporaryObjectExprPrint(); +// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{}; struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{}; namespace PR24872 { Index: test/Sema/ast-print.c === --- test/Sema/ast-print.c +++ test/Sema/ast-print.c @@ -83,8 +83,7 @@ EnumWithAttributesFoo __attribute__((deprecated)), // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50 EnumWithAttributesBar __attribute__((unavailable)) = 50 - // CHECK-NEXT: }; - // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr; + // CHECK-NEXT: } *EnumWithAttributesPtr; } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}} // FIXME: If enum is forward-declared at file scope, attributes are lost. Index: test/Misc/ast-print-record-decl.c === --- test/Misc/ast-print-record-decl.c +++ test/Misc/ast-print-record-decl.c @@ -6,8 +6,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -18,7 +18,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \ +// RUN: -DBASES= %s // Repeat for union: // @@ -28,8 +29,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -40,7 +41,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \ +// RUN: -DBASES= %s // Repeat for C++ (BASES helps ensure we're printing as C++ not as C): // @@ -52,7 +54,7 @@ // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \ // RUN: > %t.cpp -// RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s --input-file %t.cpp // // Now check compiling and printing of the printed file. @@ -64,7 +66,7 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.cpp \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s // END. @@ -161,29 +163,41 @@ // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}} KW __attribute__((deprecated(""))) T *p0; - // PRINT-NEXT: [[KW]] - // PRINT-DAG: __attribute__((deprecated(""))) - // PRINT-DAG: __attribute__((aligned(16))) - // PRINT-NOT: __attribute__ - // PRINT-SAME: T[[BASES]] { - // PRINT-NEXT: int i; - // PRINT-NEXT: [[KW]] T *p2; - // PRINT-NEXT: } *p1; - KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}} + // PRINT-NEXT: [[KW]] + // PRINT-DAG: __attribute__((deprecated(""))) + // PRINT-DAG:
[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts
jdenny created this revision. jdenny added reviewers: rsmith, hfinkel. jdenny added a dependency: D45463: [AST] Print correct tag decl for tag specifier. For example, given: struct T1 { struct T2 *p0; }; -ast-print produced: struct T1 { struct T2; struct T2 *p0; }; Compiling that produces a warning that the first struct T2 declaration does not declare anything. Details: A tag decl group is one or more decls that share a type specifier that is a tag decl (that is, a struct/union/class/enum decl). Within functions, the parser builds such a tag decl group as part of a DeclStmt. However, in decl contexts, such as file scope or a member list, the parser does not group together the members of a tag decl group. Previously, detection of tag decl groups during printing was implemented but only if the tag decl was unnamed. Otherwise, as in the above example, the members of the group did not print together and so sometimes introduced warnings. This patch extends detection of tag decl groups in decl contexts to any tag decl that is recorded in the AST as not free-standing. https://reviews.llvm.org/D45465 Files: lib/AST/DeclPrinter.cpp test/Misc/ast-print-enum-decl.c test/Misc/ast-print-record-decl.c test/Sema/ast-print.c test/SemaCXX/ast-print.cpp Index: test/SemaCXX/ast-print.cpp === --- test/SemaCXX/ast-print.cpp +++ test/SemaCXX/ast-print.cpp @@ -214,10 +214,13 @@ struct [[gnu::visibility("hidden")]] S; } -// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{}; +// CHECK: struct CXXFunctionalCastExprPrint { +// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{}; struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{}; -// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{}; +// CHECK: struct CXXTemporaryObjectExprPrint { +// CHECK-NEXT: CXXTemporaryObjectExprPrint(); +// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{}; struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{}; namespace PR24872 { Index: test/Sema/ast-print.c === --- test/Sema/ast-print.c +++ test/Sema/ast-print.c @@ -83,8 +83,7 @@ EnumWithAttributesFoo __attribute__((deprecated)), // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50 EnumWithAttributesBar __attribute__((unavailable)) = 50 - // CHECK-NEXT: }; - // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr; + // CHECK-NEXT: } *EnumWithAttributesPtr; } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}} // FIXME: If enum is forward-declared at file scope, attributes are lost. Index: test/Misc/ast-print-record-decl.c === --- test/Misc/ast-print-record-decl.c +++ test/Misc/ast-print-record-decl.c @@ -6,8 +6,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -18,7 +18,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \ +// RUN: -DBASES= %s // Repeat for union: // @@ -28,8 +29,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c -// RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \ -// RUN: --input-file %t.c +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \ +// RUN: %s --input-file %t.c // // Now check compiling and printing of the printed file. // @@ -40,7 +41,8 @@ // RUN: | FileCheck --check-prefixes=CHECK,LLVM %s // // RUN: %clang_cc1 -verify -ast-print %t.c \ -// RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s +// RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \ +// RUN: -DBASES= %s // Repeat for C++ (BASES helps ensure we're printing as C++ not as C): // @@ -52,7 +54,7 @@ // // RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \ // RUN: > %t.cpp -// RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \ +// RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \ // RUN: -DBASES=' : B' %s