summaryrefslogtreecommitdiff
path: root/lib/Lex/PPLexerChange.cpp
AgeCommit message (Collapse)Author
2018-01-24Merging r323008:Hans Wennborg
------------------------------------------------------------------------ r323008 | vsapsai | 2018-01-20 00:41:47 +0100 (Sat, 20 Jan 2018) | 32 lines [Lex] Fix crash on code completion in comment in included file. This fixes PR32732 by updating CurLexerKind to reflect available lexers. We were hitting null pointer in Preprocessor::Lex because CurLexerKind was CLK_Lexer but CurLexer was null. And we set it to null in Preprocessor::HandleEndOfFile when exiting a file with code completion point. To reproduce the crash it is important for a comment to be inside a class specifier. In this case in Parser::ParseClassSpecifier we improve error recovery by pushing a semicolon token back into the preprocessor and later on try to lex a token because we haven't reached the end of file. Also clang crashes only on code completion in included file, i.e. when IncludeMacroStack is not empty. Though we reset CurLexer even if include stack is empty. The difference is that during pushing back a semicolon token, preprocessor calls EnterCachingLexMode which decides it is already in caching mode because various lexers are null and IncludeMacroStack is not empty. As the result, CurLexerKind remains CLK_Lexer instead of updating to CLK_CachingLexer. rdar://problem/34787685 Reviewers: akyrtzi, doug.gregor, arphaman Reviewed By: arphaman Subscribers: cfe-commits, kfunk, arphaman, nemanjai, kbarton Differential Revision: https://reviews.llvm.org/D41688 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_60@323333 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18Another attempt to fix warning discovered by r313487. [-Wunused-lambda-capture]Vitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313521 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18Revert rL313511, "Fix a warning discovered by rL313487. ↵NAKAMURA Takumi
[-Wunused-lambda-capture]" It was incompatible to msc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313513 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18Fix a warning discovered by rL313487. [-Wunused-lambda-capture]NAKAMURA Takumi
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313511 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-18Reformat.NAKAMURA Takumi
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313510 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-21Fixed a crash on replaying Preamble's PP conditional stack.Ilya Biryukov
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/trunk@311330 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-05Fix invalid warnings for header guards in preamblesErik Verbruggen
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
2017-05-30Allow for unfinished #if blocks in preamblesErik Verbruggen
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
2017-05-19[modules] Simplify module macro handling in non-local-submodule-visibility mode.Richard Smith
When reaching the end of a module, we used to convert its macros to ModuleMacros but also leave them in the MacroDirective chain for the identifier. This meant that every lookup of such a macro would find two (identical) definitions. It also made it difficult to determine the correct owner for a macro when reaching the end of a module: the most recent MacroDirective in the chain could be from an #included submodule rather than the current module. Simplify this: whenever we convert a MacroDirective to a ModuleMacro when leaving a module, clear out the MacroDirective chain for that identifier, and just rely on the ModuleMacro to provide the macro definition information. (We don't want to do this for local submodule visibility mode, because in that mode we maintain a distinct MacroDirective chain for each submodule, and we need to keep around the prior MacroDirective in case we re-enter the submodule -- for instance, if its header is #included more than once in a module build, we need the include guard directive to stick around. But the problem doesn't arise in this case for the same reason: each submodule has its own MacroDirective chain, so the macros don't leak out of submodules in the first place.) This reinstates r302932, reverted in r302947, with a fix for a bug that resulted in us sometimes losing macro definitions due to failing to clear out the overridden module macro list when promoting a directive to a module macro. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303468 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-12Revert r302932, as it appears to be breaking stage2 for some of our ↵Richard Smith
modules-enabled buildbots. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302947 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-12[modules] Simplify module macro handling in non-local-submodule-visibility mode.Richard Smith
When reaching the end of a module, we used to convert its macros to ModuleMacros but also leave them in the MacroDirective chain for the identifier. This meant that every lookup of such a macro would find two (identical) definitions. It also made it difficult to determine the correct owner for a macro when reaching the end of a module: the most recent MacroDirective in the chain could be from an #included submodule rather than the current module. Simplify this: whenever we convert a MacroDirective to a ModuleMacro when leaving a module, clear out the MacroDirective chain for that identifier, and just rely on the ModuleMacro to provide the macro definition information. (We don't want to do this for local submodule visibility mode, because in that mode we maintain a distinct MacroDirective chain for each submodule, and we need to keep around the prior MacroDirective in case we re-enter the submodule -- for instance, if its header is #included more than once in a module build, we need the include guard directive to stick around. But the problem doesn't arise in this case for the same reason: each submodule has its own MacroDirective chain, so the macros don't leak out of submodules in the first place.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302932 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-04Add #pragma clang module begin/end pragmas and generate them when ↵Richard Smith
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
2017-04-27[Modules] Improve diagnostics for incomplete umbrellaBruno Cardoso Lopes
One of the -Wincomplete-umbrella warnings diagnoses when a header is present in the directory but it's not present in the umbrella header. Currently, this warning only happens on top level modules; any submodule using an umbrella header does not get this warning. Fix that by also considering the submodules. Differential Revision: https://reviews.llvm.org/D32576 rdar://problem/22623686 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301597 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-27[Modules] Refactor logic for incomplete umbrella warnings. NFCBruno Cardoso Lopes
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301596 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-16Use setUsedForHeaderGuard() accessor function instead of direcly accessing ↵Yaron Keren
UsedForHeaderGuard. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300423 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-27Fix MSVC warning about missing 'this' from lambda default capture modeSimon Pilgrim
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285281 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-26[PP] Replace some index based for loops with range based onesErik Verbruggen
While in the area, also change some unsigned variables to size_t, and introduce an LLVM_FALLTHROUGH instead of a comment stating that. Differential Revision: http://reviews.llvm.org/D25982 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285193 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26C++ Modules TS: add frontend support for building pcm files from moduleRichard Smith
interface files. At the moment, all declarations (and no macros) are exported, and 'export' declarations are not supported yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279794 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-23PR24667: fix quadratic runtime if textually-included modular headers define ↵Richard Smith
large numbers of macros. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261705 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-19[modules] Do less scanning of macro definition chains when computing the set ofRichard Smith
exported module macros outside local submodule visibility mode. Related to PR24667. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261373 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-29Emit a -Wmicrosoft warning when pasting /##/ into a comment token in MS mode.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256595 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18Replace SM.getFileEntryForID(Lexer->getFileID()) with Lexer->getFileEntry().Yaron Keren
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255993 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-07Remove spaces in empty line, NFC.Yaron Keren
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252405 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-02Sink some PTHManager includes out of Preprocessor.hReid Kleckner
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
2015-10-20Roll-back r250822.Angel Garcia Gomez
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250827 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250822 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30[modules] Make sure macros get made visible in the top-level file if we've gotRichard Smith
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
2015-06-19Introduced pragmas for audited nullability regions.Douglas Gregor
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
2015-05-21Avoid using a C++11 library feature not present in libstdc++4.7.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237872 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-21[modules] If we re-enter a submodule from within itself (when submoduleRichard Smith
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
2015-05-16[modules] Retain the name as written for umbrella headers and directories, ↵Richard Smith
rather than converting to an absolute path. No observable change expected, but this allows us to correctly compute the module for an umbrella header, which later changes will require. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237508 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15[modules] Add local submodule visibility support for declarations.Richard Smith
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237473 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-14[modules] Rearrange preprocessor module visibility handling, no observable ↵Richard Smith
change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237331 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-02[modules] Don't bother creating a ModuleMacro representing a #undef that ↵Richard Smith
overrides nothing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236374 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-02[modules] If a module #includes a modular header that #undef's its macro, itRichard Smith
should not export the macro. ... at least, not unless we have local submodule visibility enabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236369 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-01[modules] Add -fmodules-local-submodule-visibility flag.Richard Smith
This flag specifies that the normal visibility rules should be used even for local submodules (submodules of the currently-being-built module). Thus names will only be visible if a header / module that declares them has actually been included / imported, and not merely because a submodule that happened to be built earlier declared those names. This also removes the need to modularize bottom-up: textually-included headers will be included into every submodule that includes them, since their include guards will not leak between modules. So far, this only governs visibility of macros, not of declarations, so is not ready for real use yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236350 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-01[modules] Start moving the module visibility information off the Module itself.Richard Smith
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236300 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-29[modules] Stop trying to fake up a linear MacroDirective history.Richard Smith
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236176 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-28Refactor to make MacroState ownership and lifetime clearer.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236032 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-27[modules] Incrementally compute the list of overridden module macros based onRichard Smith
the active module macros at the point of definition, rather than reconstructing it from the macro history. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235941 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-24Remove unused variable to silence GCC warningDavid Majnemer
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235693 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-24[modules] Partial revert of r235669: don't create ModuleMacros for imported ↵Richard Smith
local macros. The surrounding infrastructure isn't quite ready for this yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235677 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-23[modules] Refactor creation of ModuleMacros and create them when importing ↵Richard Smith
from local submodules. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235669 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-23[modules] Properly attribute macros to modules if they're in a file ↵Richard Smith
textually included into a file in the module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235661 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-23[modules] Determine the set of macros exported by a submodule at the end of ↵Richard Smith
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235614 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-05Remove superceded warning warn_forgotten_module_headerBen Langmuir
This DefaultIgnore warning under -Wincomplete-module was firing on any module map files that happened to be parsed (it's only supposed to fire on headers), and it has been superceded by -Wnon-modular-include-in-module anyway. For compatibility, I rewired -Wincomplete-module to imply -Wnon-modular-include-in-module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221357 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-22[modules] Add support for 'textual header' directives.Richard Smith
This allows a module to specify that it logically contains a file, but that said file is non-modular and intended for textual inclusion. This allows layering checks to work properly in the presence of such files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220448 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-23PR18793: If we try to EnterTokenStream when our current lexer is a cachingRichard Smith
lexer, add the token buffer underneath the caching lexer where possible and push the tokens directly into the caching lexer otherwise. We previously put the lexer into a corrupted state where we could not guarantee to provide the tokens in the right order and would sometimes assert. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218333 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-29unique_ptrify Preprocessor's TokenLexerCacheDavid Blaikie
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216756 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-30Removed unused typedef for recursive_directory_iteratorBen Langmuir
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212047 91177308-0d34-0410-b5e6-96231b3b80d8