aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex
AgeCommit message (Collapse)AuthorFilesLines
2017-07-05Fix invalid warnings for header guards in preamblesErik Verbruggen3-7/+3
Fixes https://bugs.llvm.org/show_bug.cgi?id=33574 Differential Revision: https://reviews.llvm.org/D34882 llvm-svn: 307134
2017-06-29Track the set of module maps read while building a .pcm file and reload ↵Richard Smith1-1/+2
those when preprocessing from that .pcm file. llvm-svn: 306628
2017-06-27[Sema] Allow unmarked overloadable functions.George Burgess IV1-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
2017-06-21[preprocessor] Fix assertion hit when 'SingleFileParseMode' option is ↵Argyrios Kyrtzidis1-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
2017-06-20[preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, ↵Argyrios Kyrtzidis2-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
2017-06-19Support non-identifier module names when preprocessing modules.Richard Smith1-26/+44
llvm-svn: 305758
2017-06-16[PR33394] Avoid lexing editor placeholders when Clang is used onlyAlex Lorenz1-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
2017-06-14[Preprocessor]Correct Macro-Arg allocation of StringifiedArguments, Erich Keane1-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
2017-06-09Support operator keywords used in Windows SDK(fix ubsan)Erich Keane1-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
2017-06-09Add #pragma clang module build/endbuild pragmas for performing a module buildRichard Smith1-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
2017-06-09support operator keywords used in Windows SDKErich Keane1-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
2017-06-09[libclang] Introduce a new parsing option ↵Argyrios Kyrtzidis1-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
2017-06-05Factor out and unify emission of "module is unavailable" diagnostics.Richard Smith2-27/+25
Inspired by post-commit review of r304190. llvm-svn: 304728
2017-06-03Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova1-0/+2
llvm-svn: 304643
2017-06-03Added LLVM_FALLTHROUGH to address warning: this statement may fall through + ↵Galina Kistanova1-4/+11
formatted. NFC. llvm-svn: 304642
2017-06-02Support lazy stat'ing of files referenced by module maps.Richard Smith3-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
2017-05-31[modules] When compiling a preprocessed module map, look for headers relativeRichard Smith1-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
2017-05-30Allow for unfinished #if blocks in preamblesErik Verbruggen3-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
2017-05-30Diagnose attempts to build a preprocessed module that defines an unavailable ↵Richard Smith1-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
2017-05-30[modules] When we #include a local submodule header that we've already built,Richard Smith1-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
2017-05-26Factor resolving of header directives -> files out of module map parser.Richard Smith1-97/+104
llvm-svn: 303945
2017-05-24Revert "Sema: allow imaginary constants via GNU extension if UDL overloads ↵Tim Northover1-20/+24
not present." This reverts commit r303697. It broke libc++ tests that were specifically checking incompatibility in C++14 mode. llvm-svn: 303813
2017-05-24Fix 'set but not used' [-Wunused-but-set-variable] warningSimon Pilgrim1-2/+0
llvm-svn: 303734
2017-05-24Change __has_feature(objc_diagnose_if_attr) to ↵Argyrios Kyrtzidis1-1/+1
__has_feature(attribute_diagnose_if_objc) for consistency with rest of attribute checks. llvm-svn: 303713
2017-05-24Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods ↵Argyrios Kyrtzidis1-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
2017-05-23Sema: allow imaginary constants via GNU extension if UDL overloads not present.Tim Northover1-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
2017-05-22Give files from #line the characteristics of the current fileReid Kleckner2-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
2017-05-19Remove last (unnecessary) use of mapping from SourceLocation to Module andRichard Smith2-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
2017-05-19[modules] Simplify module macro handling in non-local-submodule-visibility mode.Richard Smith1-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
2017-05-17[Lexer] Ensure that the token is not an annotation token whenAlex Lorenz1-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
2017-05-12Remove unused tracking of owning module for MacroInfo objects.Richard Smith3-33/+3
llvm-svn: 302966
2017-05-12Revert r302932, as it appears to be breaking stage2 for some of our ↵Richard Smith1-7/+12
modules-enabled buildbots. llvm-svn: 302947
2017-05-12[modules] Simplify module macro handling in non-local-submodule-visibility mode.Richard Smith1-12/+7
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.) llvm-svn: 302932
2017-05-09[Modules] Allow umbrella frameworks to define private submodules for ↵Bruno Cardoso Lopes1-2/+4
subframeworks In r298391 we fixed the umbrella framework model to work when submodules named "Private" are used. This complements the work by allowing the umbrella framework model to work in general. rdar://problem/31790067 llvm-svn: 302491
2017-05-08If we are building a module, and we read a second description of the sameRichard Smith1-1/+13
module from a different module map, ignore it. This happens during builds of preprocessed modules (where it is harmless). llvm-svn: 302463
2017-05-05Permit keywords in module names in #pragma clang module *.Richard Smith1-1/+1
This is necessary to be able to build a libc++ module from preprocessed source (due to the submodule std.new). llvm-svn: 302312
2017-05-05Add support for building modules from preprocessed source.Richard Smith2-13/+55
To support this, an optional marker "#pragma clang module contents" is recognized in module map files, and the rest of the module map file from that point onwards is treated as the source of the module. Preprocessing a module map produces the input module followed by the marker and then the preprocessed contents of the module. Ignoring line markers, a preprocessed module might look like this: module A { header "a.h" } #pragma clang module contents #pragma clang module begin A // ... a.h ... #pragma clang module end The preprocessed output generates line markers, which are not accepted by the module map parser, so -x c++-module-map-cpp-output should be used to compile such outputs. A couple of major parts do not work yet: 1) The files that are listed in the module map must exist on disk, in order to build the on-disk header -> module lookup table in the PCM file. To fix this, we need the preprocessed output to track the file size and other stat information we might use to build the lookup table. 2) Declaration ownership semantics don't work properly yet, since mapping from a source location to a module relies on mapping from FileIDs to modules, which we can't do if module transitions can occur in the middle of a file. llvm-svn: 302309
2017-05-05Add a fix-it for -Wunguarded-availabilityAlex Lorenz1-17/+49
This patch adds a fix-it for the -Wunguarded-availability warning. This fix-it is similar to the Swift one: it suggests that you wrap the statement in an `if (@available)` check. The produced fixits are indented (just like the Swift ones) to make them look nice in Xcode's fix-it preview. rdar://31680358 Differential Revision: https://reviews.llvm.org/D32424 llvm-svn: 302253
2017-05-04Fix whitespace before token-paste of an argument.James Y Knight1-12/+18
The whitespace should come from the argument name in the macro expansion, rather than from the token passed to the macro (same as it does when not pasting). Added a new test case for the change in behavior to stringize_space.c. FileCheck'ized macro_paste_commaext.c, tweaked the test case, and added a comment; no behavioral change to this test. Differential Revision: https://reviews.llvm.org/D30427 llvm-svn: 302195
2017-05-04Add #pragma clang module begin/end pragmas and generate them when ↵Richard Smith5-66/+176
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). llvm-svn: 302098
2017-04-29Add pragma to perform module import and use it in -E output.Richard Smith2-8/+68
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.) llvm-svn: 301725
2017-04-27[Modules] Improve diagnostics for incomplete umbrellaBruno Cardoso Lopes1-4/+17
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 llvm-svn: 301597
2017-04-27[Modules] Refactor logic for incomplete umbrella warnings. NFCBruno Cardoso Lopes1-37/+36
llvm-svn: 301596
2017-04-27Preprocessor: Suppress -Wnonportable-include-path for header mapsDuncan P. N. Exon Smith4-21/+24
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 llvm-svn: 301592
2017-04-27Constify SourceManager input to MacroInfo::getDefinitionLengthSlow, NFC.Yaron Keren1-1/+1
llvm-svn: 301526
2017-04-26Revert "Revert "PPCallbacks::MacroUndefined, change signature and add test.""Vedant Kumar2-15/+17
This reverts commit r301469. It isn't needed with r301470, which fixes the API break introduced in the original commit. llvm-svn: 301472
2017-04-26Revert "PPCallbacks::MacroUndefined, change signature and add test."Vedant Kumar2-17/+15
This reverts commit r301449. It breaks the build with: MacroPPCallbacks.h:114:50: error: non-virtual member function marked 'override' hides virtual member function llvm-svn: 301469
2017-04-26PPCallbacks::MacroUndefined, change signature and add test.Frederich Munch2-15/+17
Summary: The PPCallbacks::MacroUndefined callback is currently insufficient for clients that need to track the MacroDirectives. This patch adds an additional argument to PPCallbacks::MacroUndefined that is the undef MacroDirective. Reviewers: bruno, manmanren Reviewed By: bruno Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D29923 llvm-svn: 301449
2017-04-24[modules ts] Diagnose 'export' declarations outside of a module interface.Richard Smith1-0/+1
llvm-svn: 301271
2017-04-24Pragma: Fix DebugOverflowStack() resulting in endless loop.Matthias Braun1-3/+3
Drive-by fix (noticed while working on https://reviews.llvm.org/D32205): DebugOverflowStack() is supposed to provoke a stack overflow, however LLVM was smart enough to use the red-zone and fold the load into a tail jump on x86_64 optimizing this to an endless loop instead of a stack overflow. llvm-svn: 301218