aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2017-01-12Remove redundant passing around of a "ContainsAutoType" flag.Richard Smith1-8/+5
This flag serves no purpose other than to prevent us walking through a type to check whether it contains an 'auto' specifier; this duplication of information is error-prone, does not appear to provide any performance benefit, and will become less practical once we support C++1z deduced class template types and eventually constrained types from the Concepts TS. No functionality change intended. llvm-svn: 291737
2017-01-07Consistently use a ConstantEvaluated context for expressions in attributes,Richard Smith1-3/+4
except for those with the "attributes are unevaluated contexts" flag. llvm-svn: 291358
2017-01-04[Parse] Don't ignore attributes after a late-parsed attr.George Burgess IV1-2/+6
Without this, we drop everything after the first late-parsed attribute in a single __attribute__. (Where "drop" means "stuff everything into LA->Toks.") llvm-svn: 291020
2016-12-16[c++1z] P0195R2: Allow multiple using-declarators in a single using-declaration.Richard Smith1-7/+4
llvm-svn: 289905
2016-12-09Store decls in prototypes on the declarator instead of in the ASTReid Kleckner1-0/+16
This saves two pointers from FunctionDecl that were being used for some rare and questionable C-only functionality. The DeclsInPrototypeScope ArrayRef was added in r151712 in order to parse this kind of C code: enum e {x, y}; int f(enum {y, x} n) { return x; // should return 1, not 0 } The challenge is that we parse 'int f(enum {y, x} n)' it its own function prototype scope that gets popped before we build the FunctionDecl for 'f'. The original change was doing two questionable things: 1. Saving all tag decls introduced in prototype scope on a TU-global Sema variable. This is problematic when you have cases like this, where 'x' and 'y' shouldn't be visible in 'f': void f(void (*fp)(enum { x, y } e)) { /* no x */ } This patch fixes that, so now 'f' can't see 'x', which is consistent with GCC. 2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that they could be used in ActOnStartOfFunctionDef. This is just an inefficient way to move information around. The AST lives forever, but the list of non-parameter decls in prototype scope is short lived. Moving these things to the Declarator solves both of these issues. Reviewers: rsmith Subscribers: jmolloy, cfe-commits Differential Revision: https://reviews.llvm.org/D27279 llvm-svn: 289225
2016-12-07[ObjC++] Don't enter a C++ declarator scope when the current context isAlex Lorenz1-0/+8
an Objective-C declaration This commit ensures that Sema won't enter a C++ declarator scope when the current context is an Objective-C declaration. This prevents an assertion failure in EnterDeclaratorContext that's used to ensure that current context will be restored correctly after exiting the declarator context. rdar://20560175 Differential Revision: https://reviews.llvm.org/D26922 llvm-svn: 288893
2016-12-02Mass-rename the handful of error_* diagnostics to err_*.Richard Smith1-1/+1
llvm-svn: 288545
2016-11-17Use unique_ptr for cached tokens for default arguments in C++.Malcolm Parsons1-6/+4
Summary: This changes pointers to cached tokens for default arguments in C++ from raw pointers to unique_ptrs. There was a fixme in the code where the cached tokens are created about using a smart pointer. The change is straightforward, though I did have to track down and fix a memory corruption caused by the change. memcpy was being used to copy parameter information. This duplicated the unique_ptr, which led to the cached token buffer being deleted prematurely. Patch by David Tarditi! Reviewers: malcolm.parsons Subscribers: arphaman, malcolm.parsons, cfe-commits Differential Revision: https://reviews.llvm.org/D26435 llvm-svn: 287241
2016-11-10Accept nullability qualifiers on array parameters.Jordan Rose1-3/+2
Since array parameters decay to pointers, '_Nullable' and friends should be available for use there as well. This is especially important for parameters that are typedefs of arrays. The unsugared syntax for this follows the syntax for 'static'-sized arrays in C: void test(int values[_Nullable]); This syntax was previously accepted but the '_Nullable' (and any other attributes) were silently discarded. However, applying '_Nullable' to a typedef was previously rejected and is now accepted; therefore, it may be necessary to test for the presence of this feature: #if __has_feature(nullability_on_arrays) One important change here is that DecayedTypes don't always immediately contain PointerTypes anymore; they may contain an AttributedType instead. This only affected one place in-tree, so I would guess it's not likely to cause problems elsewhere. This commit does not change -Wnullability-completeness just yet. I want to think about whether it's worth doing something special to avoid breaking existing clients that compile with -Werror. It also doesn't change '#pragma clang assume_nonnull' behavior, which currently treats the following two declarations as equivalent: #pragma clang assume_nonnull begin void test(void *pointers[]); #pragma clang assume_nonnull end void test(void * _Nonnull pointers[]); This is not the desired behavior, but changing it would break backwards-compatibility. Most likely the best answer is going to be adding a new warning. Part of rdar://problem/25846421 llvm-svn: 286519
2016-11-10Clean up uses of unique_ptr for RAII objects. NFC.George Burgess IV1-8/+9
- EnterExpressionEvaluationContext allows you to specify whether you *actually* want to enter an evaluation context. - For types that don't allow that, llvm::Optional<Foo> should do the same thing as std::unique_ptr<Foo>, but with 100% less heap allocations. llvm-svn: 286500
2016-11-02regcall: Implement regcall Calling Conv in clangErich Keane1-0/+5
This patch implements the register call calling convention, which ensures as many values as possible are passed in registers. CodeGen changes were committed in https://reviews.llvm.org/rL284108. Differential Revision: https://reviews.llvm.org/D25204 llvm-svn: 285849
2016-09-13[SemaObjC] Be more strict while parsing type arguments and protocolsBruno Cardoso Lopes1-1/+2
Fix a crash-on-invalid. When parsing type arguments and protocols, parseObjCTypeArgsOrProtocolQualifiers() calls ParseTypeName(), which tries to find matching tokens for '[', '(', etc whenever they appear among potential type names. If unmatched, ParseTypeName() yields a tok::eof token stream. This leads to crashes since the parsing at this point is not expected to go beyond the param list closing '>'. Fix that by properly handling tok::eof in parseObjCTypeArgsOrProtocolQualifiers() callers. Differential Revision: https://reviews.llvm.org/D23852 rdar://problem/25063557 llvm-svn: 281383
2016-09-13[clang-cl] Diagnose duplicate uuids.Nico Weber1-2/+14
This mostly behaves cl.exe's behavior, even though clang-cl is stricter in some corner cases and more lenient in others (see the included test). To make the uuid declared previously here diagnostic work correctly, tweak stripTypeAttributesOffDeclSpec() to keep attributes in the right order. https://reviews.llvm.org/D24469 llvm-svn: 281367
2016-09-03Let Microsoft attributes apply to the type, not the variable.Nico Weber1-8/+12
There was already a function that moved attributes off the declspec into an attribute list for attributes applying to the type, teach that function to also move Microsoft attributes around and rename it to match its new broader role. Nothing uses Microsoft attributes yet, so no behavior change. Part of https://reviews.llvm.org/D23895 llvm-svn: 280576
2016-08-18C++ Modules TS: Add parsing support for module import declaration.Richard Smith1-9/+13
llvm-svn: 279163
2016-07-22P0217R3: Parsing support and framework for AST representation of C++1zRichard Smith1-1/+75
decomposition declarations. There are a couple of things in the wording that seem strange here: decomposition declarations are permitted at namespace scope (which we partially support here) and they are permitted as the declaration in a template (which we reject). llvm-svn: 276492
2016-07-16[ObjC] Implement @available in the Parser and ASTErik Pilkington1-1/+1
This patch adds a new AST node: ObjCAvailabilityCheckExpr, and teaches the Parser and Sema to generate it. This node represents an availability check of the form: @available(macos 10.10, *); Which will eventually compile to a runtime check of the host's OS version. This is the first patch of the feature I proposed here: http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html Differential Revision: https://reviews.llvm.org/D22171 llvm-svn: 275654
2016-07-15[AST] Keep track of the left brace source location of a tag decl.Argyrios Kyrtzidis1-5/+3
This is useful for source modification tools. There will be a follow-up commit using it. llvm-svn: 275590
2016-06-29P0305R1: Parsing support for init-statements in 'if' and 'switch' statements.Richard Smith1-1/+2
No semantic analysis yet. This is a pain to disambiguate correctly, because the parsing rules for the declaration form of a condition and of an init-statement are quite different -- for a token sequence that looks like a declaration, we frequently need to disambiguate all the way to the ')' or ';'. We could do better here in some cases by stopping disambiguation once we've decided whether we've got an expression or not (rather than keeping going until we know whether it's an init-statement declaration or a condition declaration), by unifying our parsing code for the two types of declaration and moving the syntactic checks into Sema; if this has a measurable impact on parsing performance, I'll look into that. llvm-svn: 274169
2016-06-28AvailabilityAttr: we accept "macos" as the platform name.Manman Ren1-0/+7
We continue accepting "macosx" but canonicalize it to "macos", When emitting diagnostics, we use "macOS" instead of "OS X". The PlatformName in TargetInfo is changed from "macosx" to "macos" so we can directly compare the Platform in AvailabilityAttr with the PlatformName in TargetInfo. rdar://26795172 rdar://26800775 llvm-svn: 274064
2016-06-14[Parser] Handle __pragma(pack, etc. after type definitionsDavid Majnemer1-0/+16
Support certain MS pragmas right after the closing curly brace of a class. Clang did not expect __pragma in this position. This fixes PR28094. llvm-svn: 272628
2016-05-24[ms] Allow more unqualified lookup of types in dependent base classesReid Kleckner1-10/+18
Summary: In dependent contexts where we know a type name is required, such as a new expression, we can recover by forming a DependentNameType. This generalizes our existing compatibility hack for default arguments for template type parameters. Works towards parsing atlctrlw.h, which is PR26748. Reviewers: avt77, rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D20500 llvm-svn: 270615
2016-05-19Make Sema::getPrintingPolicy less ridiculously expensive. This used to performRichard Smith1-1/+1
an identifier table lookup, *and* copy the LangOptions (including various std::vector<std::string>s). Twice. We call this function once each time we start parsing a declaration specifier sequence, and once for each call to Sema::Diag. This reduces the compile time for a sample .c file from the linux kernel by 20%. llvm-svn: 270009
2016-05-12[OpenCL] Output OpenCL version in diagnostics.Anastasia Stulova1-3/+8
Diagnostics should note version dependent issues by giving a hint about current version being compiled for. This patch changes diagnostics of static storage class specifier and generic type qualifier to specify OpenCL version as well as converts other diagnostics to match the style. Patch by Vedran Miletic! Review: http://reviews.llvm.org/D19780 llvm-svn: 269305
2016-05-11[MSVC] Implementation of __unaligned as a proper type qualifierAndrey Bokhanko1-4/+11
This patch implements __unaligned (MS extension) as a proper type qualifier (before that, it was implemented as an ignored attribute). It also fixes PR27367 and PR27666. Differential Revision: http://reviews.llvm.org/D20103 llvm-svn: 269220
2016-05-09Enable support for __float128 in Clang and enable it on pertinent platformsNemanja Ivanovic1-0/+7
This patch corresponds to reviews: http://reviews.llvm.org/D15120 http://reviews.llvm.org/D19125 It adds support for the __float128 keyword, literals and target feature to enable it. Based on the latter of the two aforementioned reviews, this feature is enabled on Linux on i386/X86 as well as SystemZ. This is also the second attempt in commiting this feature. The first attempt did not enable it on required platforms which caused failures when compiling type_traits with -std=gnu++11. If you see failures with compiling this header on your platform after this commit, it is likely that your platform needs to have this feature enabled. llvm-svn: 268898
2016-05-06Revert r268727, it caused PR27666.Nico Weber1-11/+4
llvm-svn: 268736
2016-05-06[MSVC] Implementation of __unaligned as a proper type qualifierAndrey Bokhanko1-4/+11
This patch implements __unaligned (MS extension) as a proper type qualifier (before that, it was implemented as an ignored attribute). It also fixes PR27367. Differential Revision: http://reviews.llvm.org/D19654 llvm-svn: 268727
2016-04-29[Concepts] Pass requires-clause to ActOnTemplateParameterList; NFCHubert Tong1-1/+1
Summary: Prepare to store requires-clause expression for access via TemplateParameterList. Reviewers: aaron.ballman, faisalv, rsmith Subscribers: cfe-commits, nwilson Differential Revision: http://reviews.llvm.org/D19220 llvm-svn: 268081
2016-04-21Correctly parse GCC-style asm line following MS-style asm line.Denis Zobnin1-21/+0
Quit parsing MS-style inline assembly if the following statement has GCC style. Enables compilation of code like void f() { __asm mov ebx, ecx __asm__("movl %ecx, %edx"); } Differential Revision: http://reviews.llvm.org/D18652 llvm-svn: 266976
2016-04-15Revert 266186 as it breaks anything that includes type_traits on some platformsNemanja Ivanovic1-7/+0
Since this patch provided support for the __float128 type but disabled it on all platforms by default, some platforms can't compile type_traits with -std=gnu++11 since there is a specialization with __float128. This reverts the patch until D19125 is approved (i.e. we know which platforms need this support enabled). llvm-svn: 266460