summaryrefslogtreecommitdiffstats
path: root/include/clang/Lex/Preprocessor.h
Commit message (Collapse)AuthorAgeFilesLines
* Merging r311330:Hans Wennborg2017-08-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | ------------------------------------------------------------------------ r311330 | ibiryukov | 2017-08-21 05:03:08 -0700 (Mon, 21 Aug 2017) | 16 lines Fixed a crash on replaying Preamble's PP conditional stack. Summary: The crash occurs when the first token after a preamble is a macro expansion. Fixed by moving replayPreambleConditionalStack from Parser into Preprocessor. It is now called right after the predefines file is processed. Reviewers: erikjv, bkramer, klimek, yvvan Reviewed By: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36872 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_50@311591 91177308-0d34-0410-b5e6-96231b3b80d8
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-171-3/+16
| | | | | | | | | | | | | | | | | rename Arguments to Parameters in Macro Definitions. - Extracted the reading of the tokens out into a separate function. - Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation). This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible. I will also directly update some extra clang tooling that is broken by the change from Argument to Parameter. Hopefully the bots will stay appeased. Thanks! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308190 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert changes from my previous refactoring - will need to fix dependencies ↵Faisal Vali2017-07-171-16/+3
| | | | | | | | | in clang's extra tooling (such as clang-tidy etc.). Sorry about that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308158 91177308-0d34-0410-b5e6-96231b3b80d8
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-171-3/+16
| | | | | | | | | | | | | | rename Arguments to Parameters in Macro Definitions. - Extracted the reading of the tokens out into a separate function. - Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation). This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible. Thanks! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308157 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix invalid warnings for header guards in preamblesErik Verbruggen2017-07-051-5/+4
| | | | | | | | | | Fixes https://bugs.llvm.org/show_bug.cgi?id=33574 Differential Revision: https://reviews.llvm.org/D34882 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307134 91177308-0d34-0410-b5e6-96231b3b80d8
* [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, ↵Argyrios Kyrtzidis2017-06-201-2/+11
| | | | | | | | | | parse all directive blocks if the condition uses undefined macros This is useful for being able to parse the preprocessor directive blocks even if the header, that defined the macro that is checked, hasn't been included. Differential Revision: https://reviews.llvm.org/D34263 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305797 91177308-0d34-0410-b5e6-96231b3b80d8
* Add #pragma clang module build/endbuild pragmas for performing a module buildRichard Smith2017-06-091-0/+1
| | | | | | | | | | | | | | | | as part of a compilation. This is intended for two purposes: 1) Writing self-contained test cases for modules: we can now write a single source file test that builds some number of module files on the side and imports them. 2) Debugging / test case reduction. A single-source testcase is much more amenable to reduction, compared to a VFS tarball or .pcm files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305101 91177308-0d34-0410-b5e6-96231b3b80d8
* Factor out and unify emission of "module is unavailable" diagnostics.Richard Smith2017-06-051-0/+7
| | | | | | | Inspired by post-commit review of r304190. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304728 91177308-0d34-0410-b5e6-96231b3b80d8
* Allow for unfinished #if blocks in preamblesErik Verbruggen2017-05-301-0/+64
| | | | | | | | | | | | | | | | | | | | | Previously, a preamble only included #if blocks (and friends like ifdef) if there was a corresponding #endif before any declaration or definition. The problem is that any header file that uses include guards will not have a preamble generated, which can make code-completion very slow. To prevent errors about unbalanced preprocessor conditionals in the preamble, and unbalanced preprocessor conditionals after a preamble containing unfinished conditionals, the conditional stack is stored in the pch file. This fixes PR26045. Differential Revision: http://reviews.llvm.org/D15994 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304207 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove last (unnecessary) use of mapping from SourceLocation to Module andRichard Smith2017-05-191-4/+2
| | | | | | | | | | remove the mechanism for doing so. This mechanism was incorrect in the presence of preprocessed modules (and #pragma clang module begin/end). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303469 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unused tracking of owning module for MacroInfo objects.Richard Smith2017-05-121-15/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302966 91177308-0d34-0410-b5e6-96231b3b80d8
* Add #pragma clang module begin/end pragmas and generate them when ↵Richard Smith2017-05-041-14/+17
| | | | | | | | | | | | | | | preprocessing a module. These pragmas are intended to simulate the effect of entering or leaving a file with an associated module. This is not completely implemented yet: declarations between the pragmas will not be attributed to the correct module, but macro visibility is already functional. Modules named by #pragma clang module begin must already be known to clang (in some module map that's either loaded or on the search path). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302098 91177308-0d34-0410-b5e6-96231b3b80d8
* Add pragma to perform module import and use it in -E output.Richard Smith2017-04-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | Many of our supported configurations support modules but do not have any first-class syntax to perform a module import. This leaves us with a problem: there is no way to represent the expansion of a #include that imports a module in the -E output for such languages. (We don't want to just leave it as a #include because that requires the consumer of the preprocessed source to have the same file system layout and include paths as the creator.) This patch adds a new pragma: #pragma clang module import MODULE.NAME.HERE that imports a module, and changes -E and -frewrite-includes to use it when rewriting a #include that maps to a module import. We don't make any attempt to use a native language syntax import if one exists, to get more consistent output. (If in the future, @import and #include have different semantics in some way, the pragma will track the #include semantics.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301725 91177308-0d34-0410-b5e6-96231b3b80d8
* [Modules] Refactor logic for incomplete umbrella warnings. NFCBruno Cardoso Lopes2017-04-271-0/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301596 91177308-0d34-0410-b5e6-96231b3b80d8
* Preprocessor: Suppress -Wnonportable-include-path for header mapsDuncan P. N. Exon Smith2017-04-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a file search involves a header map, suppress -Wnonportable-include-path. It's firing lots of false positives for framework authors internally, and it's not trivial to fix. Consider a framework called "Foo" with a main (installed) framework header "Foo/Foo.h". It's atypical for "Foo.h" to actually live inside a directory called "Foo" in the source repository. Instead, the build system generates a header map while building the framework. If Foo.h lives at the top-level of the source repository (common), and the git repo is called ssh://some.url/foo.git, then the header map will have something like: Foo/Foo.h -> /Users/myname/code/foo/Foo.h where "/Users/myname/code/foo" is the clone of ssh://some.url/foo.git. After #import <Foo/Foo.h>, the current implementation of -Wnonportable-include-path will falsely assume that Foo.h was found in a nonportable way, because of the name of the git clone (.../foo/Foo.h). However, that directory name was not involved in the header search at all. This commit adds an extra parameter to Preprocessor::LookupFile and HeaderSearch::LookupFile to track if the search used a header map, making it easy to suppress the warning. Longer term, once we find a way to avoid the false positive, we should turn the warning back on. rdar://problem/28863903 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301592 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply "Modules: Cache PCMs in memory and avoid a use-after-free"Duncan P. N. Exon Smith2017-03-201-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit r298185, effectively reapplying r298165, after fixing the new unit tests (PR32338). The memory buffer generator doesn't null-terminate the MemoryBuffer it creates; this version of the commit informs getMemBuffer about that to avoid the assert. Original commit message follows: ---- Clang's internal build system for implicit modules uses lock files to ensure that after a process writes a PCM it will read the same one back in (without contention from other -cc1 commands). Since PCMs are read from disk repeatedly while invalidating, building, and importing, the lock is not released quickly. Furthermore, the LockFileManager is not robust in every environment. Other -cc1 commands can stall until timeout (after about eight minutes). This commit changes the lock file from being necessary for correctness to a (possibly dubious) performance hack. The remaining benefit is to reduce duplicate work in competing -cc1 commands which depend on the same module. Follow-up commits will change the internal build system to continue after a timeout, and reduce the timeout. Perhaps we should reconsider blocking at all. This also fixes a use-after-free, when one part of a compilation validates a PCM and starts using it, and another tries to swap out the PCM for something new. The PCMCache is a new type called MemoryBufferCache, which saves memory buffers based on their filename. Its ownership is shared by the CompilerInstance and ModuleManager. - The ModuleManager stores PCMs there that it loads from disk, never touching the disk if the cache is hot. - When modules fail to validate, they're removed from the cache. - When a CompilerInstance is spawned to build a new module, each already-loaded PCM is assumed to be valid, and is frozen to avoid the use-after-free. - Any newly-built module is written directly to the cache to avoid the round-trip to the filesystem, making lock files unnecessary for correctness. Original patch by Manman Ren; most testcases by Adrian Prantl! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298278 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "Modules: Cache PCMs in memory and avoid a use-after-free"Renato Golin2017-03-181-4/+0
| | | | | | This reverts commit r298165, as it broke the ARM builds. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298185 91177308-0d34-0410-b5e6-96231b3b80d8
* Modules: Cache PCMs in memory and avoid a use-after-freeDuncan P. N. Exon Smith2017-03-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang's internal build system for implicit modules uses lock files to ensure that after a process writes a PCM it will read the same one back in (without contention from other -cc1 commands). Since PCMs are read from disk repeatedly while invalidating, building, and importing, the lock is not released quickly. Furthermore, the LockFileManager is not robust in every environment. Other -cc1 commands can stall until timeout (after about eight minutes). This commit changes the lock file from being necessary for correctness to a (possibly dubious) performance hack. The remaining benefit is to reduce duplicate work in competing -cc1 commands which depend on the same module. Follow-up commits will change the internal build system to continue after a timeout, and reduce the timeout. Perhaps we should reconsider blocking at all. This also fixes a use-after-free, when one part of a compilation validates a PCM and starts using it, and another tries to swap out the PCM for something new. The PCMCache is a new type called MemoryBufferCache, which saves memory buffers based on their filename. Its ownership is shared by the CompilerInstance and ModuleManager. - The ModuleManager stores PCMs there that it loads from disk, never touching the disk if the cache is hot. - When modules fail to validate, they're removed from the cache. - When a CompilerInstance is spawned to build a new module, each already-loaded PCM is assumed to be valid, and is frozen to avoid the use-after-free. - Any newly-built module is written directly to the cache to avoid the round-trip to the filesystem, making lock files unnecessary for correctness. Original patch by Manman Ren; most testcases by Adrian Prantl! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298165 91177308-0d34-0410-b5e6-96231b3b80d8
* [Preprocessor] Fix incorrect token caching that occurs when lexing _PragmaAlex Lorenz2017-02-241-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in macro argument pre-expansion mode when skipping a function body This commit fixes a token caching problem that currently occurs when clang is skipping a function body (e.g. when looking for a code completion token) and at the same time caching the tokens for _Pragma when lexing it in macro argument pre-expansion mode. When _Pragma is being lexed in macro argument pre-expansion mode, it caches the tokens so that it can avoid interpreting the pragma immediately (as the macro argument may not be used in the macro body), and then either backtracks over or commits these tokens. The problem is that, when we're backtracking/committing in such a scenario, there's already a previous backtracking position stored in BacktrackPositions (as we're skipping the function body), and this leads to a situation where the cached tokens from the pragma (like '(' 'string_literal' and ')') will remain in the cached tokens array incorrectly even after they're consumed (in the case of backtracking) or just ignored (in the case when they're committed). Furthermore, what makes it even worse, is that because of a previous backtracking position, the logic that deals with when should we call ExitCachingLexMode in CachingLex no longer works for us in this situation, and more tokens in the macro argument get cached, to the point where the EOF token that corresponds to the macro argument EOF is cached. This problem leads to all sorts of issues in code completion mode, where incorrect errors get presented and code completion completely fails to produce completion results. rdar://28523863 Differential Revision: https://reviews.llvm.org/D28772 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296140 91177308-0d34-0410-b5e6-96231b3b80d8
* Move Preprocessor over to std::shared_ptr rather than IntrusiveRefCntPtrDavid Blaikie2017-01-051-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291166 91177308-0d34-0410-b5e6-96231b3b80d8
* Move PreprocessorOptions to std::shared_ptr from IntrusiveRefCntPtrDavid Blaikie2017-01-051-5/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291160 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't assert when redefining a built-in macro in a PCH, PR29119Nico Weber2016-12-091-1/+2
| | | | | | | | | | | | | | | | | PCH files store the macro history for a given macro, and the whole history list for one identifier is given to the Preprocessor at once via Preprocessor::setLoadedMacroDirective(). This contained an assert that no macro history exists yet for that identifier. That's usually true, but it's not true for builtin macros, which are created in Preprocessor() before flags and pchs are processed. Luckily, ASTWriter stops writing macro history lists at builtins (see shouldIgnoreMacro() in ASTWriter.cpp), so the head of the history list was missing for builtin macros. So make the assert weaker, and splice the history list to the existing single define for builtins. https://reviews.llvm.org/D27545 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289228 91177308-0d34-0410-b5e6-96231b3b80d8
* [PP] Remove another unused parameterErik Verbruggen2016-10-261-1/+1
| | | | | | | Differential Revision: http://reviews.llvm.org/D25981 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285188 91177308-0d34-0410-b5e6-96231b3b80d8
* PP: Remove unused parameters from methodsErik Verbruggen2016-10-261-3/+3
| | | | | | | | | NFC Differential Revision: http://reviews.llvm.org/D25938 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285180 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove move constructors that are identical to the generated default move ctor.Benjamin Kramer2016-10-211-8/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284856 91177308-0d34-0410-b5e6-96231b3b80d8
* Use noexcept instead of LLVM_NOEXCEPT now that all compilers support itReid Kleckner2016-10-191-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284667 91177308-0d34-0410-b5e6-96231b3b80d8
* PR28438: Update the information on an identifier with local definitions beforeRichard Smith2016-08-181-0/+6
| | | | | | | | | trying to write out its macro graph, in case we imported a module that added another module macro between the most recent local definition and the end of the module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279024 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply r276973 "Adjust Registry interface to not require plugins to export ↵John Brawn2016-08-051-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a registry" This differs from the previous version by being more careful about template instantiation/specialization in order to prevent errors when building with clang -Werror. Specifically: * begin is not defined in the template and is instead instantiated when Head is. I think the warning when we don't do that is wrong (PR28815) but for now at least do it this way to avoid the warning. * Instead of performing template specializations in LLVM_INSTANTIATE_REGISTRY instead provide a template definition then do explicit instantiation. No compiler I've tried has problems with doing it the other way, but strictly speaking it's not permitted by the C++ standard so better safe than sorry. Original commit message: Currently the Registry class contains the vestiges of a previous attempt to allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a plugin would have its own copy of a registry and export it to be imported by the tool that's loading the plugin. This only works if the plugin is entirely self-contained with the only interface between the plugin and tool being the registry, and in particular this conflicts with how IR pass plugins work. This patch changes things so that instead the add_node function of the registry is exported by the tool and then imported by the plugin, which solves this problem and also means that instead of every plugin having to export every registry they use instead LLVM only has to export the add_node functions. This allows plugins that use a registry to work on Windows if LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277806 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r276973 "Adjust Registry interface to not require plugins to export a ↵John Brawn2016-07-281-0/+2
| | | | | | | | | | registry" Buildbot failures when building with clang -Werror. Reverting while I try to figure this out. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277008 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply r276856 "Adjust Registry interface to not require plugins to export ↵John Brawn2016-07-281-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | a registry" This version has two fixes compared to the original: * In Registry.h the template static members are instantiated before they are used, as clang gives an error if you do it the other way around. * The use of the Registry template in clang-tidy is updated in the same way as has been done everywhere else. Original commit message: Currently the Registry class contains the vestiges of a previous attempt to allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a plugin would have its own copy of a registry and export it to be imported by the tool that's loading the plugin. This only works if the plugin is entirely self-contained with the only interface between the plugin and tool being the registry, and in particular this conflicts with how IR pass plugins work. This patch changes things so that instead the add_node function of the registry is exported by the tool and then imported by the plugin, which solves this problem and also means that instead of every plugin having to export every registry they use instead LLVM only has to export the add_node functions. This allows plugins that use a registry to work on Windows if LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276973 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement filtering for code completion of identifiers.Vassil Vassilev2016-07-271-0/+16
| | | | | | | | | Patch by Cristina Cristescu and Axel Naumann! Agreed on post commit review (D17820). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276878 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r276856 "Adjust Registry interface to not require plugins to export a ↵John Brawn2016-07-271-0/+2
| | | | | | | | | registry" This is causing a huge pile of buildbot failures. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276857 91177308-0d34-0410-b5e6-96231b3b80d8
* Adjust Registry interface to not require plugins to export a registryJohn Brawn2016-07-271-2/+0
| | | | | | | | | | | | | | | | | | | | | Currently the Registry class contains the vestiges of a previous attempt to allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a plugin would have its own copy of a registry and export it to be imported by the tool that's loading the plugin. This only works if the plugin is entirely self-contained with the only interface between the plugin and tool being the registry, and in particular this conflicts with how IR pass plugins work. This patch changes things so that instead the add_node function of the registry is exported by the tool and then imported by the plugin, which solves this problem and also means that instead of every plugin having to export every registry they use instead LLVM only has to export the add_node functions. This allows plugins that use a registry to work on Windows if LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used. Differential Revision: http://reviews.llvm.org/D21385 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276856 91177308-0d34-0410-b5e6-96231b3b80d8
* [modules] When diagnosing a missing module import, suggest adding a #include ifRichard Smith2016-04-271-0/+13
| | | | | | | | the current language doesn't have an import syntax and we can figure out a suitable file to include. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267802 91177308-0d34-0410-b5e6-96231b3b80d8
* AnnotateFunctions: Tweak for mingw.NAKAMURA Takumi2016-04-041-0/+2
| | | | | | | - Externalize the registry. - Update libdeps. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265301 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a PragmaHandler Registry for plugins to add PragmaHandlers toJohn Brawn2016-04-041-0/+4
| | | | | | | | | | | This allows plugins which add AST passes to also define pragmas to do things like only enable certain behaviour of the AST pass in files where a certain pragma is used. Differential Revision: http://reviews.llvm.org/D18319 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265295 91177308-0d34-0410-b5e6-96231b3b80d8
* PR24667: fix quadratic runtime if textually-included modular headers define ↵Richard Smith2016-02-231-3/+13
| | | | | | large numbers of macros. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261705 91177308-0d34-0410-b5e6-96231b3b80d8
* Simplify EnterTokenStream API to make it more robust for memory managementDavid Blaikie2016-02-091-1/+11
| | | | | | | | | | | | | | | While this won't help fix things like the bug that r260219 addressed, it seems like good tidy up to have anyway. (it might be nice if "makeArrayRef" always produced a MutableArrayRef & let it decay to an ArrayRef when needed - then I'd use that for the MutableArrayRefs in this patch) If we had std::dynarray I'd use that instead of unique_ptr+size_t, ideally (but then it'd have to be threaded down through the Preprocessor all the way - no idea how painful that would be) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260246 91177308-0d34-0410-b5e6-96231b3b80d8
* [Parser] Update CachedTokens while parsing ObjectiveC template argument listBruno Cardoso Lopes2016-01-311-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider the following ObjC++ snippet: -- @protocol PA; @protocol PB; @class NSArray<ObjectType>; typedef int some_t; id<PA> FA(NSArray<id<PB>> *h, some_t group); -- This would hit an assertion in the parser after generating an annotation token while trying to update the token cache: Assertion failed: (CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token") ... 7 clang::Preprocessor::AnnotatePreviousCachedTokens(clang::Token const&) + 494 8 clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool, bool, clang::CXXScopeSpec&, bool) + 1163 9 clang::Parser::TryAnnotateTypeOrScopeToken(bool, bool) + 361 10 clang::Parser::isCXXDeclarationSpecifier(clang::Parser::TPResult, bool*) + 598 ... The cached preprocessor token in this case is: greatergreater '>>' Loc=<testcase.mm:7:24> while the annotation ("NSArray<id<PB>>") ends at "testcase.mm:7:25", hence the assertion. Properly update the CachedTokens during template parsing to contain two greater tokens instead of a greatergreater. Differential Revision: http://reviews.llvm.org/D15173 rdar://problem/23494277 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259311 91177308-0d34-0410-b5e6-96231b3b80d8
* Sink some PTHManager includes out of Preprocessor.hReid Kleckner2015-11-021-1/+1
| | | | | | | This reduces the number of .cpp files needed to be rebuilt after touching OnDiskHashTable from 120 to 21 for me. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251810 91177308-0d34-0410-b5e6-96231b3b80d8
* [CUDA] Allow parsing of host and device code simultaneously.Artem Belevich2015-09-221-1/+6
| | | | | | | | | | | | * adds -aux-triple option to specify target triple * propagates aux target info to AST context and Preprocessor * pulls in target specific preprocessor macros. * pulls in target-specific builtins from aux target. * sets appropriate host or device attribute on builtins. Differential Revision: http://reviews.llvm.org/D12917 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248299 91177308-0d34-0410-b5e6-96231b3b80d8
* [modules] When checking the include guard for a header, check whether it'sRichard Smith2015-07-101-0/+16
| | | | | | | | | | | visible in the module we're considering entering. Previously we assumed that if we knew the include guard for a modular header, we'd already parsed it, but that need not be the case if a header is present in the current module and one of its dependencies; the result of getting this wrong was that the current module's submodule for the header would end up empty. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241953 91177308-0d34-0410-b5e6-96231b3b80d8
* [modules] Make sure macros get made visible in the top-level file if we've gotRichard Smith2015-06-301-1/+3
| | | | | | | | local submodule visibility enabled; that top-level file might not actually be the module includes buffer if use of prebuilt modules is disabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241120 91177308-0d34-0410-b5e6-96231b3b80d8
* [modules] Fix findDirectiveAtLoc to not call a member function on a null ↵Richard Smith2015-06-251-1/+3
| | | | | | | | | | | | pointer. This is exercised by existing tests, and fixes a failure with -fsanitize=null. No observable change otherwise; the code happened to do the right thing in practice under recent versions of Clang and GCC because MacroDirective::getDefinition happens to check whether this == null. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240691 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduced pragmas for audited nullability regions.Douglas Gregor2015-06-191-0/+18
| | | | | | | | | | | | | | | | | Introduce the clang pragmas "assume_nonnull begin" and "assume_nonnull end" in which we make default assumptions about the nullability of many unannotated pointers: - Single-level pointers are inferred to __nonnull - NSError** in a (function or method) parameter list is inferred to NSError * __nullable * __nullable. - CFErrorRef * in a (function or method) parameter list is inferred to CFErrorRef __nullable * __nullable. - Other multi-level pointers are never inferred to anything. Implements rdar://problem/19191042. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240156 91177308-0d34-0410-b5e6-96231b3b80d8
* push_back() loop -> append() for random access iterators.Benjamin Kramer2015-06-121-2/+3
| | | | | | | append will resize the vector to the optimal size. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239607 91177308-0d34-0410-b5e6-96231b3b80d8
* Replace a few std::string& with StringRef. NFC.Rafael Espindola2015-06-011-1/+1
| | | | | | Patch by Косов Евгений! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238774 91177308-0d34-0410-b5e6-96231b3b80d8
* Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial typesBenjamin Kramer2015-05-291-2/+2
| | | | | | | | | | | | | | | | | | | | If the type isn't trivially moveable emplace can skip a potentially expensive move. It also saves a couple of characters. Call sites were found with the ASTMatcher + some semi-automated cleanup. memberCallExpr( argumentCountIs(1), callee(methodDecl(hasName("push_back"))), on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))), hasArgument(0, bindTemporaryExpr( hasType(recordDecl(hasNonTrivialDestructor())), has(constructExpr()))), unless(isInTemplateInstantiation())) No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238601 91177308-0d34-0410-b5e6-96231b3b80d8
* [modules] If we re-enter a submodule from within itself (when submoduleRichard Smith2015-05-211-17/+31
| | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237871 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor: when exposing a definition in some module, provide listeners with theRichard Smith2015-05-151-0/+2
| | | | | | | module rather than requiring them to work it out themselves. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237416 91177308-0d34-0410-b5e6-96231b3b80d8