summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
Commit message (Collapse)AuthorAgeFilesLines
...
* [Preprocessor] Always discard body of #define if we failed to parse itIlya Biryukov2019-08-011-5/+9
| | | | | | | | | | | | | | | | | | | | Summary: Preivously we would only discard it if we failed to parse parameter lists. If we do not consume the body, parser sees tokens inside directive. In turn, this leads to spurious diagnostics and a crash in TokenBuffer, see the added tests. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65517 llvm-svn: 367530
* Remove cache for macro arg stringizationReid Kleckner2019-07-302-32/+4
| | | | | | | | | | | | | | | | | | | Summary: The cache recorded the wrong expansion location for all but the first stringization. It seems uncommon to stringize the same macro argument multiple times, so this cache doesn't seem that important. Fixes PR39942 Reviewers: vsk, rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65428 llvm-svn: 367337
* [clang-scan-deps] Dependency directives source minimizer: handle #pragma onceAlex Lorenz2019-07-181-1/+15
| | | | | | | | | We should re-emit `#pragma once` to ensure the preprocessor will still honor it when running on minimized sources. Differential Revision: https://reviews.llvm.org/D64945 llvm-svn: 366509
* Fix parameter name comments using clang-tidy. NFC.Rui Ueyama2019-07-165-14/+14
| | | | | | | | | | | | | | | | | | | | | This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
* Delete dead storesFangrui Song2019-07-121-2/+1
| | | | llvm-svn: 365901
* [clang-scan-deps] Dependency directives source minimizer:Alex Lorenz2019-07-101-1/+8
| | | | | | | | | | | | single quotes are not digit separators after a valid character literal prefix The single quote character can act as a c++ digit separator. However, the minimizer shouldn't treat it as such when it's actually following a valid character literal prefix, like L, U, u, or u8. Differential Revision: https://reviews.llvm.org/D64525 llvm-svn: 365700
* [modules] Add PP callbacks for entering and leaving a submodule.Vassil Vassilev2019-07-041-0/+12
| | | | llvm-svn: 365153
* Change std::{lower,upper}_bound to llvm::{lower,upper}_bound or ↵Fangrui Song2019-07-032-17/+11
| | | | | | llvm::partition_point. NFC llvm-svn: 365006
* [clang][HeaderSearch] Shorten paths for includes in mainfile's directoryKadir Cetinkaya2019-07-031-16/+28
| | | | | | | | | | | | | | | | | | Summary: Currently HeaderSearch only looks at SearchDir's passed into it, but in addition to those paths headers can be relative to including file's directory. This patch makes sure that is taken into account. Reviewers: gribozavr Subscribers: jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63295 llvm-svn: 365005
* [C++2a] Add __builtin_bit_cast, used to implement std::bit_castErik Pilkington2019-07-021-0/+1
| | | | | | | | | | | | | | | | | | This commit adds a new builtin, __builtin_bit_cast(T, v), which performs a bit_cast from a value v to a type T. This expression can be evaluated at compile time under specific circumstances. The compile time evaluation currently doesn't support bit-fields, but I'm planning on fixing this in a follow up (some of the logic for figuring this out is in CodeGen). I'm also planning follow-ups for supporting some more esoteric types that the constexpr evaluator supports, as well as extending __builtin_memcpy constexpr evaluation to use the same infrastructure. rdar://44987528 Differential revision: https://reviews.llvm.org/D62825 llvm-svn: 364954
* Fix __has_cpp_attribute expansion to produce trailing L and (whereRichard Smith2019-06-211-2/+10
| | | | | | | | necessary) leading whitespace. Simplify unit test and extend to cover no_unique_address attribute. llvm-svn: 364102
* [clang][HeaderSearch] Consider all path separators equalKadir Cetinkaya2019-06-061-0/+5
| | | | | | | | | | | | Reviewers: ilya-biryukov, sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62965 llvm-svn: 362731
* Fix windows build for commit r362459Alex Lorenz2019-06-031-6/+6
| | | | llvm-svn: 362463
* Add clang source minimizer that reduces source to directivesAlex Lorenz2019-06-032-0/+757
| | | | | | | | | | | | | | | | | | | | | that might affect the dependency list for a compilation This commit introduces a dependency directives source minimizer to clang that minimizes header and source files to the minimum necessary preprocessor directives for evaluating includes. It reduces the source down to #define, #include, The source minimizer works by lexing the input with a custom fast lexer that recognizes the preprocessor directives it cares about, and emitting those directives in the minimized source. It ignores source code, comments, and normalizes whitespace. It gives up and fails if seems any directives that it doesn't recognize as valid (e.g. #define 0). In addition to the source minimizer this patch adds a -print-dependency-directives-minimized-source CC1 option that allows you to invoke the minimizer from clang directly. Differential Revision: https://reviews.llvm.org/D55463 llvm-svn: 362459
* Make __has_builtin work with __builtin_LINE and friends.Eric Fiselier2019-05-291-0/+4
| | | | | | | | | | The source location builtins are implemented as keywords, but __has_builtin should still report true for them. This patch also fixes a test failure on systemz where the alignment of string literals is 2 not 1. llvm-svn: 361920
* [Preprocessor] Fix crash emitting note with framework location for "file not ↵Volodymyr Sapsai2019-05-271-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | found" error. A filename can be remapped with a header map to point to a framework header and we can find the corresponding framework without the header. But if the original filename doesn't have a remapped framework name, we'll fail to find its location and will dereference a null pointer during diagnostics emission. Fix by tracking remappings better and emit the note only if a framework is found before any of the remappings. rdar://problem/48883447 Reviewers: arphaman, erik.pilkington, jkorous Reviewed By: arphaman Subscribers: dexonsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D61707 llvm-svn: 361779
* [PragmaHandler] Expose `#pragma` locationJoel E. Denny2019-05-212-31/+29
| | | | | | | | | | | | | | | | | | | | | | | Currently, a pragma AST node's recorded location starts at the namespace token (such as `omp` in the case of OpenMP) after the `#pragma` token, and the `#pragma` location isn't available. However, the `#pragma` location can be useful when, for example, rewriting a directive using Clang's Rewrite facility. This patch makes `#pragma` locations available in any `PragmaHandler` but it doesn't yet make use of them. This patch also uses the new `struct PragmaIntroducer` to simplify `Preprocessor::HandlePragmaDirective`. It doesn't do the same for `PPCallbacks::PragmaDirective` because that changes the API documented in `clang-tools-extra/docs/pp-trace.rst`, and I'm not sure about backward compatibility guarantees there. Reviewed By: ABataev, lebedev.ri, aaron.ballman Differential Revision: https://reviews.llvm.org/D61643 llvm-svn: 361335
* [Lex] Allow to consume tokens while preprocessingIlya Biryukov2019-05-178-23/+36
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: By adding a hook to consume all tokens produced by the preprocessor. The intention of this change is to make it possible to consume the expanded tokens without re-runnig the preprocessor with minimal changes to the preprocessor and minimal performance penalty when preprocessing without recording the tokens. The added hook is very low-level and reconstructing the expanded token stream requires more work in the client code, the actual algorithm to collect the tokens using this hook can be found in the follow-up change. Reviewers: rsmith Reviewed By: rsmith Subscribers: eraman, nemanjai, kbarton, jsji, riccibruno, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59885 llvm-svn: 361007
* Reland "[Clang][PP] Add the __FILE_NAME__ builtin macro"Kristina Brooks2019-05-161-2/+17
| | | | | | | | | | | | | | | | | | | | | | | | | This relands commit rL360833 which caused issues on Win32 bots due to path handling/normalization differences. Now this uses `sys::path::filename` which should handle additional edge cases on Win32. Original commit: "[Clang][PP] Add the __FILE_NAME__ builtin macro" This patch adds the __FILE_NAME__ macro that expands to the last component of the path, similar to __FILE__ except with a guarantee that only the last path component (without the separator) will be rendered. I intend to follow through with discussion of this with WG14 as a potential inclusion in the C standard or failing that, try to discuss this with GCC developers since this extension is desired by GCC and Clang users/developers alike. Differential Revision: https://reviews.llvm.org/D61756 llvm-svn: 360938
* Revert r360833 until I can work out the issue with Win32 botsKristina Brooks2019-05-161-24/+2
| | | | | | | | | This reverts "r360833: [Clang][PP] Add the __FILE_NAME__ builtin macro." The tests are failing on Windows bots, reverting the patchset until I can work out why. llvm-svn: 360842
* Fix assumption about Win32 paths in r360833Kristina Brooks2019-05-161-2/+8
| | | | | | | Attempt to fix Windows buildbots due to differences in path handling (caused by r360833). llvm-svn: 360839
* [Clang][PP] Add the __FILE_NAME__ builtin macro.Kristina Brooks2019-05-161-2/+18
| | | | | | | | | | | | | | | | This patch adds the `__FILE_NAME__` macro that expands to the last component of the path, similar to `__FILE__` except with a guarantee that only the last path component (without the separator) will be rendered. I intend to follow through with discussion of this with WG14 as a potential inclusion in the C standard or failing that, try to discuss this with GCC developers since this extension is desired by GCC and Clang users/developers alike. Differential Revision: https://reviews.llvm.org/D61756 llvm-svn: 360833
* [Preamble] Stop circular inclusion of main file when building preambleNikolai Kosjar2019-05-101-0/+12
| | | | | | | | | | | | | | | If a header file was processed for the second time, we could end up with a wrong conditional stack and skipped ranges: In the particular example, if the header guard is evaluated the second time and it is decided to skip the conditional block, the corresponding "#endif" is never seen since the preamble does not include it and we end up in the Tok.is(tok::eof) case with a wrong conditional stack. Detect the circular inclusion, emit a diagnostic and stop processing the inclusion. llvm-svn: 360418
* -frewrite-imports: Add support for wildcard rules in umbrella modules withDavid Blaikie2019-05-071-4/+3
| | | | | | | | | | This trips over a few other limitations, but in the interests of incremental development I'm starting here & I'll look at the issues with -verify and filesystem checks (the fact that the behavior depends on the existence of a 'foo' directory even though it shouldn't need it), etc. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D61656 llvm-svn: 360195
* [c++20] Implement tweaked __VA_OPT__ rules from P1042R1:Richard Smith2019-05-042-11/+50
| | | | | | | | | | * __VA_OPT__ is expanded if the *expanded* __VA_ARGS__ is non-empty, not if the original argument contained no tokens. * Placemarkers at the start and end of __VA_OPT__ are retained just long enough to paste them with adjacent ## operators. We never paste "across" a discarded placemarker. llvm-svn: 359964
* When skipping code at the start of a file during PCH use, Preprocessor::LexMike Rice2019-04-291-2/+17
| | | | | | | | | | | | | | is not used since it consumes all preprocessor directives until it returns a real token. Using the specific Lexer (i.e. CurLexer->Lex) makes it possible to stop skipping after an #include or #pragma hdrstop. Previously the skipping code was only handling CurLexer, now all will be handled correctly. Fixes: llvm.org/PR41585 Differential Revision: https://reviews.llvm.org/D61217 llvm-svn: 359506
* [clang][HeaderSuggestion] Handle the case of dotdot with an absolute pathKadir Cetinkaya2019-04-241-4/+3
| | | | | | | | | | | | | | | | | Summary: Include insertion in clangd was inserting absolute paths when the include directory was an absolute path with a double dot. This patch makes sure double dots are handled both with absolute and relative paths. Reviewers: sammccall Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60873 llvm-svn: 359078
* [clang][HeaderSearch] Make sure there are no backslashes in suggestedPathKadir Cetinkaya2019-04-241-1/+1
| | | | | | | | Reviewers: sammccall Differential Revision: https://reviews.llvm.org/D60995 llvm-svn: 359075
* [c++2a] Add semantic support for private module fragments.Richard Smith2019-04-181-1/+11
| | | | llvm-svn: 358713
* Add '#pragma clang __debug module_map module.name' to dump the moduleRichard Smith2019-04-181-1/+17
| | | | | | map being used for the module 'module.name'. llvm-svn: 358632
* [c++2a] Improve diagnostic for use of declaration from another TU'sRichard Smith2019-04-181-1/+15
| | | | | | | | | | global module fragment. We know that the declaration in question should have been introduced by a '#include', so try to figure out which one and suggest it. Don't suggest importing the global module fragment itself! llvm-svn: 358631
* [c++20] Parsing support for module-declarations, import-declarations,Richard Smith2019-04-142-0/+5
| | | | | | | | | and the global and private module fragment. For now, the private module fragment introducer is ignored, but use of the global module fragment introducer should be properly enforced. llvm-svn: 358353
* [C++20] Implement context-sensitive header-name lexing and pp-import parsing ↵Richard Smith2019-04-114-93/+362
| | | | | | in the preprocessor. llvm-svn: 358231
* Remove use of lookahead from _Pragma handling and from all otherRichard Smith2019-04-114-102/+83
| | | | | | | | | | | | | | | internal lexing steps in the preprocessor. It is not safe to use the preprocessor's token lookahead except when operating on the final sequence of tokens that would be produced by phase 4 of translation. Doing so corrupts the token lookahead cache used by the parser. (See added testcase for an example.) Lookahead should instead be viewed as a layer on top of the normal lexer. Added assertions to catch any further incorrect uses of lookahead within lexing actions. llvm-svn: 358230
* Range-style std::find{,_if} -> llvm::find{,_if}. NFCFangrui Song2019-03-312-5/+4
| | | | llvm-svn: 357359
* Basic: Return a reference from FileManager::getVirtualFileSystem, NFCDuncan P. N. Exon Smith2019-03-263-5/+5
| | | | | | | | | | FileManager constructs a VFS in its constructor if it isn't passed one, and there's no way to reset it. Make that contract clear by returning a reference from its accessor. https://reviews.llvm.org/D59388 llvm-svn: 357038
* [OpenCL] Allow variadic macros as Clang feature.Anastasia Stulova2019-03-261-2/+1
| | | | llvm-svn: 356987
* Improve the diagnostic for #include_next occurring in a file not foundRichard Smith2019-03-211-0/+4
| | | | | | | | | | | in the include path. Instead of making the incorrect claim that the included file has an absolute path, describe the actual problem: the including file was found either by absolute path, or relative to such a file, or relative to the primary source file. llvm-svn: 356712
* Refactor handling of #include directives to cleanly separate theRichard Smith2019-03-211-33/+49
| | | | | | | "skipped header because it should be imported as a module" cases from the "skipped header because of some other reason" cases. llvm-svn: 356704
* Replace tok::angle_string_literal with new tok::header_name.Richard Smith2019-03-195-16/+42
| | | | | | | | | | Use the new kind for both angled header-name tokens and for double-quoted header-name tokens. This is in preparation for C++20's context-sensitive header-name token formation rules. llvm-svn: 356530
* Factor out repeated code parsing and concatenating header-names fromRichard Smith2019-03-195-181/+122
| | | | | | | | | | | tokens. We now actually form an angled_string_literal token for a header name by concatenation rather than just working out what its contents would be. This substantially simplifies downstream processing and is necessary for C++20 header unit imports. llvm-svn: 356433
* Don't apply the include depth limit until we actually decide to enterRichard Smith2019-03-191-7/+7
| | | | | | | | | the file. NFC unless a skipped #include is found at the final permitted #include level. llvm-svn: 356432
* Add PragmaHandler for MSVC pragma execution_character_setReid Kleckner2019-03-141-0/+65
| | | | | | | | | | | | __pragma(execution_character_set(push, "UTF-8")) is used in TraceLoggingProvider.h. This commit implements a no-op handler for compatability, similar to how the flag -fexec_charset is handled. Patch by Matt Gardner! Differential Revision: https://reviews.llvm.org/D58530 llvm-svn: 356185
* Modules: Rename MemoryBufferCache to InMemoryModuleCacheDuncan P. N. Exon Smith2019-03-091-3/+3
| | | | | | | | | | | | | Change MemoryBufferCache to InMemoryModuleCache, moving it from Basic to Serialization. Another patch will start using it to manage module build more explicitly, but this is split out because it's mostly mechanical. Because of the move to Serialization we can no longer abuse the Preprocessor to forward it to the ASTReader. Besides the rename and file move, that means Preprocessor::Preprocessor has one fewer parameter and ASTReader::ASTReader has one more. llvm-svn: 355777
* Fix file headers. NFCFangrui Song2019-03-012-2/+2
| | | | llvm-svn: 355176
* Print a note to the called macro when diagnosing err_embedded_directiveNico Weber2019-02-143-0/+6
| | | | | | | | Fixes PR40713, see there for the motivation for this. Differential Revision: https://reviews.llvm.org/D58161 llvm-svn: 354009
* [Preprocessor] Add a note with framework location for "file not found" error.Volodymyr Sapsai2019-02-055-23/+52
| | | | | | | | | | | | | | | | | | | | | | | | | When a framework with the same name is available at multiple framework search paths, we use the first matching location. If a framework at this location doesn't have all the headers, it can be confusing for developers because they see only an error `'Foo/Foo.h' file not found`, can find the complete framework with required header, and don't know the incomplete framework was used instead. Add a note explaining a framework without required header was found. Also mention framework directory path to make it easier to find the incomplete framework. rdar://problem/39246514 Reviewers: arphaman, erik.pilkington, jkorous Reviewed By: jkorous Subscribers: jkorous, dexonsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D56561 llvm-svn: 353231
* [CUDA][HIP] Do not diagnose use of _Float16Yaxun Liu2019-01-291-2/+5
| | | | | | | | | | | r352221 caused regressions in CUDA/HIP since device function may use _Float16 whereas host does not support it. In this case host compilation should not diagnose usage of _Float16 in device functions or variables. For now just do not diagnose _Float16 for CUDA/HIP. In the future we should have more precise check. Differential Revision: https://reviews.llvm.org/D57369 llvm-svn: 352488
* Remove F16 literal support based on Float16 support.Erich Keane2019-01-251-4/+5
| | | | | | | | | Float16 support was disabled recently on many platforms, however that commit still allowed literals of Float16 type to work. This commit removes those based on the same logic as Float16 disable. Change-Id: I72243048ae2db3dc47bd3d699843e3edf9c395ea llvm-svn: 352229
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-1922-88/+66
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
OpenPOWER on IntegriCloud