aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2018-04-06Fix typos in clangAlexander Kornienko1-2/+2
Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
2018-03-29[ast] Do not auto-initialize Objective-C for-loop variables in Objective-C++ ↵George Karpenkov1-1/+6
in templatized code under ARC The AST for the fragment ``` @interface I @end template <typename> void decode(I *p) { for (I *k in p) {} } void decode(I *p) { decode<int>(p); } ``` differs heavily when templatized and non-templatized: ``` |-FunctionTemplateDecl 0x7fbfe0863940 <line:4:1, line:7:1> line:5:6 decode | |-TemplateTypeParmDecl 0x7fbfe0863690 <line:4:11> col:11 typename depth 0 index 0 | |-FunctionDecl 0x7fbfe08638a0 <line:5:1, line:7:1> line:5:6 decode 'void (I *__strong)' | | |-ParmVarDecl 0x7fbfe08637a0 <col:13, col:16> col:16 referenced p 'I *__strong' | | `-CompoundStmt 0x7fbfe0863b88 <col:19, line:7:1> | |   `-ObjCForCollectionStmt 0x7fbfe0863b50 <line:6:3, col:20> | |     |-DeclStmt 0x7fbfe0863a50 <col:8, col:13> | |     | `-VarDecl 0x7fbfe08639f0 <col:8, col:11> col:11 k 'I *const __strong' | |     |-ImplicitCastExpr 0x7fbfe0863a90 <col:16> 'I *' <LValueToRValue> | |     | `-DeclRefExpr 0x7fbfe0863a68 <col:16> 'I *__strong' lvalue ParmVar 0x7fbfe08637a0 'p' 'I *__strong' | |     `-CompoundStmt 0x7fbfe0863b78 <col:19, col:20> | `-FunctionDecl 0x7fbfe0863f80 <line:5:1, line:7:1> line:5:6 used decode 'void (I *__strong)' |   |-TemplateArgument type 'int' |   |-ParmVarDecl 0x7fbfe0863ef8 <col:13, col:16> col:16 used p 'I *__strong' |   `-CompoundStmt 0x7fbfe0890cf0 <col:19, line:7:1> |     `-ObjCForCollectionStmt 0x7fbfe0890cc8 <line:6:3, col:20> |       |-DeclStmt 0x7fbfe0890c70 <col:8, col:13> |       | `-VarDecl 0x7fbfe0890c00 <col:8, col:11> col:11 k 'I *__strong' callinit |       |   `-ImplicitValueInitExpr 0x7fbfe0890c60 <<invalid sloc>> 'I *__strong' |       |-ImplicitCastExpr 0x7fbfe0890cb0 <col:16> 'I *' <LValueToRValue> |       | `-DeclRefExpr 0x7fbfe0890c88 <col:16> 'I *__strong' lvalue ParmVar 0x7fbfe0863ef8 'p' 'I *__strong' |       `-CompoundStmt 0x7fbfe0863b78 <col:19, col:20> ``` Note how in the instantiated version ImplicitValueInitExpr unexpectedly appears. While objects are auto-initialized under ARC, it does not make sense to have an initializer for a for-loop variable, and it makes even less sense to have such a different AST for instantiated and non-instantiated version. Digging deeper, I have found that there are two separate Sema* files for dealing with templates and for dealing with non-templatized code. In a non-templatized version, an initialization was performed only for variables which are not loop variables for an Objective-C loop and not variables for a C++ for-in loop: ```   if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) {     bool IsForRangeLoop = false;     if (TryConsumeToken(tok::colon, FRI->ColonLoc)) {       IsForRangeLoop = true;       if (Tok.is(tok::l_brace))         FRI->RangeExpr = ParseBraceInitializer();       else         FRI->RangeExpr = ParseExpression();     }     Decl *ThisDecl = Actions.ActOnDeclarator(getCurScope(), D);     if (IsForRangeLoop)       Actions.ActOnCXXForRangeDecl(ThisDecl);     Actions.FinalizeDeclaration(ThisDecl);     D.complete(ThisDecl);     return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, ThisDecl);   }   SmallVector<Decl *, 8> DeclsInGroup;   Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes(       D, ParsedTemplateInfo(), FRI); ``` However the code in SemaTemplateInstantiateDecl was inconsistent, guarding only against C++ for-in loops. rdar://38391075 Differential Revision: https://reviews.llvm.org/D44989 llvm-svn: 328749
2018-03-23Sink PrettyDeclStackTrace down to the AST libraryJordan Rose1-2/+2
...and add some very basic stack trace entries for module building. This would have helped track down rdar://problem/38434694 sooner. llvm-svn: 328276
2018-02-28Fix a couple of cases where we would fail to correctly parse deduced class ↵Richard Smith1-2/+3
template specialization types. Specifically, we would not properly parse these types within template arguments (for non-type template parameters), and in tentative parses. Fixing both of these essentially requires that we parse deduced template specialization types as types in all contexts, even in template argument lists -- in particular, tentative parsing may look ahead and annotate a deduced template specialization type before we figure out that we're actually supposed to treat the tokens as a template-name. We deal with this by simply permitting deduced template specialization types when parsing template arguments, and converting them to template template arguments. llvm-svn: 326299
2018-02-27Improve the way attribute argument printing happens for omitted optional ↵Aaron Ballman1-2/+5
arguments when pretty printing. Patch by Joel Denny. llvm-svn: 326266
2018-02-25Add a C++11 and C2x spelling for the type safety attribute ↵Aaron Ballman1-0/+4
(argument_with_type_tag, pointer_with_type_tag, and type_tag_for_datatype) in the clang vendor namespace. The TypeTagForDatatype attribute had custom parsing rules that previously prevented it from being supported with square bracket notation. The ArgumentWithTypeTag attribute previously had unnecessary custom parsing that could be handled declaratively. llvm-svn: 326052
2018-02-24Add a C++11 and C2x spelling for the objc_bridge_related attribute in the ↵Aaron Ballman1-0/+4
clang vendor namespace. This attribute has custom parsing rules that previously prevented it from being supported with square bracket notation. llvm-svn: 326038
2018-02-24Add a C++11 and C2x spelling for the availability attribute in the clang ↵Aaron Ballman1-5/+11
vendor namespace. This attribute has custom parsing rules that previously prevented it from being supported with square bracket notation. Rework the clang attribute argument parsing to be more easily extended for other custom-parsed attributes. llvm-svn: 326036
2018-02-02Add missing direct-init / parameter-declaration-clause disambiguation whenRichard Smith1-3/+18
parsing a trailing-return-type of a (function pointer) variable declaration. llvm-svn: 324151
2018-01-01Again reverting an attempt to convert the DeclSpec enums into scoped enums.Faisal Vali1-5/+5
- reverts r321622, r321625, and r321626. - the use of bit-fields is still resulting in warnings - even though we can use static-asserts to harden the code and ensure the bit-fields are wide enough. The bots still complain of warnings being seen. - to silence the warnings requires specifying the bit-fields with the underlying enum type (as opposed to the enum type itself), which then requires lots of unnecessary static casts of each enumerator within DeclSpec to the underlying-type, which even though could be seen as implementation details, it does hamper readability - and given the additional litterings, makes me question the value of the change. So in short - I give up (for now at least). Sorry about the noise. llvm-svn: 321628
2018-01-01[NFC] Modernize enums TypeSpecifierWidth, TypeSpecifierSign & ↵Faisal Vali1-5/+5
TypeSpecifierType into scoped enums with underlying types. - Since these enums are used as bit-fields - for the bit-fields to be interpreted as unsigned, the underlying type must be specified as unsigned. Previous failed attempt - wherein I did not specify an underlying type - was the sum of: https://reviews.llvm.org/rC321614 https://reviews.llvm.org/rC321615 llvm-svn: 321622
2018-01-01Revert r321614 and r321615Faisal Vali1-5/+5
- the enum changes to TypeSpecifierType are breaking some tests - and will require a more careful integration. Sorry about rushing these changes - thought I could sneak them in prior to heading out for new years ;) llvm-svn: 321616
2018-01-01[NFC] Modernize enums TypeSpecifierWidth, TypeSpecifierSign & ↵Faisal Vali1-5/+5
TypeSpecifierType into scoped enums. llvm-svn: 321614
2017-12-31[NFC] Modernize enum DeclSpecContext into a scoped enum.Faisal Vali1-40/+49
llvm-svn: 321590
2017-12-30[NFC] Modernize enum 'UnqualifiedId::IdKind' into a scoped enum ↵Faisal Vali1-1/+1
UnqualifiedIdKind. llvm-svn: 321574
2017-12-29[NFC] Modernize enum Declarator::TheContext to a type-safe scoped enum.Faisal Vali1-60/+66
Note, we don't do any bitwise manipulations when using them. llvm-svn: 321546
2017-12-25Add a fixit for attributes incorrectly placed prior to 'struct/class/enum' ↵Faisal Vali1-4/+10
keyword. Suggest moving the following erroneous attrib list (based on location) [[]] struct X; to struct [[]] X; Additionally, added a fixme for the current implementation that diagnoses misplaced attributes to consider using the newly introduced diagnostic (that I think is more user-friendly). llvm-svn: 321449
2017-12-07Remove old concepts parsing codeHubert Tong1-8/+0
Summary: This is so we can implement concepts per P0734R0. Relevant failing test cases are disabled. Reviewers: hubert.reinterpretcast, rsmith, saar.raz, nwilson Reviewed By: saar.raz Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40380 Patch by Changyu Li! llvm-svn: 319992
2017-12-04Now that C++17 is official (https://www.iso.org/standard/68564.html), start ↵Aaron Ballman1-2/+2
changing the C++1z terminology over to C++17. NFC intended, these are all mechanical changes. llvm-svn: 319688
2017-10-15Add -f[no-]double-square-bracket-attributes as new driver options to control ↵Aaron Ballman1-10/+24
use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a proposal to add [[]] attributes to C2x, but also allows you to enable these attributes in C++98, or disable them in C++11 or later. llvm-svn: 315856
2017-10-14Fix backwards warning for use of C++17 ↵Richard Smith1-3/+4
attributes-on-namespaces-and-enumerators feature. llvm-svn: 315784
2017-10-11[OpenCL] Allow function declaration with empty argument list.Alexey Bader1-1/+2
Treat 'f()' as 'f(void)' rather than a function w/o a prototype. Reviewers: Anastasia, yaxunl Reviewed By: Anastasia, yaxunl Subscribers: cfe-commits, echuraev, chapuni Differential Revision: https://reviews.llvm.org/D33681 Re-apply revision 306653. llvm-svn: 315453
2017-09-22Give external linkage and mangling to lambdas inside inline variables and ↵Richard Smith1-29/+37
variable templates. This implements the proposed approach in https://github.com/itanium-cxx-abi/cxx-abi/issues/33 This reinstates r313827, reverted in r313856, with a fix for the 'out-of-bounds enumeration value' ubsan error in that change. llvm-svn: 313955
2017-09-21Revert "Give external linkage and mangling to lambdas inside inline ↵Vitaly Buka1-37/+29
variables and variable templates." To fix: runtime error: load of value 15, which is not a valid value for type 'clang::LVComputationKind' This reverts commit r313827. llvm-svn: 313856
2017-09-20Give external linkage and mangling to lambdas inside inline variables and ↵Richard Smith1-29/+37
variable templates. This implements the proposed approach in https://github.com/itanium-cxx-abi/cxx-abi/issues/33 llvm-svn: 313827
2017-09-08Recommit "Add _Float16 as a C/C++ source language type"Sjoerd Meijer1-0/+7
This is a recommit of r312781; in some build configurations variable names are omitted, so changed the new regression test accordingly. llvm-svn: 312794
2017-09-08Fixed a crash in code completion.Ilya Biryukov1-5/+17
Summary: The crash occured when FunctionDecl was parsed with an initializer. Reviewers: bkramer, klimek, francisco.lopes Reviewed By: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D37382 llvm-svn: 312788
2017-09-08Revert "Add _Float16 as a C/C++ source language type"Sjoerd Meijer1-7/+0
The clang-with-lto-ubuntu bot didn't like the new regression test, revert while I investigate the issue. llvm-svn: 312784
2017-09-08Add _Float16 as a C/C++ source language typeSjoerd Meijer1-0/+7
This adds _Float16 as a source language type, which is a 16-bit floating point type defined in C11 extension ISO/IEC TS 18661-3. In follow up patches documentation and more tests will be added. Differential Revision: https://reviews.llvm.org/D33719 llvm-svn: 312781
2017-08-15Allow pretty platform names in availability attributesAlex Lorenz1-7/+12
rdar://32076651 llvm-svn: 310921
2017-08-10Place implictly declared functions at block scopeMomchil Velikov1-1/+3
Such implicitly declared functions behave as if the enclosing block contained the declaration extern int name() (C90, 6.3.3.2 Function calls), thus their names should have block scope (C90, 6.1.2.1 Scope of identifiers). This patch fixes https://bugs.llvm.org/show_bug.cgi?id=33224 Differential Revision: https://reviews.llvm.org/D33676 llvm-svn: 310616
2017-07-02fix trivial typos in comments; NFCHiroshi Inoue1-1/+1
llvm-svn: 306969
2017-07-01[Modules] Implement ODR-like semantics for tag types in C/ObjCBruno Cardoso Lopes1-7/+12
Allow ODR for ObjC/C in the sense that we won't keep more that one definition around (merge them). However, ensure the decl pass the structural compatibility check in C11 6.2.7/1, for that, reuse the structural equivalence checks used by the ASTImporter. Few other considerations: - Create error diagnostics for tag types mismatches and thread them into the structural equivalence checks. - Note that by doing this we only support redefinition between types that are considered "compatible types" by C. This is mixed approach of the suggestions discussed in http://lists.llvm.org/pipermail/cfe-dev/2017-March/053257.html Differential Revision: https://reviews.llvm.org/D31778 rdar://problem/31909368 llvm-svn: 306918
2017-06-30[Parse] Use normalized attr name for late-parsing checks.George Burgess IV1-8/+8
llvm-svn: 306899
2017-06-26[Sema] Fix a crash-on-invalid when a template parameter list has a classAkira Hatanaka1-1/+5
definition or non-reference class type. The crash occurs when there is a template parameter list in a class that is missing the closing angle bracket followed by a definition of a struct. For example: class C0 { public: template<typename T, typename T1 = T // missing closing angle bracket struct S0 {}; C0() : m(new S0<int>) {} S0<int> *m; }; This happens because the parsed struct is added to the scope of the enclosing class without having its access specifier set, which results in an assertion failure in SemaAccess.cpp later. This commit fixes the crash by adding the parsed struct to the enclosing file scope and marking structs as invalid if they are defined in template parameter lists. rdar://problem/31783961 rdar://problem/19570630 Differential Revision: https://reviews.llvm.org/D33606 llvm-svn: 306317
2017-06-01Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova1-0/+4
llvm-svn: 304472
2017-05-19When a type-id is unexpectedly given a name, assume that the name is unrelatedRichard Smith1-5/+22
syntax unless we have a reason to think otherwise. This improves error recovery in a couple of cases. llvm-svn: 303398
2017-05-18Fix the location of "missing ';'" suggestions after annotation tokens.Richard Smith1-8/+11
We were incorrectly setting PrevTokLocation to the first token in the annotation token instead of the last when consuming it. To fix this without adding a complex switch to the hot path through ConsumeToken, we now have a ConsumeAnnotationToken function for consuming annotation tokens in addition to the other Consume*Token special case functions. llvm-svn: 303372
2017-05-10Improve diagnosis of unknown template name.Richard Smith1-2/+9
When an undeclared identifier in a context that requires a type is followed by '<', only look for type templates when typo-correcting, tweak the diagnostic text to say that a template name (not a type name) was undeclared, and parse the template arguments when recovering from the error. llvm-svn: 302732
2017-04-11[Parser][ObjC++] Improve diagnostics and recovery when C++ keywords are usedAlex Lorenz1-0/+15
as identifiers in Objective-C++ This commit improves the 'expected identifier' errors that are presented when a C++ keyword is used as an identifier in Objective-C++ by mentioning that this is a C++ keyword in the diagnostic message. It also improves the error recovery: the parser will now treat the C++ keywords as identifiers to prevent unrelated parsing errors. rdar://20626062 Differential Revision: https://reviews.llvm.org/D26503 llvm-svn: 299950
2017-04-01[NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped EnumFaisal Vali1-10/+14
- also replace direct equality checks against the ConstantEvaluated enumerator with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17. - update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed. llvm-svn: 299316
2017-03-23Publish RAIIObjectsForParser.h for external usage.Vassil Vassilev1-1/+1
Some clients (eg the cling interpreter) need to recover their parser from errors. Patch by Axel Naumann (D31190)! llvm-svn: 298606
2017-03-01Introduce an 'external_source_symbol' attribute that describes the originAlex Lorenz1-0/+136
and the nature of a declaration This commit adds an external_source_symbol attribute to Clang. This attribute specifies that a declaration originates from an external source and describes the nature of that source. This attribute will be used to improve IDE features like 'jump-to-definition' for mixed-language projects or project that use auto-generated code. rdar://30423368 Differential Revision: https://reviews.llvm.org/D29819 llvm-svn: 296649
2017-02-14Remove unused variable. No functional change.Richard Trieu1-1/+1
llvm-svn: 295125
2017-02-14Improve diagnostic reporting when using __declspec without enabling ↵Aaron Ballman1-0/+25
__declspec as a keyword. Fixes PR31936. llvm-svn: 295114
2017-02-13[CodeCompletion] Code complete the missing C++11 keywordsAlex Lorenz1-5/+13
This commit adds context sensitive code completion support for the C++11 keywords that currently don't have completion results. The following keywords are supported by this patch: alignas constexpr static_assert noexcept (as a function/method qualifier) thread_local The following special identifiers are also supported: final (as a method qualifier or class qualifier) override rdar://29219185 Differential Revision: https://reviews.llvm.org/D28286 llvm-svn: 295001
2017-02-08Fix constructor declarator detection for the case when the name is followed byRichard Smith1-3/+13
an attribute-specifier-seq. (Also fixes the same problem for deduction-guides.) llvm-svn: 294396
2017-02-07P0091R3: Implement basic parsing support for C++17 deduction-guides.Richard Smith1-6/+29
We model deduction-guides as functions with a new kind of name that identifies the template whose deduction they guide; the bulk of this patch is adding the new name kind. This gives us a clean way to attach an extensible list of guides to a class template in a way that doesn't require any special handling in AST files etc (and we're going to need these functions we come to performing deduction). llvm-svn: 294266
2017-01-26PR0091R3: Implement parsing support for using templates as types.Richard Smith1-4/+6
This change adds a new type node, DeducedTemplateSpecializationType, to represent a type template name that has been used as a type. This is modeled around AutoType, and shares a common base class for representing a deduced placeholder type. We allow deduced class template types in a few more places than the standard does: in conditions and for-range-declarators, and in new-type-ids. This is consistent with GCC and with discussion on the core reflector. This patch does not yet support deduced class template types being named in typename specifiers. llvm-svn: 293207
2017-01-19PR13403 (+duplicates): implement C++ DR1310 (http://wg21.link/cwg1310).Richard Smith1-50/+19
Under this defect resolution, the injected-class-name of a class or class template cannot be used except in very limited circumstances (when declaring a constructor, in a nested-name-specifier, in a base-specifier, or in an elaborated-type-specifier). This is apparently done to make parsing easier, but it's a pain for us since we don't know whether a template-id using the injected-class-name is valid at the point when we annotate it (we don't yet know whether the template-id will become part of an elaborated-type-specifier). As a tentative resolution to a perceived language defect, mem-initializer-ids are added to the list of exceptions here (they generally follow the same rules as base-specifiers). When the reference to the injected-class-name uses the 'typename' or 'template' keywords, we permit it to be used to name a type or template as an extension; other compilers also accept some cases in this area. There are also a couple of corner cases with dependent template names that we do not yet diagnose, but which will also get this treatment. llvm-svn: 292518