summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/DeclPrinter.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Concepts] Type ConstraintsSaar Raz2020-01-151-1/+3
| | | | | | | Add support for type-constraints in template type parameters. Also add support for template type parameters as pack expansions (where the type constraint can now contain an unexpanded parameter pack). Differential Revision: https://reviews.llvm.org/D44352
* [Concepts] Function trailing requires clausesSaar Raz2020-01-091-0/+5
| | | | | | Function trailing requires clauses now parsed, supported in overload resolution and when calling, referencing and taking the address of functions or function templates. Differential Revision: https://reviews.llvm.org/D43357
* [DeclCXX] Remove unknown external linkage specificationsEhud Katz2019-11-211-11/+4
| | | | | | | | | | | | | | | | Partial revert of r372681 "Support for DWARF-5 C++ language tags". The change introduced new external linkage languages ("C++11" and "C++14") which not supported in C++. It also changed the definition of the existing enum to use the DWARF constants. The problem is that "LinkageSpecDeclBits.Language" (the field that reserves this enum) is actually defined as 3 bits length (bitfield), which cannot contain the new DWARF constants. Defining the enum as integer literals is more appropriate for maintaining valid values. Differential Revision: https://reviews.llvm.org/D69935
* Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))Pierre Habouzit2019-11-181-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | __attribute__((objc_direct)) is an attribute on methods declaration, and __attribute__((objc_direct_members)) on implementation, categories or extensions. A `direct` property specifier is added (@property(direct) type name) These attributes / specifiers cause the method to have no associated Objective-C metadata (for the property or the method itself), and the calling convention to be a direct C function call. The symbol for the method has enforced hidden visibility and such direct calls are hence unreachable cross image. An explicit C function must be made if so desired to wrap them. The implicit `self` and `_cmd` arguments are preserved, however to maintain compatibility with the usual `objc_msgSend` semantics, 3 fundamental precautions are taken: 1) for instance methods, `self` is nil-checked. On arm64 backends this typically adds a single instruction (cbz x0, <closest-ret>) to the codegen, for the vast majority of the cases when the return type is a scalar. 2) for class methods, because the class may not be realized/initialized yet, a call to `[self self]` is emitted. When the proper deployment target is used, this is optimized to `objc_opt_self(self)`. However, long term we might want to emit something better that the optimizer can reason about. When inlining kicks in, these calls aren't optimized away as the optimizer has no idea that a single call is really necessary. 3) the calling convention for the `_cmd` argument is changed: the caller leaves the second argument to the call undefined, and the selector is loaded inside the body when it's referenced only. As far as error reporting goes, the compiler refuses: - making any overloads direct, - making an overload of a direct method, - implementations marked as direct when the declaration in the interface isn't (the other way around is allowed, as the direct attribute is inherited from the declaration), - marking methods required for protocol conformance as direct, - messaging an unqualified `id` with a direct method, - forming any @selector() expression with only direct selectors. As warnings: - any inconsistency of direct-related calling convention when @selector() or messaging is used, - forming any @selector() expression with a possibly direct selector. Lastly an `objc_direct_members` attribute is added that can decorate `@implementation` blocks and causes methods only declared there (and in no `@interface`) to be automatically direct. When decorating an `@interface` then all methods and properties declared in this block are marked direct. Radar-ID: rdar://problem/2684889 Differential Revision: https://reviews.llvm.org/D69991 Reviewed-By: John McCall
* [AST] Let DeclarationNameInfo printing use PrintingPolicy, and fix ↵Sam McCall2019-11-151-2/+2
| | | | const-correctness
* [AST] Use written names instead of `type-param-0-0` in more cases when ↵Sam McCall2019-11-151-38/+30
| | | | | | | | | | | | | | | | | | | printing types and decls. Summary: This doesn't cover decls in diagnostics, which use NamedDecl::getNameForDiagnostic(). (That should also be fixed later I think). This covers some cases of https://github.com/clangd/clangd/issues/76 (hover, but not outline or sighelp) Reviewers: hokein Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70236
* Support for DWARF-5 C++ language tags.Adrian Prantl2019-09-241-4/+11
| | | | | | | | | | | | This patch provides support for DW_LANG_C_plus_plus_11, DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend. Patch by Sourabh Singh Tomar! Differential Revision: https://reviews.llvm.org/D67613 Reapplies r372663 after adapting a failing test in the LLDB testsuite. llvm-svn: 372681
* Revert "Support for DWARF-5 C++ language tags."Jonas Devlieghere2019-09-231-11/+4
| | | | | | This reverts commit bf9c8ffb54943c6d77398adbedddf05ef9724007. llvm-svn: 372672
* Support for DWARF-5 C++ language tags.Adrian Prantl2019-09-231-4/+11
| | | | | | | | | | This patch provides support for DW_LANG_C_plus_plus_11, DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend. Patch by Sourabh Singh Tomar! Differential Revision: https://reviews.llvm.org/D67613 llvm-svn: 372663
* [Concepts] Concept definitions (D40381)Saar Raz2019-07-101-2/+7
| | | | | | | First in a series of patches to land C++2a Concepts support. This patch adds AST and parsing support for concept-declarations. llvm-svn: 365699
* Use getOperatorSpelling to get the spelling of an overloaded operatorRichard Smith2019-06-141-7/+1
| | | | | | rather than duplicating operator name tables in multiple places. llvm-svn: 363446
* [C++20] add Basic consteval specifierGauthier Harnisch2019-06-141-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: this revision adds Lexing, Parsing and Basic Semantic for the consteval specifier as specified by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1073r3.html with this patch, the consteval specifier is treated as constexpr but can only be applied to function declaration. Changes: - add the consteval keyword. - add parsing of consteval specifier for normal declarations and lambdas expressions. - add the whether a declaration is constexpr is now represented by and enum everywhere except for variable because they can't be consteval. - adapt diagnostic about constexpr to print constexpr or consteval depending on the case. - add tests for basic semantic. Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: eraman, efriedma, rnkovacs, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61790 llvm-svn: 363362
* [c++20] Add support for explicit(bool), as described in P0892R2.Richard Smith2019-05-091-4/+18
| | | | | | | | Patch by Tyker! Differential Revision: https://reviews.llvm.org/D60934 llvm-svn: 360311
* Revert r359949 "[clang] adding explicit(bool) from c++2a"Hans Wennborg2019-05-061-18/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This caused Clang to start erroring on the following: struct S {   template <typename = int> explicit S(); }; struct T : S {}; struct U : T {   U(); }; U::U() {} $ clang -c /tmp/x.cc /tmp/x.cc:10:4: error: call to implicitly-deleted default constructor of 'T' U::U() {}    ^ /tmp/x.cc:5:12: note: default constructor of 'T' is implicitly deleted because base class 'S' has no default constructor struct T : S {};            ^ 1 error generated. See discussion on the cfe-commits email thread. This also reverts the follow-ups r359966 and r359968. > this patch adds support for the explicit bool specifier. > > Changes: > - The parsing for the explicit(bool) specifier was added in ParseDecl.cpp. > - The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class. > - Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted. > - Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration. > - The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected. > - Test for Semantic and Serialization were added. > > This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback. > Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky. > > Patch by Tyker > > Differential Revision: https://reviews.llvm.org/D60934 llvm-svn: 360024
* [c++20] Implement P0428R2 - Familiar template syntax for generic lambdasHamza Sood2019-05-041-10/+36
| | | | | | Differential Revision: https://reviews.llvm.org/D36527 llvm-svn: 359967
* [clang] adding explicit(bool) from c++2aNicolas Lesser2019-05-041-4/+18
| | | | | | | | | | | | | | | | | | | | | this patch adds support for the explicit bool specifier. Changes: - The parsing for the explicit(bool) specifier was added in ParseDecl.cpp. - The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class. - Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted. - Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration. - The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected. - Test for Semantic and Serialization were added. This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback. Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky. Patch by Tyker Differential Revision: https://reviews.llvm.org/D60934 llvm-svn: 359949
* Clean up ObjCPropertyDecl printingDavid Goldman2019-04-081-36/+53
| | | | | | | | | | | | | | | Summary: - `@property(attr, attr2)` instead of `@property ( attr,attr2 )`. - Change priority of attributes (see code/comments inline). - Support for printing weak and unsafe_unretained attributes. Subscribers: arphaman, jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57965 llvm-svn: 357937
* [OPENMP 5.0]Initial support for 'allocator' clause.Alexey Bataev2019-03-121-0/+6
| | | | | | | Added parsing/sema analysis/serialization/deserialization for the 'allocator' clause of the 'allocate' directive. llvm-svn: 355952
* [OPENMP 5.0]Add initial support for 'allocate' directive.Alexey Bataev2019-03-071-1/+17
| | | | | | | Added parsing/sema analysis/serialization/deserialization support for 'allocate' directive. llvm-svn: 355614
* [OpenMP 5.0] Parsing/sema support for "omp declare mapper" directive.Michael Kruse2019-02-011-1/+21
| | | | | | | | | | | | | | | | | This patch implements parsing and sema for "omp declare mapper" directive. User defined mapper, i.e., declare mapper directive, is a new feature in OpenMP 5.0. It is introduced to extend existing map clauses for the purpose of simplifying the copy of complex data structures between host and device (i.e., deep copy). An example is shown below: struct S { int len; int *d; }; #pragma omp declare mapper(struct S s) map(s, s.d[0:s.len]) // Memory region that d points to is also mapped using this mapper. Contributed-by: Lingda Li <lildmh@gmail.com> Differential Revision: https://reviews.llvm.org/D56326 llvm-svn: 352906
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Add support for 'atomic_default_mem_order' clause on 'requires' directive. ↵Patrick Lyster2018-11-021-5/+3
| | | | | | Also renamed test files relating to 'requires'. Differntial review: https://reviews.llvm.org/D53513 llvm-svn: 345967
* [OPENMP] Add support for OMP5 requires directive + unified_address clauseKelvin Li2018-09-261-1/+14
| | | | | | | | | Add support for OMP5.0 requires directive and unified_address clause. Patches to follow will include support for additional clauses. Differential Revision: https://reviews.llvm.org/D52359 llvm-svn: 343063
* StmtPrinter: allow customizing the end-of-line characterGeorge Karpenkov2018-09-151-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D51824 llvm-svn: 342311
* [OPENMP] Fix processing of declare target construct.Alexey Bataev2018-08-141-0/+4
| | | | | | | The attribute marked as inheritable since OpenMP 5.0 supports it + additional fixes to support new functionality. llvm-svn: 339704
* Remove trailing spaceFangrui Song2018-07-301-14/+14
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* [Attr] Don't print implicit attributesJoel E. Denny2018-05-151-1/+1
| | | | | | | | | | | | Fixes bug reported at: http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180514/228390.html Reviewed by: aaron.ballman Differential Revision: https://reviews.llvm.org/D46894 llvm-svn: 332411
* [AST] Fix printing tag decl groups in decl contextsJoel E. Denny2018-05-151-11/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. Reviewed by: rsmith Differential Revision: https://reviews.llvm.org/D45465 llvm-svn: 332314
* [AST] Print correct tag decl for tag specifierJoel E. Denny2018-05-141-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Track the result of evaluating a computed noexcept specification on theRichard Smith2018-05-031-1/+1
| | | | | | | | | | | | | | FunctionProtoType. We previously re-evaluated the expression each time we wanted to know whether the type is noexcept or not. We now evaluate the expression exactly once. This is not quite "no functional change": it fixes a crasher bug during AST deserialization where we would try to evaluate the noexcept specification in a situation where we have not deserialized sufficient portions of the AST to permit such evaluation. llvm-svn: 331428
* [Attr] Print enum attributes at correct positionJoel E. Denny2018-04-241-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For example, given: void fn() { enum __attribute__((deprecated)) T *p; } -ast-print produced: void fn() { enum T __attribute__((deprecated(""))) *p; } -ast-print on that produced: void fn() { enum T *p __attribute__((deprecated(""))); } The attribute is on enum T in the first case, but it's on p in the other cases. Details: Within enum declarations, enum attributes were always printed after the tag and any member list. When no member list was present but the enum was a type specifier in a variable declaration, the attribute then applied to the variable not the enum, changing the semantics. This patch fixes that by always printing attributes between the enum's keyword and tag, as clang already does for structs, unions, and classes. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D45456 llvm-svn: 330722
* Remove redundant casts. NFCGeorge Burgess IV2018-03-011-1/+1
| | | | | | | | | | | | | | | | | | | So I wrote a clang-tidy check to lint out redundant `isa`, `cast`, and `dyn_cast`s for fun. This is a portion of what it found for clang; I plan to do similar cleanups in LLVM and other subprojects when I find time. Because of the volume of changes, I explicitly avoided making any change that wasn't highly local and obviously correct to me (e.g. we still have a number of foo(cast<Bar>(baz)) that I didn't touch, since overloading is a thing and the cast<Bar> did actually change the type -- just up the class hierarchy). I also tried to leave the types we were cast<>ing to somewhere nearby, in cases where it wasn't locally obvious what we were dealing with before. llvm-svn: 326416
* [DeclPrinter] Fix two cases that crash clang -ast-print.Artem Belevich2018-01-171-4/+5
| | | | | | | | | | | | | Both are related to handling anonymous structures. * clang didn't handle () around an anonymous struct variable. * clang also crashed on syntax errors that could lead to other syntactic constructs following the declaration of an anonymous struct. While the code is invalid, that's not a good reason to panic compiler. Differential Revision: https://reviews.llvm.org/D41788 llvm-svn: 322742
* [DeclPrinter] Allow printing fully qualified name of function declarationSerge Pavlov2017-11-231-5/+11
| | | | | | | | | | | When requesting a tooltip for a function call in an IDE, the fully qualified name helps to remove ambiguity in the function signature. Patch by Nikolai Kosjar! Differential Revision: https://reviews.llvm.org/D40013 llvm-svn: 318896
* [DeclPrinter] Extract function PrintConstructorInitializers, NFCAlex Lorenz2017-11-161-64/+69
| | | | | | | | Patch by Nikolai Kosjar! Differential Revision: https://reviews.llvm.org/D40066 llvm-svn: 318367
* [DeclPrinter] Honor TerseOutput for constructorsAlex Lorenz2017-11-161-56/+59
| | | | | | | | Patch by Nikolai Kosjar! Differential Revision: https://reviews.llvm.org/D39957 llvm-svn: 318365
* [OPENMP] Fix for PR34445: Reduction initializer segfaults at runtime inAlexey Bataev2017-09-061-0/+12
| | | | | | | | | | move constructor. Previously user-defined reduction initializer was considered as an assignment expression, not as initializer. Fixed this by treating the initializer expression as an initializer. llvm-svn: 312638
* Print enum constant values using the original source formattingAlex Lorenz2017-08-171-9/+12
| | | | | | | | if possible when creating "Declaration" nodes in XML comments rdar://14765746 llvm-svn: 311085
* ASTPrinter: Objective-C method declarations don't need a space afterAlex Lorenz2017-06-021-2/+4
| | | | | | | | the return type rdar://32332039 llvm-svn: 304553
* [ASTPrinter] Print template parameter lists for out-of-line functionsAlex Lorenz2017-04-181-0/+11
| | | | llvm-svn: 300560
* [ASTPrinter] Print nested name specifiers for out-of-line functionsAlex Lorenz2017-04-111-1/+8
| | | | | | rdar://31501863 llvm-svn: 299962
* Handle deduction guides better in -ast-print.Richard Smith2017-02-181-3/+12
| | | | llvm-svn: 295521
* [AST Printer] Print attributes on enum constantsJordan Rose2017-01-201-0/+1
| | | | | | | The AST printer was dropping attributes on enumerators (enum constants). Now it's not. llvm-svn: 292571
* Make output of -ast-print a valid C++ code.Serge Pavlov2016-11-101-63/+158
| | | | | | | | | | | | | | | | | | Output generated by option -ast-print looks like C/C++ code, and it really is for plain C. For C++ the produced output was not valid C++ code, but the differences were small. With this change the output is fixed and can be compiled. Tests are changed so that output produced by -ast-print is compiled again with the same flags and both outputs are compared. Option -ast-print is extensively used in clang tests but it itself was tested poorly, existing tests only checked that compiler did not crash. There are unit tests in file DeclPrinterTest.cpp, but they test only terse output mode. Differential Revision: https://reviews.llvm.org/D26452 llvm-svn: 286439
* Do not print enum underlying type if language is not C++11Serge Pavlov2016-11-041-1/+1
| | | | | | | Output generated by option '-ast-print' must not contains enum base type specifications if source language does not include C++11. llvm-svn: 285979
* Make output of ast-print closer to C++ codeSerge Pavlov2016-10-311-4/+3
| | | | | | | Put semicolon after non-defining method declaration and a class specialization body. llvm-svn: 285543
* Fix PR 28885: Fix AST Printer output for the inherited constructor usingAlex Lorenz2016-10-031-0/+11
| | | | | | | | | | | | | declarations. This commit ensures that the correct record type is printed out for the using declarations that represent C++ inherited constructors. It fixes a regression introduced in r274049 which changed the name that's stored in the using declarations that correspond to inherited constructors. Differential Revision: https://reviews.llvm.org/D25131 llvm-svn: 283105
* Revert r283102 (Typo in the phabricator link)Alex Lorenz2016-10-031-11/+0
| | | | llvm-svn: 283104
* Fix PR 28885: Fix AST Printer output for the inherited constructor usingAlex Lorenz2016-10-031-0/+11
| | | | | | | | | | | | | declarations. This commit ensures that the correct record type is printed out for the using declarations that represent C++ inherited constructors. It fixes a regression introduced in r274049 which changed the name that's stored in the using declarations that correspond to inherited constructors. Differential Revision: https://reviews.llvm.org/D25131 llvm-svn: 283102
* Teach -ast-print to print constexpr variables.Vassil Vassilev2016-07-081-3/+10
| | | | | | Patch reviewed by Richard Smith (D22168). llvm-svn: 274930
OpenPOWER on IntegriCloud