summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/Pragma.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [modules] Fix incorrect diagnostic mapping computation when a module changesRichard Smith2018-02-091-0/+14
| | | | | | | | | | | | | | | diagnostic settings using _Pragma within a macro. The AST writer had previously been assuming that all diagnostic state transitions would occur within a FileID corresponding to a file. When a diagnostic state change occured within a macro, it was unable to form a location for that state change and would instead corrupt the diagnostic state of the "root" node (and thus that of the main compilation). Also introduce a "#pragma clang __debug diag_mapping" debugging utility that I added to track this issue down. llvm-svn: 324695
* Always allow "#pragma region".Matt Davis2018-01-271-2/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Both MS and PS4 targets are capable of recognizing the existence of: #pragma region, #pragma endregion. Since this pragma is only a hint for certain editors, and has no logic, it seems helpful to permit this pragma in all cases, not just MS compatibility mode. Reviewers: rnk, rsmith, majnemer Reviewed By: majnemer Subscribers: Quuxplusone, probinson, majnemer, cfe-commits Differential Revision: https://reviews.llvm.org/D42248 llvm-svn: 323577
* Preserve unknown STDC pragma through preprocessorSteven Wu2018-01-051-55/+0
| | | | | | | | | | | | | | | | | | | Summary: #pragma STDC FP_CONTRACT handler is only registered in parser so we should keep the unknown STDC pragma through preprocessor and we also should not emit warning for unknown STDC pragma during preprocessor. rdar://problem/35724351 Reviewers: efriedma, rsmith, arphaman Reviewed By: efriedma Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D41780 llvm-svn: 321909
* [Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other ↵Eugene Zelenko2017-12-081-23/+26
| | | | | | minor fixes (NFC). llvm-svn: 320207
* [Preprocessor] Preserve #pragma clang assume_nonnull in preprocessed outputEli Friedman2017-09-271-0/+5
| | | | | | | | Patch by Zbigniew Sarbinowski! Differential Revision: https://reviews.llvm.org/D37861 llvm-svn: 314364
* Support non-identifier module names when preprocessing modules.Richard Smith2017-06-191-26/+44
| | | | llvm-svn: 305758
* 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
* Factor out and unify emission of "module is unavailable" diagnostics.Richard Smith2017-06-051-12/+2
| | | | | | Inspired by post-commit review of r304190. llvm-svn: 304728
* 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
* Give files from #line the characteristics of the current fileReid Kleckner2017-05-221-2/+2
| | | | | | | | | | 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
* Permit keywords in module names in #pragma clang module *.Richard Smith2017-05-051-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
* Add #pragma clang module begin/end pragmas and generate them when ↵Richard Smith2017-05-041-43/+124
| | | | | | | | | | | | | | 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
* Add pragma to perform module import and use it in -E output.Richard Smith2017-04-291-0/+59
| | | | | | | | | | | | | | | | | | | | | 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
* 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 llvm-svn: 301592
* Pragma: Fix DebugOverflowStack() resulting in endless loop.Matthias Braun2017-04-241-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
* [Preprocessor] Fix incorrect token caching that occurs when lexing _PragmaAlex Lorenz2017-02-241-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 296140
* Do not print include_next/pragma once warnings when input is a header.Erik Verbruggen2016-10-271-2/+4
| | | | | | | | | | | r276653 suppressed the pragma once warning when generating a PCH file. This patch extends that to any main file for which clang is told (with the -x option) that it's a header file. It will also suppress the warning "#include_next in primary source file". Differential Revision: http://reviews.llvm.org/D25989 llvm-svn: 285295
* [PP] Replace some index based for loops with range based onesErik Verbruggen2016-10-261-1/+1
| | | | | | | | | 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 llvm-svn: 285193
* [PP] Remove another unused parameterErik Verbruggen2016-10-261-2/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D25981 llvm-svn: 285188
* Fix some Clang-tidy modernize-use-using and Include What You Use warnings; ↵Eugene Zelenko2016-09-071-10/+42
| | | | | | | | other minor fixes. Differential revision: https://reviews.llvm.org/D24115 llvm-svn: 280870
* Support '#pragma once' in headers when using PCHSunil Srivastava2016-07-251-1/+3
| | | | | | | | | | | | | The '#pragma once' directive was erroneously ignored when encountered in the header-file specified in generate-PCH-mode. This resulted in compile-time errors in some cases with legal code, and also a misleading warning being produced. Patch by Warren Ristow! Differential Revision: http://reviews.llvm.org/D19815 llvm-svn: 276653
* [NFC] Header cleanupMehdi Amini2016-07-181-2/+0
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
* Add a PragmaHandler Registry for plugins to add PragmaHandlers toJohn Brawn2016-04-041-0/+7
| | | | | | | | | | 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 llvm-svn: 265295
* Fix use after free.Benjamin Kramer2016-02-131-1/+1
| | | | | | Found by asan. llvm-svn: 260814
* Accept "-Weverything" in clang diagnistic pragmasSunil Srivastava2016-02-131-4/+13
| | | | | | Differential Revision: http://reviews.llvm.org/D15095 llvm-svn: 260788
* Simplify EnterTokenStream API to make it more robust for memory managementDavid Blaikie2016-02-091-6/+6
| | | | | | | | | | | | | | | 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) llvm-svn: 260246
* Improve AST dumping:Richard Smith2016-01-121-1/+18
| | | | | | | | 1) When dumping a declaration that declares a name for a type, also dump the named type. 2) Add a #pragma clang __debug dump X, that dumps the lookup results for X in the current context. llvm-svn: 257529
* Roll-back r250822.Angel Garcia Gomez2015-10-201-1/+2
| | | | | | | | | | Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
* Apply modernize-use-default to clang.Angel Garcia Gomez2015-10-201-2/+1
| | | | | | | | | | | | 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 llvm-svn: 250822
* Parse and ignore #pragma runtime_checks in MS extensions mode (PR25138)Hans Wennborg2015-10-121-1/+1
| | | | | | We already silently ignore the /RTC, which controls the same functionality. llvm-svn: 250099
* Improved error recovery for _PragmaHubert Tong2015-07-301-1/+5
| | | | | | | | | | | | | | | | | | | | | Summary: Currently, if the argument to _Pragma is not a parenthesised string literal, the bad token will be consumed, as well as the ')', if present. If additional bad tokens are passed to the _Pragma, this results in extra error messages which may distract from the true problem. The proposed patch causes all tokens to be consumed until the closing ')' or a new line, whichever is reached first. Reviewers: hfinkel, rsmith Subscribers: hubert.reinterpretcast, fraggamuffin, rnk, cfe-commits Differential Revision: http://reviews.llvm.org/D8308 Patch by Rachel Craik! llvm-svn: 243692
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-1/+1
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-1/+1
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* Introduced pragmas for audited nullability regions.Douglas Gregor2015-06-191-0/+55
| | | | | | | | | | | | | | | | | 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. llvm-svn: 240156
* Bug fix for PR23577 (https://llvm.org/bugs/show_bug.cgi?id=23577#c0).Alexander Musman2015-05-251-14/+28
| | | | | | | | | | | | "1-4" specifiers are returned as numeric constants, not identifiers, and should be treated as such. Currently pragma handler incorrectly assumes that they are returned as identifiers. Patch by Andrey Bokhanko. Differential Revision: http://reviews.llvm.org/D9856 llvm-svn: 238129
* [modules] Add a mechanism to dump information about a macro.Richard Smith2015-04-301-0/+8
| | | | | | Wire this up to "#pragma clang __debug macro <name>". llvm-svn: 236280
* [modules] Stop trying to fake up a linear MacroDirective history.Richard Smith2015-04-291-3/+2
| | | | | | | | | | | | | | Modules builds fundamentally have a non-linear macro history. In the interest of better source fidelity, represent the macro definition information faithfully: we have a linear macro directive history within each module, and at any point we have a unique "latest" local macro directive and a collection of visible imported directives. This also removes the attendent complexity of attempting to create a correct MacroDirective history (which we got wrong in the general case). No functionality change intended. llvm-svn: 236176
* [modules] Store a ModuleMacro* on an imported macro directive rather than ↵Richard Smith2015-04-231-4/+2
| | | | | | duplicating the info within it. llvm-svn: 235644
* Remove many superfluous SmallString::str() calls.Yaron Keren2015-03-181-2/+2
| | | | | | | | | | | | | | | Now that SmallString is a first-class citizen, most SmallString::str() calls are not required. This patch removes a whole bunch of them, yet there are lots more. There are two use cases where str() is really needed: 1) To use one of StringRef member functions which is not available in SmallString. 2) To convert to std::string, as StringRef implicitly converts while SmallString do not. We may wish to change this, but it may introduce ambiguity. llvm-svn: 232622
* Properly initialize the parser_crash debug token.Benjamin Kramer2015-03-081-0/+2
| | | | | | Found by msan. llvm-svn: 231605
* Standardize on StringMap::insert, removing uses of StringMap::GetOrCreateValue.David Blaikie2014-11-191-3/+1
| | | | llvm-svn: 222306
* [modules] Add support for #include_next.Richard Smith2014-10-201-3/+3
| | | | | | | | | | | | #include_next interacts poorly with modules: it depends on where in the list of include paths the current file was found. Files covered by module maps are not found in include search paths when building the module (and are not found in include search paths when @importing the module either), so this isn't really meaningful. Instead, we fake up the result that #include_next *should* have given: find the first path that would have resulted in the given file being picked, and search from there onwards. llvm-svn: 220177
* Use unique_ptr for ScratchBuf and PragmaHandlers in the preprocessor.Craig Topper2014-09-121-5/+4
| | | | llvm-svn: 217656
* Don't Lex past EOF when lexing _PragmaReid Kleckner2014-08-141-1/+1
| | | | | | Fixes PR20662. llvm-svn: 215672
* Use -Rblah, not -Wblah, to control remark diagnostics. This was always theRichard Smith2014-08-071-3/+5
| | | | | | | | | | | | | | | | | | | | | | intent when we added remark support, but was never implemented in the general case, because the first -R flags didn't need it. (-Rpass= had special handling to accomodate its argument.) -Rno-foo, -Reverything, and -Rno-everything can be used to turn off a remark, or to turn on or off all remarks. Per discussion on cfe-commits, -Weverything does not affect remarks, and -Reverything does not affect warnings or errors. The only "real" -R flag we have right now is -Rmodule-build; that flag is effectively renamed from -Wmodule-build to -Rmodule-build by this change. -Wpass and -Wno-pass (and their friends) are also renamed to -Rpass and -Rno-pass by this change; it's not completely clear whether we intended to have a -Rpass (with no =pattern), but that is unchanged by this commit, other than the flag name. The default pattern is effectively one which matches no passes. In future, we may want to make the default pattern be .*, so that -Reverything works for -Rpass properly. llvm-svn: 215046
* [modules] Substantially improve handling of #undef:Richard Smith2014-07-251-1/+1
| | | | | | | | | | * Track override set across module load and save * Track originating module to allow proper re-export of #undef * Make override set properly transitive when it picks up a #undef This fixes nearly all of the remaining macro issues with self-host. llvm-svn: 213922
* DiagnosticsEngine: update severity setters to new terminologyAlp Toker2014-06-121-2/+2
| | | | llvm-svn: 210764
* Complete the switch from mappings to declarative diagnostic severitiesAlp Toker2014-06-121-14/+14
| | | | | | | | | This begins to address cognitive dissonance caused by treating the Note diagnostic level as a severity in the diagnostic engine. No change in functionality. llvm-svn: 210758
* Improve diagnostic mapping terminologyAlp Toker2014-06-101-1/+1
| | | | | | | | | | | | Diagnostic mappings are used to calculate the final severity of diagnostic instances. Detangle the implementation to reflect the terminology used in documentation and bindings. No change in functionality. llvm-svn: 210518
* [C++11] Use 'nullptr'. Lex edition.Craig Topper2014-05-171-10/+11
| | | | llvm-svn: 209083
OpenPOWER on IntegriCloud