summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
Commit message (Collapse)AuthorAgeFilesLines
...
* [modules] Add ability to specify module name to module file mapping (reapply)Boris Kolpackov2017-08-311-9/+14
| | | | | | | | | | | | | | | | | | | | Extend the -fmodule-file option to support the [<name>=]<file> value format. If the name is omitted, then the old semantics is preserved (the module file is loaded whether needed or not). If the name is specified, then the mapping is treated as just another prebuilt module search mechanism, similar to -fprebuilt-module-path, and the module file is only loaded if actually used (e.g., via import). With one exception: this mapping also overrides module file references embedded in other modules (which can be useful if module files are moved/renamed as often happens during remote compilation). This override semantics requires some extra work: we now store the module name in addition to the file name in the serialized AST representation. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D35020 llvm-svn: 312220
* Revert r312105 [modules] Add ability to specify module name to module file ↵Victor Leschuk2017-08-301-14/+9
| | | | | | | | mapping Looks like it breaks win10 builder. llvm-svn: 312112
* [modules] Add ability to specify module name to module file mappingBoris Kolpackov2017-08-301-9/+14
| | | | | | | | | | | | | | | | | | | | Extend the -fmodule-file option to support the [<name>=]<file> value format. If the name is omitted, then the old semantics is preserved (the module file is loaded whether needed or not). If the name is specified, then the mapping is treated as just another prebuilt module search mechanism, similar to -fprebuilt-module-path, and the module file is only loaded if actually used (e.g., via import). With one exception: this mapping also overrides module file references embedded in other modules (which can be useful if module files are moved/renamed as often happens during remote compilation). This override semantics requires some extra work: we now store the module name in addition to the file name in the serialized AST representation. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D35020 llvm-svn: 312105
* [Preprocessor] Correct internal token parsing of newline characters in CRLFErich Keane2017-08-241-0/+2
| | | | | | | | | | | | | | | | | | | | Discovered due to a goofy git setup, the test system-headerline-directive.c (and a few others) failed because the token-consumption will consume only the '\r' in CRLF, making the preprocessor's printed value give the wrong line number when returning from an include. For example: (line 1):#include <noline.h>\r\n The "file exit" code causes the printer to try to print the 'returned to the main file' line. It looks up what the current line number is. However, since the current 'token' is the '\n' (since only the \r was consumed), it will give the line number as '1", not '2'. This results in a few failed tests, but more importantly, results in error messages being incorrect when compiling a previously preprocessed file. Differential Revision: https://reviews.llvm.org/D37079 llvm-svn: 311683
* Fixed a crash on replaying Preamble's PP conditional stack.Ilya Biryukov2017-08-212-1/+14
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 311330
* Rename cxx1z -> cxx17 across all diagnostic IDs.Richard Smith2017-08-131-1/+1
| | | | llvm-svn: 310805
* [c++2a] Treat 'concept' and 'requires' as keywords, add compat warning for ↵Richard Smith2017-08-131-0/+2
| | | | | | C++17 and before. llvm-svn: 310803
* Revert "[Modules] Prevent #import to reenter header if not building a module."Bruno Cardoso Lopes2017-08-121-1/+1
| | | | | | | This reverts commit r310605. Richard pointed out a better way to achieve this, which I'll post a patch for soon. llvm-svn: 310775
* [Modules] Prevent #import to reenter header if not building a module.Bruno Cardoso Lopes2017-08-101-1/+1
| | | | | | | | | | When non-modular headers are imported while not building a module but in -fmodules mode, be conservative and preserve the default #import semantic: do not reenter headers. rdar://problem/33745031 llvm-svn: 310605
* [Lexer] Finding beginning of token with escaped new lineAlexander Kornienko2017-08-101-28/+44
| | | | | | | | | | | | | | | | | | | | Summary: Lexer::GetBeginningOfToken produced invalid location when backtracking across escaped new lines. This fixes PR26228 Reviewers: akyrtzi, alexfh, rsmith, doug.gregor Reviewed By: alexfh Subscribers: alexfh, cfe-commits Patch by Paweł Żukowski! Differential Revision: https://reviews.llvm.org/D30748 llvm-svn: 310576
* Reapply Sema: allow imaginary constants via GNU extension if UDL overloads ↵Tim Northover2017-08-091-24/+20
| | | | | | | | | | | | | | | | | | not present. C++14 added user-defined literal support for complex numbers so that you can write something like "complex<double> val = 2i". However, there is an existing GNU extension supporting this syntax and interpreting the result as a _Complex type. This changes parsing so that such literals are interpreted in terms of C++14's operators if an overload is present but otherwise falls back to the original GNU extension. (We now have more robust diagnostics for implicit conversions so the libc++ test that caused the original revert still passes). llvm-svn: 310478
* Revert "Lexer: always allow imaginary constants in GNU mode."Tim Northover2017-08-081-1/+1
| | | | | | | This reverts r310423. It was committed by mistake, I intended to commit the improved diagnostics for implicit conversions instead. llvm-svn: 310426
* Lexer: always allow imaginary constants in GNU mode.Tim Northover2017-08-081-1/+1
| | | | llvm-svn: 310423
* PR33902: Invalidate line number cache when adding more text to existing buffer.Richard Smith2017-07-301-0/+8
| | | | | | | | This led to crashes as the line number cache would report a bogus line number for a line of code, and we'd try to find a nonexistent column within the line when printing diagnostics. llvm-svn: 309503
* [NFC] Use RAII to un-poison and then re-poison __VA_ARGS__Faisal Vali2017-07-251-13/+12
| | | | | | | - This will also be used for the forthcoming __VA_OPT__ feature approved for C++2a. - recommended by rsmith during his review of the __VA_OPT__ patch (https://reviews.llvm.org/D35782) llvm-svn: 308948
* [NFC] Update local variable names to upper-case as per LLVM Coding Standards.Faisal Vali2017-07-201-9/+9
| | | | llvm-svn: 308574
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-175-58/+75
| | | | | | | | | | | | | | | | | 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! llvm-svn: 308190
* Revert changes from my previous refactoring - will need to fix dependencies ↵Faisal Vali2017-07-175-75/+58
| | | | | | | | in clang's extra tooling (such as clang-tidy etc.). Sorry about that. llvm-svn: 308158
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-175-58/+75
| | | | | | | | | | | | | | 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! llvm-svn: 308157
* Keep the IdentifierInfo in the Token for alternative operator keywordOlivier Goffart2017-07-143-46/+35
| | | | | | | | | | | | | | | | | | | The goal of this commit is to fix clang-format so it does not merge tokens when using the alternative spelling keywords. (eg: "not foo" should not become "notfoo") The problem is that Preprocessor::HandleIdentifier used to drop the identifier info from the token for these keyword. This means the first condition of TokenAnnotator::spaceRequiredBefore is not met. We could add explicit check for the spelling in that condition, but I think it is better to keep the IdentifierInfo and handle the operator keyword explicitly when needed. That actually leads to simpler code, and probably slightly more efficient as well. Another side effect of this change is that __identifier(and) will now work as one would expect, removing a FIXME from the MicrosoftExtensions.cpp test Differential Revision: https://reviews.llvm.org/D35172 llvm-svn: 308008
* Fix invalid warnings for header guards in preamblesErik Verbruggen2017-07-053-7/+3
| | | | | | | | Fixes https://bugs.llvm.org/show_bug.cgi?id=33574 Differential Revision: https://reviews.llvm.org/D34882 llvm-svn: 307134
* Track the set of module maps read while building a .pcm file and reload ↵Richard Smith2017-06-291-1/+2
| | | | | | those when preprocessing from that .pcm file. llvm-svn: 306628
* [Sema] Allow unmarked overloadable functions.George Burgess IV2017-06-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch extends the `overloadable` attribute to allow for one function with a given name to not be marked with the `overloadable` attribute. The overload without the `overloadable` attribute will not have its name mangled. So, the following code is now legal: void foo(void) __attribute__((overloadable)); void foo(int); void foo(float) __attribute__((overloadable)); In addition, this patch fixes a bug where we'd accept code with `__attribute__((overloadable))` inconsistently applied. In other words, we used to accept: void foo(void); void foo(void) __attribute__((overloadable)); But we will do this no longer, since it defeats the original purpose of requiring `__attribute__((overloadable))` on all redeclarations of a function. This breakage seems to not be an issue in practice, since the only code I could find that had this pattern often looked like: void foo(void); void foo(void) __attribute__((overloadable)) __asm__("foo"); void foo(int) __attribute__((overloadable)); ...Which can now be simplified by simply removing the asm label and overloadable attribute from the redeclaration of `void foo(void);` Differential Revision: https://reviews.llvm.org/D32332 llvm-svn: 306467
* [preprocessor] Fix assertion hit when 'SingleFileParseMode' option is ↵Argyrios Kyrtzidis2017-06-211-6/+6
| | | | | | | | enabled and #if with an undefined identifier and without #else 'HandleEndifDirective' asserts that 'WasSkipping' is false, so switch to using 'FoundNonSkip' as the hint for 'SingleFileParseMode' to keep going with parsing. llvm-svn: 305940
* [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, ↵Argyrios Kyrtzidis2017-06-202-14/+53
| | | | | | | | | | 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 llvm-svn: 305797
* Support non-identifier module names when preprocessing modules.Richard Smith2017-06-191-26/+44
| | | | llvm-svn: 305758
* [PR33394] Avoid lexing editor placeholders when Clang is used onlyAlex Lorenz2017-06-161-1/+2
| | | | | | | | | | | | | | | | for preprocessing r300667 added support for editor placeholder to Clang. That commit didn’t take into account that users who use Clang for preprocessing only (-E) will get the "editor placeholder in source file" error when preprocessing their source (PR33394). This commit ensures that Clang doesn't lex editor placeholders when running a preprocessor only action. rdar://32718000 Differential Revision: https://reviews.llvm.org/D34256 llvm-svn: 305576
* [Preprocessor]Correct Macro-Arg allocation of StringifiedArguments, Erich Keane2017-06-141-10/+10
| | | | | | | | | | | | | | | | | | | | | correct getNumArguments StringifiedArguments is allocated (resized) based on the size the getNumArguments function. However, this function ACTUALLY currently returns the amount of total UnexpArgTokens which is minimum the same as the new implementation of getNumMacroArguments, since empty/omitted arguments result in 1 UnexpArgToken, and included ones at minimum include 2 (1 for the arg itself, 1 for eof). This patch renames the otherwise unused getNumArguments to be more clear that it is the number of arguments that the Macro expects, and thus the maximum number that can be stringified. This patch also replaces the explicit memset (which results in value instantiation of the new tokens, PLUS clearing the memory) with brace initialization. Differential Revision: https://reviews.llvm.org/D32046 llvm-svn: 305425
* Support operator keywords used in Windows SDK(fix ubsan)Erich Keane2017-06-091-1/+3
| | | | | | | | | UBSan found an issue with a nullptr being assigned to a reference. This was because a following function went back and checked the identifier in the CPPOperatorName case. This patch corrects that location with the original logic as well. llvm-svn: 305128
* Add #pragma clang module build/endbuild pragmas for performing a module buildRichard Smith2017-06-091-0/+117
| | | | | | | | | | | | | | | 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. llvm-svn: 305101
* support operator keywords used in Windows SDKErich Keane2017-06-091-1/+5
| | | | | | | | | | | | | | | | | | to support operator keywords used in Windows SDK, alter token type when seen in system headers Hello, I submitted D33505 to address this problem, but the proposal was rejected as too big a hammer. This change will allow clang to parse the WindowsSDK header <query.h> which uses the operator name "or" as a field name. Treat cpp operator keywords as ordinary identifiers inside the Microsoft headers, but treat them as usual in the user's program. Original Submitter: Melanie Blower (mibintc) Differential Revision: https://reviews.llvm.org/D33782 llvm-svn: 305087
* [libclang] Introduce a new parsing option ↵Argyrios Kyrtzidis2017-06-091-1/+5
| | | | | | | | 'CXTranslationUnit_SingleFileParse' that puts preprocessor in a mode for parsing a single file only. This is useful for parsing a single file, as a fast/inaccurate 'mode' that can still provide declarations from the file, like the classes and their methods. llvm-svn: 305044
* Factor out and unify emission of "module is unavailable" diagnostics.Richard Smith2017-06-052-27/+25
| | | | | | Inspired by post-commit review of r304190. llvm-svn: 304728
* Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova2017-06-031-0/+2
| | | | llvm-svn: 304643
* Added LLVM_FALLTHROUGH to address warning: this statement may fall through + ↵Galina Kistanova2017-06-031-4/+11
| | | | | | formatted. NFC. llvm-svn: 304642
* Support lazy stat'ing of files referenced by module maps.Richard Smith2017-06-023-84/+254
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for a `header` declaration in a module map to specify certain `stat` information (currently, size and mtime) about that header file. This has two purposes: - It removes the need to eagerly `stat` every file referenced by a module map. Instead, we track a list of unresolved header files with each size / mtime (actually, for simplicity, we track submodules with such headers), and when attempting to look up a header file based on a `FileEntry`, we check if there are any unresolved header directives with that `FileEntry`'s size / mtime and perform deferred `stat`s if so. - It permits a preprocessed module to be compiled without the original files being present on disk. The only reason we used to need those files was to get the `stat` information in order to do header -> module lookups when using the module. If we're provided with the `stat` information in the preprocessed module, we can avoid requiring the files to exist. Unlike most `header` directives, if a `header` directive with `stat` information has no corresponding on-disk file the enclosing module is *not* marked unavailable (so that behavior is consistent regardless of whether we've resolved a header directive, and so that preprocessed modules don't get marked unavailable). We could actually do this for all `header` directives: the only reason we mark the module unavailable if headers are missing is to give a diagnostic slightly earlier (rather than waiting until we actually try to build the module / load and validate its .pcm file). Differential Revision: https://reviews.llvm.org/D33703 llvm-svn: 304515
* [modules] When compiling a preprocessed module map, look for headers relativeRichard Smith2017-05-311-2/+15
| | | | | | | | | | | | to the original module map. Also use the path and name of the original module map when emitting that information into the .pcm file. The upshot of this is that the produced .pcm file will track information for headers in their original locations (where the module was preprocessed), not relative to whatever directory the preprocessed module map was in when it was built. llvm-svn: 304346
* Allow for unfinished #if blocks in preamblesErik Verbruggen2017-05-303-28/+26
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 304207
* Diagnose attempts to build a preprocessed module that defines an unavailable ↵Richard Smith2017-05-301-0/+18
| | | | | | | | | submodule. The errors we would otherwise get are incomprehensible, as we would enter the module but not make its contents visible to itself. llvm-svn: 304190
* [modules] When we #include a local submodule header that we've already built,Richard Smith2017-05-301-20/+21
| | | | | | | | | | and it has an include guard, produce callbacks for a module import, not for a skipped non-modular header. Fixes -E output when preprocessing a module to list these cases as a module import, rather than suppressing the #include and losing the import side effect. llvm-svn: 304183
* Factor resolving of header directives -> files out of module map parser.Richard Smith2017-05-261-97/+104
| | | | llvm-svn: 303945
* Revert "Sema: allow imaginary constants via GNU extension if UDL overloads ↵Tim Northover2017-05-241-20/+24
| | | | | | | | | not present." This reverts commit r303697. It broke libc++ tests that were specifically checking incompatibility in C++14 mode. llvm-svn: 303813
* Fix 'set but not used' [-Wunused-but-set-variable] warningSimon Pilgrim2017-05-241-2/+0
| | | | llvm-svn: 303734
* Change __has_feature(objc_diagnose_if_attr) to ↵Argyrios Kyrtzidis2017-05-241-1/+1
| | | | | | __has_feature(attribute_diagnose_if_objc) for consistency with rest of attribute checks. llvm-svn: 303713
* Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods ↵Argyrios Kyrtzidis2017-05-241-0/+1
| | | | | | | | and properties as well This is an initial commit to allow using it with constant expressions, a follow-up commit will enable full support for it in ObjC methods. llvm-svn: 303712
* Sema: allow imaginary constants via GNU extension if UDL overloads not present.Tim Northover2017-05-231-25/+20
| | | | | | | | | | | | | C++14 added user-defined literal support for complex numbers so that you can write something like "complex<double> val = 2i". However, there is an existing GNU extension supporting this syntax and interpreting the result as a _Complex type. This changes parsing so that such literals are interpreted in terms of C++14's operators if an overload is present but otherwise falls back to the original GNU extension. llvm-svn: 303694
* Give files from #line the characteristics of the current fileReid Kleckner2017-05-222-22/+24
| | | | | | | | | | This allows #line directives to appear in system headers that have code that clang would normally warn on. This is compatible with GCC, which is easy to test by running `gcc -E`. Fixes PR30752 llvm-svn: 303582
* Remove last (unnecessary) use of mapping from SourceLocation to Module andRichard Smith2017-05-192-43/+3
| | | | | | | | | remove the mechanism for doing so. This mechanism was incorrect in the presence of preprocessed modules (and #pragma clang module begin/end). llvm-svn: 303469
* [modules] Simplify module macro handling in non-local-submodule-visibility mode.Richard Smith2017-05-191-12/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 303468
* [Lexer] Ensure that the token is not an annotation token whenAlex Lorenz2017-05-171-0/+4
| | | | | | | | | | | retrieving the identifer info for an Objective-C keyword This commit fixes an assertion that's triggered in getIdentifier when the token is an annotation token. rdar://32225463 llvm-svn: 303246
OpenPOWER on IntegriCloud