aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/Parser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2015-07-19[modules] Don't save uninteresting identifiers, and don't consider identifiersRichard Smith1-1/+1
to be interesting just because they are the name of a builtin. Reduces the size of an empty module by over 80% (~100KB). llvm-svn: 242650
2015-07-07C++ support for Objective-C lightweight generics.Douglas Gregor1-7/+48
Teach C++'s tentative parsing to handle specializations of Objective-C class types (e.g., NSArray<NSString *>) as well as Objective-C protocol qualifiers (id<NSCopying>) by extending type-annotation tokens to handle this case. As part of this, remove Objective-C protocol qualifiers from the declaration specifiers, which never really made sense: instead, provide Sema entry points to make them part of the type annotation token. Among other things, this properly diagnoses bogus types such as "<NSCopying> id" which should have been written as "id <NSCopying>". Implements template instantiation support for, e.g., NSArray<T>* in C++. Note that parameterized classes are not templates in the C++ sense, so that cannot (for example) be used as a template argument for a template template parameter. Part of rdar://problem/6294649. llvm-svn: 241545
2015-06-19Extend type nullability qualifiers for Objective-C.Douglas Gregor1-0/+4
Introduce context-sensitive, non-underscored nullability specifiers (nonnull, nullable, null_unspecified) for Objective-C method return types, method parameter types, and properties. Introduce Objective-C-specific semantics, including computation of the nullability of the result of a message send, merging of nullability information from the @interface of a class into its @implementation, etc . This is the Objective-C part of rdar://problem/18868820. llvm-svn: 240154
2015-05-17Don't leak TemplateIds when a plugin parses late-parsed templates at TU end.Nico Weber1-20/+29
In -fdelayed-template-parsing mode, templates that aren't used are not parsed at all. For some diagnostic plugins, this is a problem since they want to analyse the contents of the template function body. What has been suggested on cfe-dev [1] is to explicitly parse interesting templates in HandleTranslationUnit(); IWYU does this for example [2]. This is workable, but since the delayed parsing doesn't run below a call to ParseTopLevelDecl(), no DestroyTemplateIdAnnotationsRAIIObj object is on the stack to clean up TemplateIds that are created during parsing. To fix this, let ~Parser() clean them up in delayed template parsing mode instead of leaking (or asserting in +Assert builds). (r219810, relanded in r220400, fixed the same problem in incremental processing mode; the review thread of r219810 has a good discussion of the problem.) To test this, give the PrintFunctionNames plugin a flag to force parsing of a template and add a test that uses it in -fdelayed-template-parsing mode. Without the Parser.cpp change, that test asserts. 1: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-August/038415.html 2: https://code.google.com/p/include-what-you-use/source/detail?r=566 llvm-svn: 237531
2015-05-15[modules] Add local submodule visibility support for declarations.Richard Smith1-1/+7
With this change, enabling -fmodules-local-submodule-visibility results in name visibility rules being applied to submodules of the current module in addition to imported modules (that is, names no longer "leak" between submodules of the same top-level module). This also makes it much safer to textually include a non-modular library into a module: each submodule that textually includes that library will get its own "copy" of that library, and so the library becomes visible no matter which including submodule you import. llvm-svn: 237473
2015-05-12Allow empty assembly string literal with -fno-gnu-inline-asmSteven Wu1-4/+9
Empty assembly string will not introduce assembly code in the output binary and it is often used as a trick in the header to disable optimizations. It doesn't conflict with the purpose of the option so it is allowed with -fno-gnu-inline-asm flag. llvm-svn: 237073
2015-05-11Allow AsmLabel with -fno-gnu-inline-asmSteven Wu1-4/+5
Summary: AsmLabel is heavily used in system level and firmware to redirect function and access platform specific labels. They are also extensively used in system headers which makes this option unusable for many users. Since AsmLabel doesn't introduce any assembly code into the output binary, it shouldn't be considered as inline-asm. Reviewers: bob.wilson, rnk Reviewed By: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D9679 llvm-svn: 237048
2015-04-28Fix the typo in r236044. NFC.Steven Wu1-1/+1
llvm-svn: 236051
2015-04-28Fix -fno-gnu-inline-asm doesn't catch file scope asmSteven Wu1-0/+4
Summary: FileScopeAsm should be treated the same as funcion level inline asm. -fno-gnu-inline-asm should trigger an error if file scope asm is used. I missed this case from r226340. This should not affect ms-extension because it is not allowed in the file scope. Reviewers: bob.wilson, rnk Reviewed By: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D9328 llvm-svn: 236044
2015-03-12Sema: Don't emit a missing prototype warning for deleted functions.Benjamin Kramer1-1/+2
This is a bit more involved than I anticipated, so here's a breakdown of the changes: 1. Call ActOnFinishFunctionBody _after_ we parsed =default and =delete specifiers. Saying that we finished the body before parsing =default is just wrong. Changing this allows us to use isDefaulted and isDeleted on a decl in ActOnFinishFunctionBody. 2. Check for -Wmissing-prototypes after we parsed the function body. 3. Disable -Wmissing-prototypes when the Decl isDeleted. llvm-svn: 232040
2015-01-12Parse: Get rid of tok::cxx_defaultarg_end, use EOF insteadDavid Majnemer1-4/+0
I added setEofData/getEofData to solve this sort of problem back in r224505. Use the Param's decl to tell us if this is *our* EOF token. llvm-svn: 225619
2015-01-12Parse: It's cleaner to handle cxx_defaultarg_end in SkipUntil directlyDavid Majnemer1-1/+5
llvm-svn: 225616
2015-01-12Parse: Don't let BalancedDelimiterTracker consume cxx_defaultarg_endDavid Majnemer1-1/+1
It is not correct to let it consume the cxx_defaultarg_end token. I'm starting to wonder if it makes more sense to stop SkipUntil from consuming such tokens. llvm-svn: 225615
2015-01-04Wrap to 80 columns, no behavior change.Nico Weber1-4/+5
llvm-svn: 225122
2014-12-15Diagnose function template definitions inside functionsReid Kleckner1-1/+1
The parser can only be tricked into parsing a function template definition by inserting a typename keyword before the function template declaration. This used to make us crash, and now it's fixed. While here, remove an unneeded boolean parameter from ParseDeclGroup. This boolean always corresponded to non-typedef declarators at file scope. ParseDeclGroup already has precise diagnostics for the function definition typedef case, so we can let that through. Fixes PR21839. llvm-svn: 224287
2014-12-11Parse: Concatenated string literals should be verified in inline asmDavid Majnemer1-16/+13
While we would correctly handle asm("foo") and reject asm(L"bar"), we weren't careful to handle cases where an ascii literal could be concatenated with a wide literal. This fixes PR21822. llvm-svn: 223992
2014-11-24Fix crash when using __if_exists in C modeNico Rieck1-2/+3
llvm-svn: 222665
2014-11-11[OPENMP] Codegen for threadprivate variablesAlexey Bataev1-2/+1
For all threadprivate variables which have constructor/destructor emit call to void __kmpc_threadprivate_register(ident_t * <Current Location>, void *<Original Global Addr>, kmpc_ctor <Constructor>, kmpc_cctor NULL, kmpc_dtor <Destructor>); In expressions all references to such variables are replaced by calls to void *__kmpc_threadprivate_cached(ident_t *<Current Location>, kmp_int32 <Current Thread Id>, void *<Original Global Addr>, size_t <Size of Data>, void ***<Pointer to autogenerated cache – array of private copies of threadprivate variable>); Test test/OpenMP/threadprivate_codegen.cpp checks that codegen is correct. Also it checks that codegen is correct after serialization/deserialization and one of passes verifies debug info. Differential Revision: http://reviews.llvm.org/D4002 llvm-svn: 221663
2014-10-31Remove a couple typedefs for things in the clang namespace with the same ↵Craig Topper1-2/+2
name. Remove a typedef that matches an identical one in the clang namespace. llvm-svn: 220954
2014-10-27Pass around CorrectionCandidateCallbacks as unique_ptrs soKaelyn Takata1-4/+4
TypoCorrectionConsumer can keep the callback around as long as needed. llvm-svn: 220693
2014-10-22Reland r219810 "Fix late template parsing leak with incremental processing"Reid Kleckner1-1/+11
Original message: Add a second late template parser callback meant to cleanup any resources allocated by late template parsing. Call it from the Sema::ActOnEndOfTranslationUnit method after all pending template instantiations have been completed. Teach Parser::ParseTopLevelDecl to install the cleanup callback when incremental processing is enabled so that Parser::TemplateIds can be freed. Patch by Brad King! llvm-svn: 220400
2014-10-22Remove unused StmtVector& parameters from declaration parsing functions.Rafael Espindola1-8/+4
Patch by Eelis van der Weegen! llvm-svn: 220387
2014-10-15Revert "Fix late template parsing leak with incremental processing"Reid Kleckner1-11/+1
This reverts commit r219810. The test suite appears broken. llvm-svn: 219813
2014-10-15Fix late template parsing leak with incremental processingReid Kleckner1-1/+11
Add a second late template parser callback meant to cleanup any resources allocated by late template parsing. Call it from the Sema::ActOnEndOfTranslationUnit method after all pending template instantiations have been completed. Teach Parser::ParseTopLevelDecl to install the cleanup callback when incremental processing is enabled so that Parser::TemplateIds can be freed. Patch by Brad King! llvm-svn: 219810
2014-09-26-ms-extensions: Implement __super scope specifier (PR13236).Nikola Smiljanic1-5/+7
We build a NestedNameSpecifier that records the CXXRecordDecl in which __super appeared. Name lookup is performed in all base classes of the recorded CXXRecordDecl. Use of __super is allowed only inside class and member function scope. llvm-svn: 218484
2014-09-23Revert r197496, as it broke REVERTIBLE_TYPE_TRAITs from PCH files.Nico Weber1-21/+3
Also add a test to make sure that this doesn't break again. Fixes PR21036. llvm-svn: 218292
2014-09-03Parse: Replace polymorphic functor objects with lambdas and llvm::function_ref.Benjamin Kramer1-7/+0
No change in functionality. llvm-svn: 217025
2014-07-22-fms-extensions: Implement half of #pragma init_segReid Kleckner1-1/+1
Summary: This pragma is very rare. We could *hypothetically* lower some uses of it down to @llvm.global_ctors, but given that GlobalOpt isn't able to optimize prioritized global ctors today, there's really no point. If we wanted to do this in the future, I would check if the section used in the pragma started with ".CRT$XC" and had up to two characters after it. Those two characters could form the 16-bit initialization priority that we support in @llvm.global_ctors. We would have to teach LLVM to lower prioritized global ctors on COFF as well. This should let us compile some silly uses of this pragma in WebKit / Blink. Reviewers: rsmith, majnemer Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4549 llvm-svn: 213593
2014-05-21[C++11] Use 'nullptr'. Parser edition.Craig Topper1-31/+34
llvm-svn: 209275
2014-05-03Rewrite NRVO determination. Track NRVO candidates on the parser Scope and ↵Nick Lewycky1-2/+1
apply the NRVO candidate flag to all possible NRVO candidates here, and remove the flags in computeNRVO or upon template instantiation. A variable now has NRVO applied if and only if every return statement in that scope returns that variable. This is nearly optimal. Performs NRVO roughly 7% more often in a bootstrap build of clang. Patch co-authored by Richard Smith. llvm-svn: 207890
2014-05-02Cut off parsing early during code completionAlp Toker1-2/+1
These calls to ConsumeCodeCompletionToken() caused parsing to continue needlessly when an immediate cutOffParsing() would do. Document the function to clarify its correct usage. llvm-svn: 207823
2014-04-08[MS-ABI] Add support for #pragma section and related pragmasWarren Hunt1-0/+3
This patch adds support for the msvc pragmas section, bss_seg, code_seg, const_seg and data_seg as well as support for __declspec(allocate()). Additionally it corrects semantics and adds diagnostics for __attribute__((section())) and the interaction between the attribute and the msvc pragmas and declspec. In general conflicts should now be well diganosed within and among these features. In supporting the pragmas new machinery for uniform lexing for msvc pragmas was introduced. The new machinery always lexes the entire pragma and stores it on an annotation token. The parser is responsible for parsing the pragma when the handling the annotation token. There is a known outstanding bug in this implementation in C mode. Because these attributes and pragmas apply _only_ to definitions, we process them at the time we detect a definition. Due to tentative definitions in C, we end up processing the definition late. This means that in C mode, everything that ends up in a BSS section will end up in the _last_ BSS section rather than the one that was live at the time of tentative definition, even if that turns out to be the point of actual definition. This issue is not known to impact anything as of yet because we are not aware of a clear use or use case for #pragma bss_seg but should be fixed at some point. Differential Revision=http://reviews.llvm.org/D3065#inline-16241 llvm-svn: 205810
2014-03-12Fix crash if delayed template parsing meets an erroneous trailing return type.Richard Smith1-24/+4
Based on a patch and test by Stephan Tolksdorf! Refactoring and fixing adjacent brokenness by me. llvm-svn: 203733
2014-03-12[C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper1-1/+1
class. llvm-svn: 203641
2014-02-26argument -> parameter terminology fixes for FunctionTypeInfoAlp Toker1-4/+4
This is a continuation of r199686. llvm-svn: 202307
2014-02-23Fix crash when both ExpectAndConsume and ConsumeAnyToken emit diagnosticsAlp Toker1-10/+12
The DiagnosticBuilder's lifetime in parser typo recovery was overlapping with the subsequent consume which can itself emit PP diagnostics. Patch by Olivier Goffart! llvm-svn: 201965
2014-02-20Hide pragma handler classes in ParsePragma.cppReid Kleckner1-89/+2
This reduces the number of files we need to touch to add a new pragma, and reduces the number of externally visible symbols in clang. Make the handlers structs instead of classes because the vast majority have no private members. Reviewers: rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D2834 llvm-svn: 201820
2014-02-17PR18870: Parse language linkage specifiers properly if the string-literal isRichard Smith1-2/+1
spelled in an interesting way. llvm-svn: 201536
2014-02-12MS ABI: Implement #pragma vtordisp() and clang-cl /vdNReid Kleckner1-0/+7
These features are new in VS 2013 and are necessary in order to layout std::ostream correctly. Currently we have an ABI incompatibility when self-hosting with the 2013 stdlib in our convertible_fwd_ostream wrapper in gtest. This change adds another implicit attribute, MSVtorDispAttr, because implicit attributes are currently the best way to make sure the information stays on class templates through instantiation. Reviewers: majnemer Differential Revision: http://llvm-reviews.chandlerc.com/D2746 llvm-svn: 201274
2014-02-10MS ABI: Add support for #pragma pointers_to_membersDavid Majnemer1-0/+7
Introduce a notion of a 'current representation method' for pointers-to-members. When starting out, this is set to 'best case' (representation method is chosen by examining the class, selecting the smallest representation that would work given the class definition or lack thereof). This pragma allows the translation unit to dictate exactly what representation to use, similar to how the inheritance model keywords operate. N.B. PCH support is forthcoming. Differential Revision: http://llvm-reviews.chandlerc.com/D2723 llvm-svn: 201105
2014-01-27Add a new attribute meta-spelling called "GCC" -- it widens into being a GNU ↵Aaron Ballman1-1/+1
spelling, and a CXX11 spelling with the namespace "gnu". It also sets a bit on the spelling certifying that it is known to GCC. From this, we can warn about the extension appropriately. As a consequence, the FunctionDefinition functionality is completely removed. Replacing the functionality from r199676, which didn't solve the problem as elegantly. llvm-svn: 200252
2014-01-22Introduce and use Decl::getAsFunction() to simplify templated function checksAlp Toker1-6/+1
Lift the getFunctionDecl() utility out of the parser into a general Decl::getAsFunction() and use it to simplify other parts of the implementation. Reduce isFunctionOrFunctionTemplate() to a simple type check that works the same was as the other is* functions and move unwrapping of shadowed decls to callers so it doesn't get run twice. Shuffle around canSkipFunctionBody() to reduce virtual dispatch on ASTConsumer. There's no need to query when we already know the body can't be skipped. llvm-svn: 199794
2014-01-20Remove some hard-coded specialness for thread-safety attributes from the ↵Aaron Ballman1-1/+1
parser, and made it more declarative. If an attribute is allowed to appear on a function definition when late parsed, it can now use the FunctionDefinition attribute subject. It's treated as a FunctionDecl for most purposes, except it also gets exposed on the AttributeList so that it can be used while parsing. llvm-svn: 199676
2014-01-15Fix for PR9812: warn about bool instead of _Bool.Erik Verbruggen1-3/+8
llvm-svn: 199311
2014-01-14Rename language option MicrosoftMode to MSVCCompatAlp Toker1-1/+1
There's been long-standing confusion over the role of these two options. This commit makes the necessary changes to differentiate them clearly, following up from r198936. MicrosoftExt (aka. fms-extensions): Enable largely unobjectionable Microsoft language extensions to ease portability. This mode, also supported by gcc, is used for building software like FreeBSD and Linux kernel extensions that share code with Windows drivers. MSVCCompat (aka. -fms-compatibility, formerly MicrosoftMode): Turn on a special mode supporting 'heinous' extensions for drop-in compatibility with the Microsoft Visual C++ product. Standards-compilant C and C++ code isn't guaranteed to work in this mode. Implies MicrosoftExt. Note that full -fms-compatibility mode is currently enabled by default on the Windows target, which may need tuning to serve as a reasonable default. See cfe-commits for the full discourse, thread 'r198497 - Move MS predefined type_info out of InitializePredefinedMacros' No change in behaviour. llvm-svn: 199209
2014-01-06Rename getTokenSimpleSpelling() to getPunctuatorSpelling()Alp Toker1-2/+2
That's what it does, what the documentation says it does and what callers expect it to do. llvm-svn: 198603
2014-01-05Tweak the parse recovery in r198540Alp Toker1-3/+8
Cover a hypothetical case when we might not have reached the final argument declaration for some reason during recovery, and split out for readability. llvm-svn: 198542
2014-01-05Fix bungled parse recovery in K&R function declarationsAlp Toker1-6/+3
void knrNoSemi(i) int i { } Adherents of The C Programming Language unfortunate enough to miss a semicolon as above would be met with a cascade of errors spanning the remainder of the TU. This patch introduces a beautiful parse error recovery, complete with helpful FixIt to restore sanity. Before (output redacted for brevity): error: 'error' diagnostics seen but not expected: File declarators.c Line 119: declaration does not declare a parameter File declarators.c Line 123: declaration does not declare a parameter File declarators.c Line 127: parameter named 'func_E12' is missing File declarators.c Line 127: expected ';' at end of declaration File declarators.c Line 133: parameter named 'func_E13' is missing File declarators.c Line 133: expected ';' at end of declaration File declarators.c Line 139: parameter named 'func_E14' is missing File declarators.c Line 139: expected ';' at end of declaration File declarators.c Line 145: parameter named 'func_E15' is missing File declarators.c Line 145: expected ';' at end of declaration File declarators.c Line 150: expected function body after function declarator File declarators.c Line 119: declaration of 'enum E11' will not be visible outside of this function File declarators.c Line 123: declaration of 'enum E12' will not be visible outside of this function File declarators.c Line 133: ISO C forbids forward references to 'enum' types File declarators.c Line 133: declaration of 'enum E13' will not be visible outside of this function File declarators.c Line 139: ISO C forbids forward references to 'enum' types File declarators.c Line 139: declaration of 'enum E14' will not be visible outside of this function File declarators.c Line 145: ISO C forbids forward references to 'enum' types File declarators.c Line 145: declaration of 'enum E15' will not be visible outside of this function ... After: declarators.c:103:24: error: expected ';' at end of declaration void knrNoSemi(i) int i { } ^ ; Patch found in a sealed envelope dated 1978 with the message "Do not open until January 2014" llvm-svn: 198540
2014-01-05Parse: Token consumption modernization and loop de-nestingAlp Toker1-2/+1
Cleanup only. llvm-svn: 198539
2014-01-02Using the quoted version of an attribute name for consistency with other ↵Aaron Ballman1-1/+1
attribute diagnostics. llvm-svn: 198326