summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/Preprocessor.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [modules] If we re-enter a submodule from within itself (when submoduleRichard Smith2015-05-211-6/+11
| | | | | | | | | | visibility is enabled) or leave and re-enter it, restore the macro and module visibility state from last time we were in that submodule. This allows mutually-#including header files to stand a chance at being modularized with local visibility enabled. llvm-svn: 237871
* Generalize future keyword compat diagnostics.Richard Smith2015-05-141-6/+24
| | | | | | | | | | | | This, in preparation for the introduction of more new keywords in the implementation of the C++ language, generalizes the support for future keyword compat diagnostics (e.g., diag::warn_cxx11_keyword) by extending the applicability of the relevant property in IdentifierTable with appropriate renaming. Patch by Hubert Tong! llvm-svn: 237332
* [modules] Rearrange preprocessor module visibility handling, no observable ↵Richard Smith2015-05-141-1/+1
| | | | | | change intended. llvm-svn: 237331
* [modules] Remove dead code from Module for tracking macro import locations.Richard Smith2015-05-021-1/+1
| | | | llvm-svn: 236376
* [modules] If a module #includes a modular header that #undef's its macro, itRichard Smith2015-05-021-4/+1
| | | | | | | | should not export the macro. ... at least, not unless we have local submodule visibility enabled. llvm-svn: 236369
* [modules] Start moving the module visibility information off the Module itself.Richard Smith2015-05-011-4/+22
| | | | | | | It has no place there; it's not a property of the Module, and it makes restoring the visibility set when we leave a submodule more difficult. llvm-svn: 236300
* Add an assert to get information on buildbot failure.Richard Smith2015-04-291-0/+1
| | | | llvm-svn: 236181
* [modules] Stop trying to fake up a linear MacroDirective history.Richard Smith2015-04-291-4/+6
| | | | | | | | | | | | | | Modules builds fundamentally have a non-linear macro history. In the interest of better source fidelity, represent the macro definition information faithfully: we have a linear macro directive history within each module, and at any point we have a unique "latest" local macro directive and a collection of visible imported directives. This also removes the attendent complexity of attempting to create a correct MacroDirective history (which we got wrong in the general case). No functionality change intended. llvm-svn: 236176
* Refactor to make MacroState ownership and lifetime clearer.Richard Smith2015-04-281-3/+0
| | | | llvm-svn: 236032
* Fix memory leak found by asan buildbot.Richard Smith2015-04-281-0/+3
| | | | llvm-svn: 235957
* [modules] Incrementally compute the list of overridden module macros based onRichard Smith2015-04-271-2/+5
| | | | | | | the active module macros at the point of definition, rather than reconstructing it from the macro history. No functionality change intended. llvm-svn: 235941
* [modules] Determine the set of macros exported by a submodule at the end of ↵Richard Smith2015-04-231-1/+1
| | | | | | | | | | | that submodule. Previously we'd defer this determination until writing the AST, which doesn't allow us to use this information when building other submodules of the same module. This change also allows us to use a uniform mechanism for writing module macro records, independent of whether they are local or imported. llvm-svn: 235614
* [Modules] Fix crash in Preprocessor::getLastMacroWithSpelling().Argyrios Kyrtzidis2015-03-041-3/+3
| | | | | | Macro names that got undefined inside a module may not have their MacroInfo set. llvm-svn: 231251
* Modified the Objective-C lexer and parser (only Sean Callanan2014-12-091-7/+10
| | | | | | | | | | | | | | | | in debugger mode) to accept @import declarations and pass them to the debugger. In the preprocessor, accept import declarations if the debugger is enabled, but don't actually load the module, just pass the import path on to the preprocessor callbacks. In the Objective-C parser, if it sees an import declaration in statement context (usual for LLDB), ignore it and return a NullStmt. llvm-svn: 223855
* [modules] Track how 'header' directives were written in module map files,Richard Smith2014-12-021-1/+1
| | | | | | | | | | | | | rather than trying to extract this information from the FileEntry after the fact. This has a number of beneficial effects. For instance, diagnostic messages for failed module builds give a path relative to the "module root" rather than an absolute file path, and the contents of the module includes file is no longer dependent on what files the including TU happened to inspect prior to triggering the module build. llvm-svn: 223095
* [libclang] If the code-completion point is inside the preamble, adjust the ↵Argyrios Kyrtzidis2014-10-181-0/+9
| | | | | | | | | position at the beginning of the file after the preamble. Otherwise we will not hit the code-completion point. llvm-svn: 220136
* [libclang] Allow code-completion when pointing at the end-of-file.Argyrios Kyrtzidis2014-10-181-15/+14
| | | | llvm-svn: 220135
* Unique_ptrify Preprocessor::PragmaHandlersBackupDavid Blaikie2014-09-151-2/+2
| | | | | | Follow up to r217656 llvm-svn: 217829
* Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor.Craig Topper2014-09-121-14/+8
| | | | llvm-svn: 217656
* Unique_ptrify PPCallbacks ownership.Craig Topper2014-09-101-3/+1
| | | | | | Unique_ptr creation stil needs to be moved earlier at some of the call sites. llvm-svn: 217474
* unique_ptrify Preprocessor's TokenLexerCacheDavid Blaikie2014-08-291-2/+1
| | | | llvm-svn: 216756
* unique_ptrify SourceManager::createFileIDDavid Blaikie2014-08-291-1/+1
| | | | llvm-svn: 216715
* Overload SourceManager::overrideFileContents so that unconditionally passing ↵David Blaikie2014-08-271-1/+1
| | | | | | | | | | ownership is explicitly done using unique_ptr. Only those callers who are dynamically passing ownership should need the 3 argument form. Those accepting the default ("do pass ownership") should do so explicitly with a unique_ptr now. llvm-svn: 216614
* Update for LLVM api change.Rafael Espindola2014-08-271-4/+4
| | | | llvm-svn: 216585
* Add support for the static analyzer to synthesize function implementations ↵Ted Kremenek2014-08-271-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | from external model files. Currently the analyzer lazily models some functions using 'BodyFarm', which constructs a fake function implementation that the analyzer can simulate that approximates the semantics of the function when it is called. BodyFarm does this by constructing the AST for such definitions on-the-fly. One strength of BodyFarm is that all symbols and types referenced by synthesized function bodies are contextual adapted to the containing translation unit. The downside is that these ASTs are hardcoded in Clang's own source code. A more scalable model is to allow these models to be defined as source code in separate "model" files and have the analyzer use those definitions lazily when a function body is needed. Among other things, it will allow more customization of the analyzer for specific APIs and platforms. This patch provides the initial infrastructure for this feature. It extends BodyFarm to use an abstract API 'CodeInjector' that can be used to synthesize function bodies. That 'CodeInjector' is implemented using a new 'ModelInjector' in libFrontend, which lazily parses a model file and injects the ASTs into the current translation unit. Models are currently found by specifying a 'model-path' as an analyzer option; if no path is specified the CodeInjector is not used, thus defaulting to the current behavior in the analyzer. Models currently contain a single function definition, and can be found by finding the file <function name>.model. This is an initial starting point for something more rich, but it bootstraps this feature for future evolution. This patch was contributed by Gábor Horváth as part of his Google Summer of Code project. Some notes: - This introduces the notion of a "model file" into FrontendAction and the Preprocessor. This nomenclature is specific to the static analyzer, but possibly could be generalized. Essentially these are sources pulled in exogenously from the principal translation. Preprocessor gets a 'InitializeForModelFile' and 'FinalizeForModelFile' which could possibly be hoisted out of Preprocessor if Preprocessor exposed a new API to change the PragmaHandlers and some other internal pieces. This can be revisited. FrontendAction gets a 'isModelParsingAction()' predicate function used to allow a new FrontendAction to recycle the Preprocessor and ASTContext. This name could probably be made something more general (i.e., not tied to 'model files') at the expense of losing the intent of why it exists. This can be revisited. - This is a moderate sized patch; it has gone through some amount of offline code review. Most of the changes to the non-analyzer parts are fairly small, and would make little sense without the analyzer changes. - Most of the analyzer changes are plumbing, with the interesting behavior being introduced by ModelInjector.cpp and ModelConsumer.cpp. - The new functionality introduced by this change is off-by-default. It requires an analyzer config option to enable. llvm-svn: 216550
* unique_ptr-ify FileSystemStatCache::setNextStatCacheDavid Blaikie2014-08-111-0/+1
| | | | | | | | | | And in the process, discover that FileManager::removeStatCache had a double-delete when removing an element from the middle of the list (at the beginning or the end of the list, there was no problem) and add a unit test to exercise the code path (which successfully crashed when run (with modifications to match the old API) without this patch applied) llvm-svn: 215388
* Simplify MacroInfo lifetime management. We don't need three different functionsRichard Smith2014-07-241-5/+9
| | | | | | to destroy one of these. llvm-svn: 213837
* Remove unused Prev pointer from MacroInfo chain.Richard Smith2014-07-241-2/+2
| | | | | | | | Remove pointless MICache: it only ever contained up to 1 object, and was only non-empty when recovering from an error. There's no performance or memory win from maintaining this cache. llvm-svn: 213825
* Convert StringLiteralParser constructor to use ArrayRef instead of a pointer ↵Craig Topper2014-06-261-1/+1
| | | | | | and count. llvm-svn: 211763
* [C++11] Use 'nullptr'.Craig Topper2014-06-091-2/+2
| | | | llvm-svn: 210448
* [C++11] Use 'nullptr'. Lex edition.Craig Topper2014-05-171-16/+19
| | | | llvm-svn: 209083
* Provide and use a safe Token::getRawIdentifier() accessorAlp Toker2014-05-171-3/+2
| | | | llvm-svn: 209061
* Rename SourceManager::createFileIDForMemBuffer()Alp Toker2014-05-161-1/+1
| | | | | | | | It makes more sense to just overload createFileID(). Gardening only. llvm-svn: 209002
* Don't leak MacroArgs when using code completion, PR19688.Nico Weber2014-05-091-1/+4
| | | | | | | | | | | | | | | | | | | | | | | MacroArgs are owned by TokenLexer, and when a TokenLexer is destroyed, it'll call its MacroArgs's destroy() method. destroy() only appends the MacroArg to Preprocessor's MacroArgCache list, and Preprocessor's destructor then calls deallocate() on all MacroArgs in that list. This method then ends up freeing the MacroArgs's memory. In a code completion context, Parser::cutOffParsing() gets called when a code completion token is hit, which changes the type of the current token to tok::eof. eof tokens aren't always ConsumeToken()ed, so Preprocessor::HandleEndOfFile() isn't always called, and that function is responsible for popping the macro stack. Due to this, Preprocessor::CurTokenLexer can be non-NULL when ~Preprocessor runs. It's a unique_ptr, so it ended up being destructed after ~Preprocessor completed, and its MacroArgs thus got added to the freelist after the code freeing things on the freelist had already completed. The fix is to explicitly call reset() before the freelist processing happens. (See the bug for more notes.) llvm-svn: 208438
* Reformat code following Preprocessor constructor updatesAlp Toker2014-05-021-6/+5
| | | | | | Landing this separately to make the previous commits easy to follow at home. llvm-svn: 207826
* Factor TargetInfo pointer/DelayInitialization bool pair out of Preprocessor ctorAlp Toker2014-05-021-8/+3
| | | | | | | | The Preprocessor::Initialize() function already offers a clear interface to achieve this, further reducing the confusing number of states a newly constructed preprocessor can have. llvm-svn: 207825
* Remove unused IncrProcessing parameter from Preprocessor ctorAlp Toker2014-05-021-3/+2
| | | | | | | Preprocessor::enableIncrementalProcessing() provides a consistent interface to enable the feature. llvm-svn: 207824
* Preprocessor: Clarify the ownership of the IncludeMacroStack with unique_ptr.Benjamin Kramer2014-03-151-5/+1
| | | | llvm-svn: 204007
* [Preprocessor] Pass TranslationUnitKind to the preprocessor and if it is ↵Argyrios Kyrtzidis2014-03-071-1/+3
| | | | | | | | | | TU_Prefix avoid warning for unused macros. rdar://15034698 llvm-svn: 203213
* Use a more conventional logical op instead of bitwise andAlp Toker2014-02-241-1/+1
| | | | llvm-svn: 202006
* PR18855: Add support for UCNs and UTF-8 encoding within ud-suffixes.Richard Smith2014-02-171-42/+0
| | | | llvm-svn: 201532
* MS ABI: Implement #pragma vtordisp() and clang-cl /vdNReid Kleckner2014-02-121-0/+18
| | | | | | | | | | | | | | | | | 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
* Track the currently-being-built submodule inside the preprocessor (rather thanRichard Smith2014-01-311-1/+1
| | | | | | | just storing a flag indicating if there was one), and include it in the 'end of module' annotation. No functionality change. llvm-svn: 200573
* Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth2014-01-071-2/+2
| | | | | | | encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. llvm-svn: 198686
* Generate a marker token when entering or leaving a submodule when building aRichard Smith2013-11-231-2/+2
| | | | | | | | | module. Use the marker to diagnose cases where we try to transition between submodules when not at the top level (most likely because a closing brace was missing at the end of a header file, but is also possible if submodule headers attempt to do something fundamentally non-modular, like our .def files). llvm-svn: 195543
* Modules: Teach the preprocessor to recognize 'import' only after an '@'.Douglas Gregor2013-11-071-3/+7
| | | | | | | | | | | | The preprocessor currently recognizes module declarations to load a module based on seeing the 'import' keyword followed by an identifier. This sequence is fairly unlikely in C (one would need a type named 'import'), but is more common in Objective-C (where a variable named 'import' can cause problems). Since import declarations currently require a leading '@', recognize that in the preprocessor as well. Fixes <rdar://problem/15084587>. llvm-svn: 194225
* Make Preprocessor::Lex non-recursive.Eli Friedman2013-09-191-3/+33
| | | | | | | | | | | | | | | Before this patch, Lex() would recurse whenever the current lexer changed (e.g. upon entry into a macro). This patch turns the recursion into a loop: the various lex routines now don't return a token when the current lexer changes, and at the top level Preprocessor::Lex() now loops until it finds a token. Normally, the recursion wouldn't end up being very deep, but the recursion depth can explode in edge cases like a bunch of consecutive macros which expand to nothing (like in the testcase test/Preprocessor/macro_expand_empty.c in this patch). <rdar://problem/14569770> llvm-svn: 190980
* Add option to disable module loading.Daniel Jasper2013-08-051-1/+1
| | | | | | | This patch was created by Lawrence Crowl and reviewed in: http://llvm-reviews.chandlerc.com/D963 llvm-svn: 187738
* [Preprocessor] For the MacroExpands preprocessor callback, also pass the ↵Argyrios Kyrtzidis2013-05-031-1/+1
| | | | | | | | MacroArgs object that provides information about the argument tokens for a function macro. llvm-svn: 181065
* [PCH] Fix memory leak related to deserialized MacroInfo objects.Argyrios Kyrtzidis2013-04-301-1/+5
| | | | | | | | | Deserialized MacroInfos were not destroyed and if their SmallVector did heap allocation, it was leaked. rdar://13768967 llvm-svn: 180771
OpenPOWER on IntegriCloud