aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-04-04[clang][parser] Set source ranges for GNU-style attributesTimm Bäder1-11/+17
Set the source ranges for parsed GNU-style attributes in ParseGNUAttributes(), the same way that ParseCXX11Attributes() does it. Differential Revision: https://reviews.llvm.org/D75844
2021-04-01Revert "[clang][parser] Set source ranges for GNU-style attributes"Timm Bäder1-17/+11
This reverts commit 1ea9fa8c507ec360cf43faf46d13b149e37c950d.
2021-04-01[clang][parser] Set source ranges for GNU-style attributesTimm Bäder1-11/+17
Set the source ranges for parsed GNU-style attributes in ParseGNUAttributes(), the same way that ParseCXX11Attributes() does it. Differential Revision: https://reviews.llvm.org/D75844
2021-03-31[clang][parser] Allow GNU-style attributes in explicit template...Timm Bäder1-2/+26
... instantiations They are currently not being diagnosed because ProhibitAttributes() does not handle attribute lists with an invalid source range. But once it does, we need to allow GNU attributes in this place. Additionally, start optionally diagnosing empty attr lists in ProhibitCXX11Attributes(), since ProhibitAttribute() does it. Differential Revision: https://reviews.llvm.org/D97362
2021-03-16[CodeCompletion] Avoid spurious signature help for init-list argsSam McCall1-7/+12
Somewhat surprisingly, signature help is emitted as a side-effect of computing the expected type of a function argument. The reason is that both actions require enumerating the possible function signatures and running partial overload resolution, and doing this twice would be wasteful and complicated. Change #1: document this, it's subtle :-) However, sometimes we need to compute the expected type without having reached the code completion cursor yet - in particular to allow completion of designators. eb4ab3358cd4dc834a761191b5531b38114f7b13 did this but introduced a regression - it emits signature help in the wrong location as a side-effect. Change #2: only emit signature help if the code completion cursor was reached. Currently there is PP.isCodeCompletionReached(), but we can't use it because it's set *after* running code completion. It'd be nice to set this implicitly when the completion token is lexed, but ConsumeCodeCompletionToken() makes this complicated. Change #3: call cutOffParsing() *first* when seeing a completion token. After this, the fact that the Sema::Produce*SignatureHelp() functions are even more confusing, as they only sometimes do that. I don't want to rename them in this patch as it's another large mechanical change, but we should soon. Change #4: prepare to rename ProduceSignatureHelp() to GuessArgumentType() etc. Differential Revision: https://reviews.llvm.org/D98488
2021-03-12[OpenCL] Refactor diagnostic for OpenCL extension/featureAnton Zabaznov1-2/+2
There is no need to check for enabled pragma for core or optional core features, thus this check is removed Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D97058
2021-02-23[clang][parse][NFC] Remove dead ProhibitAttributes() callTimm Bäder1-1/+0
GNU-style attribute in enum bodies are allowed (and used by several tests), and this call to ProhibitAttributes() was dead code. Differential Revision: https://reviews.llvm.org/D97271
2021-02-05[OpenCL] Introduce new language options for OpenCL keywords.Anton Zabaznov1-8/+5
OpenCL keywords 'pipe' and 'generic' are unconditionally supported for OpenCL C 2.0 or in OpenCL C++ mode. In OpenCL C 3.0 these keywords are available if corresponding optional core feature is supported. Reviewed By: Anastasia, svenvh Differential Revision: https://reviews.llvm.org/D95778
2021-01-27clang: Fix static_assert in a few contexts in microsoft modeNico Weber1-1/+2
Follow-up to D17444. Fixes PR48904. See bug for details. Differential Revision: https://reviews.llvm.org/D95559
2021-01-27Parse different attribute syntaxes in arbitrary orderAaron Ballman1-12/+23
In Clang today, we parse the different attribute syntaxes (__attribute__, __declspec, and [[]]) in a fairly rigid order. This leads to confusion for users when they guess the order incorrectly, and leads to bug reports like PR24559 or necessitates changes like D94788. This patch adds a helper function to allow us to more easily parse attributes in arbitrary order, and then updates all of the places where we would parse two or more different syntaxes in a rigid order to use the helper method. The patch does not attempt to handle Microsoft attributes ([]) because those are ambiguous with other code constructs and we don't have any attributes that use the syntax.
2021-01-06[OpenCL] Add clang extension for function pointers.Anastasia Stulova1-3/+4
The new clang internal extension '__cl_clang_function_pointers' allows use of function pointers and other features that have the same functionality: - Use of member function pointers; - Unrestricted use of references to functions; - Virtual member functions. This not a vendor extension and therefore it doesn't require any special target support. Exposing this functionality fully will require vendor or Khronos extension. Tags: #clang Differential Revision: https://reviews.llvm.org/D94021
2020-12-08Fix inconsistent availability attribute message string literal check.Nigel Perks1-1/+1
Function Parser::ParseAvailabilityAttribute checks that the message string of an availability attribute is not a wide string literal. Test case clang/test/Parser/attr-availability.c specifies that a string literal is expected. The code checked that the first token in a string concatenation is a string literal, and then that the concatenated string consists of 1-byte characters. On a target where wide character is 1 byte, a string concatenation "a" L"b" passes both those checks, but L"b" alone is rejected. More generally, "a" u8"b" passes the checks, but u8"b" alone is rejected. So check isAscii() instead of character size.
2020-12-07[clang] Add a new nullability annotation for swift async: _Nullable_resultErik Pilkington1-0/+5
_Nullable_result generally like _Nullable, except when being imported into a swift async method. rdar://70106409 Differential revision: https://reviews.llvm.org/D92495
2020-12-04[Sema] Fold VLAs to constant arrays in a few more contextsErik Pilkington1-8/+29
552c6c2 removed support for promoting VLAs to constant arrays when the bounds isn't an ICE, since this can result in miscompiling a conforming program that assumes that the array is a VLA. Promoting VLAs for fields is still supported, since clang doesn't support VLAs in fields, so no conforming program could have a field VLA. This change is really disruptive, so this commit carves out two more cases where we promote VLAs which can't miscompile a conforming program: - When the VLA appears in an ivar -- this seems like a corollary to the field thing - When the VLA has an initializer -- VLAs can't have an initializer Differential revision: https://reviews.llvm.org/D90871
2020-11-16Convert ConstexprKind from Specifiers.h to a scoped enum; NFCThorsten1-4/+7
2020-11-16Convert TypeSpecifierSign from Specifiers.h to a scoped enum; NFCThorsten1-3/+3
2020-11-15[NFC, Refactor] Modernize the TypeSpecifierWidth enum (Specifiers.h) to a ↵faisalv1-7/+7
scoped enum Reviewed here: https://reviews.llvm.org/D91409 by Aaron. Highlights of the review: - avoid an underlying type for enums - avoid enum bit fields (MSVC packing anomalies) and favor static_casts to unsigned bit-fields Patch by Thorsten Schuett <schuett@gmail.com> w some minor fixes in SemaType.cpp where a couple asserts had to be repaired to deal with lack of implicit coversion to int. Thanks Thorsten!
2020-11-13Pass the source range when diagnosing an unknown attributeAaron Ballman1-1/+2
This way, the whole attribute gets highlighted with diagnostics instead of just the scope name in an attribute like [[clang::unknown]].
2020-11-10[NFC, Refactor] Rename the (scoped) enum DeclaratorContext's enumerators to ↵Faisal Vali1-69/+61
remove duplication Since these are scoped enumerators, they have to be prefixed by DeclaratorContext, so lets remove Context from the name, and return some characters to the multiverse. Patch was reviewed here: https://reviews.llvm.org/D91011 Thank you to aaron, bruno, wyatt and barry for indulging me.
2020-10-28Better source location for -Wignored-qualifiers on trailing return typesAaron Puchert1-1/+4
We collect the source location of a trailing return type in the parser, improving the location for regular functions and providing a location for lambdas, where previously there was none. Fixes PR47732. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D90129
2020-10-12[clang] Fix returning the underlying VarDecl as top-level decl for ↵Haojian Wu1-3/+5
VarTemplateDecl. Given the following VarTemplateDecl AST, ``` VarTemplateDecl col:26 X |-TemplateTypeParmDecl typename depth 0 index 0 `-VarDecl X 'bool' cinit `-CXXBoolLiteralExpr 'bool' true ``` previously, we returned the VarDecl as the top-level decl, which was not correct, the top-level decl should be VarTemplateDecl. Differential Revision: https://reviews.llvm.org/D89098
2020-09-29Better diagnostics for anonymous bit-fields with attributes or an initializer.Aaron Ballman1-1/+6
The current C++ grammar allows an anonymous bit-field with an attribute, but this is ambiguous (the attribute in that case could appertain to the type instead of the bit-field). The current thinking in the Core Working Group is that it's better to disallow attributes in that position at the grammar level so that the ambiguity resolves in favor of applying to the type. During discussions about the behavior of the attribute, the Core Working Group also felt it was better to disallow anonymous bit-fields from specifying a default member initializer. This implements both sets of related grammar changes.
2020-09-27Typo fix; NFCAaron Ballman1-1/+1
2020-09-24PR47176: Don't read from an inactive union member if a friend functionRichard Smith1-0/+4
has default arguments and an exception specification.
2020-09-24Sema: add support for `__attribute__((__swift_newtype__))`Saleem Abdulrasool1-0/+52
Add the `swift_newtype` attribute which allows a type definition to be imported into Swift as a new type. The imported type must be either an enumerated type (enum) or an object type (struct). This is based on the work of the original changes in https://github.com/llvm/llvm-project-staging/commit/8afaf3aad2af43cfedca7a24cd817848c4e95c0c Differential Revision: https://reviews.llvm.org/D87652 Reviewed By: Aaron Ballman
2020-08-28Add new warning for compound punctuation tokens that are split across macro ↵Richard Smith1-0/+5
expansions or split by whitespace. For example: #define FOO(x) (x) FOO({}); ... forms a statement-expression after macro expansion. This warning applies to '({' and '})' delimiting statement-expressions, '[[' and ']]' delimiting attributes, and '::*' introducing a pointer-to-member. The warning for forming these compound tokens across macro expansions (or across files!) is enabled by default; the warning for whitespace within the tokens is not, but is included in -Wall. Differential Revision: https://reviews.llvm.org/D86751
2020-07-27Don't form a 'context-independent expr' reference to a member duringRichard Smith1-1/+1
name annotation. Instead, defer forming the member access expression or DeclRefExpr until we build the use of ClassifyName's result. Just build an UnresolvedLookupExpr to track the LookupResult until we're ready to consume it. This also reverts commit 2f7269b6773de2750f9cd1417ef5f21cd6cf7a91 (other than its testcase). That change was an attempted workaround for the same problem.
2020-07-01[CodeComplete] Add code completion after function equalslh1231-37/+43
Summary: Provide `default` and `delete` completion after the function equals. Reviewers: kadircet, sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D82548
2020-06-23Move late-parsed class member attribute handling adjacent to all theRichard Smith1-148/+0
other late-parsed class component handling. No functionality change intended.
2020-06-09PR46255: Fix field diagnostics for C records with anonymous members.Erich Keane1-5/+4
The ParseStructUnionBody function was separately keeping track of the field decls for historical reasons, however the "ActOn" functions add the field to the RecordDecl anyway. The "ParseStructDeclaration" function, which handles parsing fields didn't have a way of handling what happens on an anonymous field, and changing it would alter a large amount of objc code, so I chose instead to implement this by just filling the FieldDecls vector with the actual FieldDecls that were successfully added to the recorddecl .
2020-06-05[ARM] Add __bf16 as new Bfloat16 C TypeTies Stuij1-0/+7
Summary: This patch upstreams support for a new storage only bfloat16 C type. This type is used to implement primitive support for bfloat16 data, in line with the Bfloat16 extension of the Armv8.6-a architecture, as detailed here: https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/arm-architecture-developments-armv8-6-a The bfloat type, and its properties are specified in the Arm Architecture Reference Manual: https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile In detail this patch: - introduces an opaque, storage-only C-type __bf16, which introduces a new bfloat IR type. This is part of a patch series, starting with command-line and Bfloat16 assembly support. The subsequent patches will upstream intrinsics support for BFloat16, followed by Matrix Multiplication and the remaining Virtualization features of the armv8.6-a architecture. The following people contributed to this patch: - Luke Cheeseman - Momchil Velikov - Alexandros Lamprineas - Luke Geeson - Simon Tatham - Ties Stuij Reviewers: SjoerdMeijer, rjmccall, rsmith, liutianle, RKSimon, craig.topper, jfb, LukeGeeson, fpetrogalli Reviewed By: SjoerdMeijer Subscribers: labrinea, majnemer, asmith, dexonsmith, kristof.beyls, arphaman, danielkiss, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76077
2020-05-10Enforce the C++11 anonymous enum bitfields check even forRichard Smith1-2/+1
Objective-C++11 and under MS extensions. This matches the MSVC behavior, and means that Objective-C behaves as a set of extensions to the base language, rather than replacing the base language rule with a different one.
2020-05-10Properly implement 'enum class' parsing.Richard Smith1-20/+47
The 'class' or 'struct' keyword is only permitted as part of either an enum definition or a standalone opaque-enum-declaration, not as part of an elaborated type specifier. We previously failed to diagnose this, and generally didn't properly implement the restrictions on elaborated type specifiers for enumeration types. In passing, also fixed incorrect parsing for enum-bases, which we previously parsed as a type-name, but are actually a type-specifier-seq. This matters for cases like 'enum E : int *p;', which is valid as a Microsoft extension. Plus some minor parse diagnostic improvements. Bumped the recently-added ExtWarn for 'enum E : int x;' to be DefaultError; this is not an intentional extension, so producing an error by default seems appropriate, but the warning flag to disable it may still be useful for code written against old Clang. The same treatment is given here to the diagnostic for 'enum class E x;', which we similarly have incorrectly accepted for many years. These diagnostics continue to be suppressed under -fms-extensions and when compiling Objective-C code. We will need to decide separately whether Objective-C should follow the C++ rules or the (older) MSVC rules.
2020-05-08Fix parsing of enum-base to follow C++11 rules.Richard Smith1-72/+70
Previously we implemented non-standard disambiguation rules to distinguish an enum-base from a bit-field but otherwise treated a : after an elaborated-enum-specifier as introducing an enum-base. That misparses various examples (anywhere an elaborated-type-specifier can appear followed by a colon, such as within a ternary operator or _Generic). We now implement the C++11 rules, with the old cases accepted as extensions where that seemed reasonable. These amount to: * an enum-base must always be accompanied by an enum definition (except in a standalone declaration of the form 'enum E : T;') * in a member-declaration, 'enum E :' always introduces an enum-base, never a bit-field * in a type-specifier (or similar context), 'enum E :' is not permitted; the colon means whatever else it would mean in that context. Fixed underlying types for enums are also permitted in Objective-C and under MS extensions, plus as a language extension in all other modes. The behavior in ObjC and MS extensions modes is unchanged (but the bit-field disambiguation is a bit better); remaining language modes follow the C++11 rules. Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++ core issues 1514 and 1966.
2020-04-29Fixing typo (singed -> signed); NFCAaron Ballman1-1/+1
2020-04-22Rename warning identifiers from cxx2a to cxx20; NFC.Aaron Ballman1-1/+1
2020-04-21C++2a -> C++20 in some identifiers; NFC.Aaron Ballman1-3/+3
2020-04-17Reland Implement _ExtInt as an extended int type specifier.Erich Keane1-0/+30
I fixed the LLDB issue, so re-applying the patch. This reverts commit a4b88c044980337bb14390be654fe76864aa60ec.
2020-04-17Revert "Implement _ExtInt as an extended int type specifier."Sterling Augustine1-30/+0
This reverts commit 61ba1481e200b5b35baa81ffcff81acb678e8508. I'm reverting this because it breaks the lldb build with incomplete switch coverage warnings. I would fix it forward, but am not familiar enough with lldb to determine the correct fix. lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:3958:11: error: enumeration values 'DependentExtInt' and 'ExtInt' not handled in switch [-Werror,-Wswitch] switch (qual_type->getTypeClass()) { ^ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4633:11: error: enumeration values 'DependentExtInt' and 'ExtInt' not handled in switch [-Werror,-Wswitch] switch (qual_type->getTypeClass()) { ^ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4889:11: error: enumeration values 'DependentExtInt' and 'ExtInt' not handled in switch [-Werror,-Wswitch] switch (qual_type->getTypeClass()) {
2020-04-17Implement _ExtInt as an extended int type specifier.Erich Keane1-0/+30
Introduction/Motivation: LLVM-IR supports integers of non-power-of-2 bitwidth, in the iN syntax. Integers of non-power-of-two aren't particularly interesting or useful on most hardware, so much so that no language in Clang has been motivated to expose it before. However, in the case of FPGA hardware normal integer types where the full bitwidth isn't used, is extremely wasteful and has severe performance/space concerns. Because of this, Intel has introduced this functionality in the High Level Synthesis compiler[0] under the name "Arbitrary Precision Integer" (ap_int for short). This has been extremely useful and effective for our users, permitting them to optimize their storage and operation space on an architecture where both can be extremely expensive. We are proposing upstreaming a more palatable version of this to the community, in the form of this proposal and accompanying patch. We are proposing the syntax _ExtInt(N). We intend to propose this to the WG14 committee[1], and the underscore-capital seems like the active direction for a WG14 paper's acceptance. An alternative that Richard Smith suggested on the initial review was __int(N), however we believe that is much less acceptable by WG14. We considered _Int, however _Int is used as an identifier in libstdc++ and there is no good way to fall back to an identifier (since _Int(5) is indistinguishable from an unnamed initializer of a template type named _Int). [0]https://www.intel.com/content/www/us/en/software/programmable/quartus-prime/hls-compiler.html) [1]http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2472.pdf Differential Revision: https://reviews.llvm.org/D73967
2020-04-08[Parser] Improve diagnostic and error recovery when C++ keywords are used as ↵Haojian Wu1-0/+25
identifiers. Summary: Previously, clang emitted a less-usefull diagnostic and didnt recover well when the keywords is used as identifier in function paramter. ``` void foo(int case, int x); // previously we drop all parameters after `int case`. ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77633
2020-03-30Fix crash if base specifier parsing hits an invalid type annotation.Richard Smith1-17/+9
Also change type annotation representation from ParsedType to TypeResult to make it clearer to consumers that they can represent invalid types.
2020-03-27Improve recovery from invalid template-ids.Richard Smith1-9/+43
Instead of bailing out of parsing when we encounter an invalid template-name or template arguments in a template-id, produce an annotation token describing the invalid construct. This avoids duplicate errors and generally allows us to recover better. In principle we should be able to extend this to store some kinds of invalid template-id in the AST for tooling use, but that isn't handled as part of this change.
2020-03-20Clean up and simplify after collision of c48442c and 19fccc5, whichRichard Smith1-7/+2
fixed the same bug in two similar ways.
2020-03-19[Parser] Avoid spurious 'missing template' error in presence of typos.Haojian Wu1-7/+12
Suppress those diagnostics if lhs of a member expression contains errors. Typo correction produces dependent expressions even in non-template code, that led to spurious diagnostics before. previous: /tmp/t.cpp:6:17: error: use 'template' keyword to treat 'f' as a dependent template name auto a = bilder.f<int>(); ^ template /tmp/t.cpp:6:10: error: use of undeclared identifier 'bilder'; did you mean 'builder'? auto a = bilder.f<int>(); ^~~~~~ builder vs now: /tmp/t.cpp:6:10: error: use of undeclared identifier 'bilder'; did you mean 'builder'? auto a = bilder.f<int>(); ^~~~~~ builder Original patch from Ilya. Reviewers: sammccall Reviewed By: sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D65592
2020-03-17PR45207: Fix crash if constrained-type-specifier annotation forms aRichard Smith1-1/+1
template_id annotation when parsing a type.
2020-03-17[Concepts] Fix incorrect control flow when TryAnnotateTypeConstraint ↵Saar Raz1-0/+6
annotates an invalid template-id TryAnnotateTypeConstraint could annotate a template-id which doesn't end up being a type-constraint, in which case control flow would incorrectly flow into ParseImplicitInt. Reenter the loop in this case. Enable relevant tests for C++20. This required disabling typo-correction during TryAnnotateTypeConstraint and changing a test case which is broken due to a separate bug (will be reported and handled separately).
2020-03-13[Sema] Fix location of star ('*') inside MemberPointerTypeLocMarcel Hlopko1-3/+3
Summary: Copy of https://reviews.llvm.org/D72073?id=235842, submitting with ilya-biryukov's permission. Reviewers: gribozavr, gribozavr2 Reviewed By: gribozavr2 Subscribers: mgorny, gribozavr2, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76061
2020-01-31[Concepts] Fix isDeclarationSpecifier to detect type-constraints correctlySaar Raz1-3/+8
isDeclarationSpecifiers did not handle some cases of placeholder-type-specifiers with type-constraints, causing parsing bugs in abbreviated constructor templates. Add comprehensive handling of type-constraints to isDeclarationSpecifier.
2020-01-28[clang][CodeComplete] Support for designated initializersKadir Cetinkaya1-0/+1
Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73271