llvm-project/clang/lib/AST
Joel E. Denny 7509a2f5cc [AST] Print correct tag decl for tag specifier
For example, given:

  void fn() {
    struct T *p0;
    struct T { int i; } *p1;
  }

-ast-print produced:

  void fn() {
    struct T { int i; } *p0;
    struct T { int i; } *p1;
  }

Compiling that fails with a redefinition error.

Given:

  void fn() {
    struct T *p0;
    struct __attribute__((deprecated)) T *p1;
  }

-ast-print dropped the attribute.

Details:

For a tag specifier (that is, struct/union/class/enum used as a type
specifier in a declaration) that was also a tag declaration (that is,
first occurrence of the tag) or tag redeclaration (that is, later
occurrence that specifies attributes or a member list), clang printed
the tag specifier as either (1) the full tag definition if one
existed, or (2) the first tag declaration otherwise.  Redefinition
errors were sometimes introduced, as in the first example above.  Even
when that was impossible because no member list was ever specified,
attributes were sometimes lost, thus changing semantics and
diagnostics, as in the second example above.

This patch fixes a major culprit for these problems.  It does so by
creating an ElaboratedType with a new OwnedDecl member wherever an
occurrence of a tag type is a (re)declaration of that tag type.
PrintingPolicy's IncludeTagDefinition used to trigger printing of the
member list, attributes, etc. for a tag specifier by using a tag
(re)declaration selected as described above.  Now, it triggers the
same thing except it uses the tag (re)declaration stored in the
OwnedDecl.  Of course, other tooling can now make use of the new
OwnedDecl as well.

Also, to be more faithful to the original source, this patch
suppresses printing of attributes inherited from previous
declarations.

Reviewed by: rsmith, aaron.ballman

Differential Revision: https://reviews.llvm.org/D45463

llvm-svn: 332281
2018-05-14 19:36:45 +00:00
..
APValue.cpp [ExprConstant] Use an AST node and a version number as a key to create 2018-04-10 05:15:01 +00:00
ASTConsumer.cpp Move LocInfoType from Sema to AST. 2016-02-01 17:42:01 +00:00
ASTContext.cpp [AST] Print correct tag decl for tag specifier 2018-05-14 19:36:45 +00:00
ASTDiagnostic.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
ASTDumper.cpp Revert rC330794 and some dependent tiny bug fixes 2018-04-26 00:42:40 +00:00
ASTImporter.cpp [AST] Print correct tag decl for tag specifier 2018-05-14 19:36:45 +00:00
ASTStructuralEquivalence.cpp Track the result of evaluating a computed noexcept specification on the 2018-05-03 03:58:32 +00:00
ASTTypeTraits.cpp Teach clang-query to dump types. I couldn't find any existing tests for clang-query's dumping functionality. =( 2016-11-02 23:57:18 +00:00
AttrImpl.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CMakeLists.txt [C++2a] Implement operator<=> CodeGen and ExprConstant 2018-05-07 21:07:10 +00:00
CXXABI.h Fix __has_unique_object_representations implementation 2017-11-30 16:37:02 +00:00
CXXInheritance.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
Comment.cpp [AST] Look through attribute type locs when searching for function type 2017-04-26 12:46:27 +00:00
CommentBriefParser.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
CommentCommandTraits.cpp
CommentLexer.cpp Fix 'unknown documentation command' warning ranges 2016-10-25 10:06:11 +00:00
CommentParser.cpp [cleanup] Remove excessive padding from TextTokenRetokenizer::Position 2016-09-20 18:32:48 +00:00
CommentSema.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
ComparisonCategories.cpp [C++2a] Implement operator<=>: Address bugs and post-commit review comments after r331677. 2018-05-08 00:52:19 +00:00
DataCollection.cpp [analyzer] Make StmtDataCollector customizable 2017-08-23 16:28:26 +00:00
Decl.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
DeclBase.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
DeclCXX.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
DeclFriend.cpp [AST] Fix some Clang-tidy modernize-use-auto warnings; other minor fixes (NFC). 2018-04-03 00:11:50 +00:00
DeclGroup.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-11-10 00:59:22 +00:00
DeclObjC.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
DeclOpenMP.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
DeclPrinter.cpp [AST] Print correct tag decl for tag specifier 2018-05-14 19:36:45 +00:00
DeclTemplate.cpp Revert rC330794 and some dependent tiny bug fixes 2018-04-26 00:42:40 +00:00
DeclarationName.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-11-21 23:26:08 +00:00
Expr.cpp Added atomic_fetch_min, max, umin, umax intrinsics to clang. 2018-05-13 07:45:58 +00:00
ExprCXX.cpp Track the result of evaluating a computed noexcept specification on the 2018-05-03 03:58:32 +00:00
ExprClassification.cpp [AST] Fix some Clang-tidy modernize-use-auto and Include What You Use warnings; other minor fixes (NFC). 2018-04-10 22:54:42 +00:00
ExprConstant.cpp Allow dllimport non-type template arguments in C++17 2018-05-10 18:57:35 +00:00
ExprObjC.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-11-30 22:33:48 +00:00
ExternalASTMerger.cpp [ASTImporter] avoid warnings: unused var, switch covered 2018-01-26 12:06:44 +00:00
ExternalASTSource.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-11-08 00:39:18 +00:00
InheritViz.cpp
ItaniumCXXABI.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
ItaniumMangle.cpp Track the result of evaluating a computed noexcept specification on the 2018-05-03 03:58:32 +00:00
Linkage.h Give external linkage and mangling to lambdas inside inline variables and variable templates. 2017-09-22 04:25:05 +00:00
Mangle.cpp [modules ts] Ensure that module linkage variables are always emitted and always have their name mangled. 2017-09-07 00:55:55 +00:00
MicrosoftCXXABI.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
MicrosoftMangle.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
NSAPI.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
NestedNameSpecifier.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
ODRHash.cpp [ODRHash] Hash template arguments of methods. 2018-04-25 00:31:15 +00:00
OpenMPClause.cpp [OPENMP] Code cleanup and code improvements. 2018-04-18 15:57:46 +00:00
ParentMap.cpp [analyzer] Correctly model iteration through "nil" objects 2018-03-08 02:53:39 +00:00
QualTypeNames.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
RawCommentList.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
RecordLayout.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-11-10 00:59:22 +00:00
RecordLayoutBuilder.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
SelectorLocationsKind.cpp
Stmt.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
StmtCXX.cpp [coroutines] Add serialization/deserialization of coroutines 2017-07-25 18:01:49 +00:00
StmtIterator.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-11-21 23:26:08 +00:00
StmtObjC.cpp Retire llvm::alignOf in favor of C++11 alignof. 2016-10-20 14:27:22 +00:00
StmtOpenMP.cpp [OPENMP] Add support for cancel constructs in `target teams distribute 2017-11-22 21:12:03 +00:00
StmtPrinter.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
StmtProfile.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
StmtViz.cpp
TemplateBase.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
TemplateName.cpp Fix a couple of cases where we would fail to correctly parse deduced class template specialization types. 2018-02-28 03:02:23 +00:00
Type.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
TypeLoc.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00
TypePrinter.cpp [AST] Print correct tag decl for tag specifier 2018-05-14 19:36:45 +00:00
VTTBuilder.cpp [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-12-01 22:04:49 +00:00
VTableBuilder.cpp Remove \brief commands from doxygen comments. 2018-05-09 01:00:01 +00:00