aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/TokenLexer.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2016-10-26[PP] Replace some index based for loops with range based onesErik Verbruggen1-6/+5
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
2016-07-07[Lex] Speed up updateConsecutiveMacroArgTokens (NFC)Vedant Kumar1-3/+4
SM.isWrittenInSameFile() calls getFileID(), which can be expensive. Move this check behind some cheaper filters. llvm-svn: 274800
2016-05-19[Lexer] Don't merge macro args from different macro filesVedant Kumar1-0/+3
The lexer sets the end location of macro arguments incorrectly *if*, while merging consecutive args to fit into a single SLocEntry, it finds args which come from different macro files. Fix the issue by using separate SLocEntries in this situation. This fixes a code coverage crasher (rdar://problem/26181005). Because the lexer reported end locations for certain macro args incorrectly, we would generate bogus coverage mappings with negative line offsets. Reviewed-by: akyrtzi Differential Revision: http://reviews.llvm.org/D20401 llvm-svn: 270160
2016-02-12Fix remaining Clang-tidy readability-redundant-control-flow warnings; other ↵Eugene Zelenko1-7/+1
minor fixes. Differential revision: http://reviews.llvm.org/D17218 llvm-svn: 260757
2016-01-22[MSVC Compat] Accept elided commas in macro function argumentsEhsan Akhgari1-6/+11
Summary: This fixes PR25875. When the trailing comma in a macro argument list is elided, we need to treat it similarly to the case where a variadic macro misses one actual argument. Reviewers: rnk, rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15670 llvm-svn: 258530
2016-01-15When copying whitespace flags from the token naming a macro argument onto theRichard Smith1-0/+1
first token of the expansion, don't forget to copy the "is at the start of a line" token (which is always false, as newlines cannot appear within a macro body); otherwise, stringizing the result can insert spurious whitespace. llvm-svn: 257863
2015-12-29Emit a -Wmicrosoft warning when pasting /##/ into a comment token in MS mode.Nico Weber1-7/+10
llvm-svn: 256595
2015-06-18[clang] Refactoring of conditions so they use isOneOf() instead of multiple ↵Daniel Marjamaki1-1/+1
is(). llvm-svn: 240008
2015-04-17[MSVC] Mimic MSVC whitespace collapse for incompatible token pastingWill Wilson1-0/+7
In public MS headers for XAudio, clang would fail to generate a valid UUID due to the UUID components being combined with the '-' UUID separators. Clang would attempting to recover but would preserve the leading whitespace from the tokens after each failed paste leading to spaces creeping into the UUID and causing an error in the __declspace(uuid()) parsing. Reference: Microsoft DirectX SDK (June 2010)\Include\XAudio2.h(51) Resolves http://llvm.org/pr23071 llvm-svn: 235186
2015-03-18Remove many superfluous SmallString::str() calls.Yaron Keren1-1/+1
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
2014-12-15MSVC: A wide string literal from L#macro_arg in a macroAlexey Bataev1-3/+19
Clang should form a wide string literal from L#macro_arg in a function-like macro in -fms-compatibility mode. Fix for http://llvm.org/PR9984. Differential Revision: http://reviews.llvm.org/D6604 llvm-svn: 224228
2014-10-25Lex: Fix an invalid access into a SmallStringDavid Majnemer1-3/+4
We would crash because we used operator[] to access past the end of a SmallString. This occured because our token had length zero. Instead, form the pointer using .data() and arithmetic. This is safe because this forms a one-past-the-end pointer and it is only used to compare with another one-past-the-end pointer. This fixes PR21379. llvm-svn: 220614
2014-05-17[C++11] Use 'nullptr'. Lex edition.Craig Topper1-5/+5
llvm-svn: 209083
2014-05-09Wrap to 80 columns, no code change.Nico Weber1-4/+3
llvm-svn: 208386
2014-02-24If the first token in a macro that appears at the start of a line expands toRichard Smith1-0/+1
nothing, be sure to inform the *next* token expanded from the macro that it is now at the start of a line. Patch by Harald van Dijk! llvm-svn: 202068
2014-02-18Fix a non-error diagnostic that had an err_ name. Also move it from Warning toRichard Smith1-5/+4
ExtWarn, since it's an extension. llvm-svn: 201540
2014-02-04Clean up whitespace checksJustin Bogner1-11/+5
In TokenLexer::ExpandFunctionArguments(), CurTok.hasLeadingSpace() is checked in multiple locations, each time subtly differently. Checking it early, when the token is seen, and using NextTokGetsSpace exclusively after that makes the code simpler. No change in behaviour is intended. Patch by Harald van Dijk! llvm-svn: 200788
2014-02-04Fix whitespace handling in empty macro expansionsJustin Bogner1-2/+6
When a macro expansion does not result in any tokens, and the macro name is preceded by whitespace, the whitespace should be passed to the first token that follows the macro expansion. Similarly when a macro expansion ends with a placemarker token, and that placemarker token is preceded by whitespace. This worked already for top-level macro expansions, but is now extended to also work for nested macro expansions. Patch by Harald van Dijk! llvm-svn: 200787
2014-02-04Fix whitespace handling in empty macro argumentsJustin Bogner1-18/+13
When a function-like macro definition ends with one of the macro's parameters, and the argument is empty, any whitespace before the parameter name in the macro definition needs to be preserved. Promoting the existing NextTokGetsSpace to a preserved bit-field and checking it at the end of the macro expansion allows it to be moved to the first token following the macro expansion result. Patch by Harald van Dijk! llvm-svn: 200786
2014-02-04Fix whitespace handling in ## operatorJustin Bogner1-13/+16
In x ## y, where x and y are regular tokens, whitespace between x and ## is ignored, and whitespace between ## and y is also ignored. When either x or y is a function argument, whitespace was preserved, but it should not be. This patch removes the checks for whitespace before ## and before y, and in the special case where x is an empty macro argument and y is a regular token, actively removes whitespace before y. One existing test is affected by that change, but as clang's output now matches the standard's requirements and that of GCC, I've tweaked the testcase. Patch by Harald van Dijk! llvm-svn: 200785
2014-01-14Rename language option MicrosoftMode to MSVCCompatAlp Toker1-2/+2
There's been long-standing confusion over the role of these two options. This commit makes the necessary changes to differentiate them clearly, following up from r198936. MicrosoftExt (aka. fms-extensions): Enable largely unobjectionable Microsoft language extensions to ease portability. This mode, also supported by gcc, is used for building software like FreeBSD and Linux kernel extensions that share code with Windows drivers. MSVCCompat (aka. -fms-compatibility, formerly MicrosoftMode): Turn on a special mode supporting 'heinous' extensions for drop-in compatibility with the Microsoft Visual C++ product. Standards-compilant C and C++ code isn't guaranteed to work in this mode. Implies MicrosoftExt. Note that full -fms-compatibility mode is currently enabled by default on the Windows target, which may need tuning to serve as a reasonable default. See cfe-commits for the full discourse, thread 'r198497 - Move MS predefined type_info out of InitializePredefinedMacros' No change in behaviour. llvm-svn: 199209
2014-01-07Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth1-1/+1
encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. llvm-svn: 198686
2013-09-19Make Preprocessor::Lex non-recursive.Eli Friedman1-12/+17
Before this patch, Lex() would recurse whenever the current lexer changed (e.g. upon entry into a macro). This patch turns the recursion into a loop: the various lex routines now don't return a token when the current lexer changes, and at the top level Preprocessor::Lex() now loops until it finds a token. Normally, the recursion wouldn't end up being very deep, but the recursion depth can explode in edge cases like a bunch of consecutive macros which expand to nothing (like in the testcase test/Preprocessor/macro_expand_empty.c in this patch). <rdar://problem/14569770> llvm-svn: 190980
2013-08-23Use pop_back_val() instead of both back() and pop_back().Robert Wilhelm1-4/+2
No functionality change intended. llvm-svn: 189112
2013-07-05Use SmallVectorImpl& for function arguments instead of SmallVector.Craig Topper1-1/+1
llvm-svn: 185715
2013-06-26Match MSVC's handling of commas during macro argument expansionReid Kleckner1-0/+8
This allows clang to parse the type_traits header in Visual Studio 2012, which is included widely in practice. This is a rework of r163022 by João Matos. The original patch broke preprocessing of gtest headers, which this patch addresses. Patch by Will Wilson! llvm-svn: 184968
2013-05-25[Preprocessor] Prevent expansion of y in x ## y when x is emptyArgyrios Kyrtzidis1-7/+13
When x is empty, x ## is suppressed, and when y gets expanded, the fact that it follows ## is not available in the macro expansion result. The macro definition can be checked instead, the ## will be available there regardless of what x expands to. Fixes http://llvm.org/PR12767 Patch by Harald van Dijk! llvm-svn: 182699
2013-05-03[Preprocessor] For the MacroExpands preprocessor callback, also pass the ↵Argyrios Kyrtzidis1-1/+1
MacroArgs object that provides information about the argument tokens for a function macro. llvm-svn: 181065
2012-12-19[preprocessor] When "merging" macro argument tokens into one SLocEntry chunk,Argyrios Kyrtzidis1-2/+6
make sure they came from the same kind of FileIDs. Thanks to Abramo Bagnara for providing the test case. llvm-svn: 170616
2012-12-04Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth1-2/+2
uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
2012-12-01Try to make the source location information for token pastes a bit more ↵Eli Friedman1-0/+6
consistent. Fixes a crash printing diagnostics on the gcc testsuite, and also makes diagnostic range printing print nicer results for token pastes. llvm-svn: 169068
2012-11-09Improved support for removing the comma preceding __VA_ARGS__ where __VA_ARGS__Andy Gibbs1-17/+64
is empty in a variadic macro expansion. This fixes a divergence in support for the ", ## __VA_ARGS__" GCC extension which differed in behaviour when in strict C99 mode (note: there is no change in behaviour has been made in the gnu99 mode that clang uses by default). In addition, there is improved support for the Microsoft alternative extension ", __VA_ARGS__". llvm-svn: 167613
2012-09-26Revert r163022, it caused PR13924.Nico Weber1-6/+0
Add a test for PR13924. Do not revert the test added in r163022, it surprisingly still passes even after reverting the code changes. llvm-svn: 164672
2012-09-24StringRef'ize Preprocessor::CreateString().Dmitri Gribenko1-1/+1
llvm-svn: 164555
2012-08-31Emulate MSVC's preprocessor macro argument separator behavior by not ↵Joao Matos1-0/+6
considering commas from nested macro expansions as argument separators. Fixes parsing of VS 2012 headers. llvm-svn: 163022
2012-08-30Make preprocessor act in a GCC-compatible fashion when a macro is redefinedRichard Smith1-2/+3
within its own argument list. The original definition is used for the immediate expansion, but the new definition is used for any subsequent occurences within the argument list or after the expansion. llvm-svn: 162906
2012-07-23Fix a typo (the the => the)Sylvestre Ledru1-1/+1
llvm-svn: 160622
2012-06-22Minor improvements to some C99 variadic-macro-related diagnostics.Richard Smith1-3/+3
llvm-svn: 159054
2012-06-13Fix issue where a token paste which forms a /* or // would discard the rest ofRichard Smith1-2/+2
the input: token-pasting was producing a tok::eof. Patch by Andy Gibbs! llvm-svn: 158412
2012-03-11Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie1-4/+4
(Lex to AST). The member variable is always "LangOpts" and the member function is always "getLangOpts". Reviewed by Chris Lattner llvm-svn: 152536
2012-02-05Basic: import SmallString<> into clang namespaceDylan Noblesmith1-1/+1
(I was going to fix the TODO about DenseMap too, but that would break self-host right now. See PR11922.) llvm-svn: 149799
2012-02-04Move a method from IdentifierTable.h out of line and remove the SmallString ↵Benjamin Kramer1-1/+1
include. Fix all the transitive include users. llvm-svn: 149783
2011-10-03Fixed exapnsion range for # and ##.Abramo Bagnara1-8/+18
llvm-svn: 141012
2011-09-19Rename SourceLocation::getFileLocWithOffset -> getLocWithOffset.Argyrios Kyrtzidis1-2/+2
It already works (and is useful with) macro locs as well. llvm-svn: 140057
2011-09-17Rename LangOptions::Microsoft to LangOptions::MicrosoftExt to make it clear ↵Francois Pichet1-3/+3
that this flag must be used only for Microsoft extensions and not emulation; to avoid confusion with the new LangOptions::MicrosoftMode flag. Many of the code now under LangOptions::MicrosoftExt will eventually be moved under the LangOptions::MicrosoftMode flag. llvm-svn: 139987
2011-08-24Silence 'may be used uninitialized' warnings.Argyrios Kyrtzidis1-2/+2
llvm-svn: 138475
2011-08-23Amend r138129 (reduction of SLocEntries) which introduced performance ↵Argyrios Kyrtzidis1-18/+46
regression due to increased calls to SourceManager::getFileID. (rdar://9992664) Use a slightly different approach that is more efficient both in terms of speed (no extra getFileID calls) and in SLocEntries reduction. Comparing pre-r138129 and this patch we get: For compiling SemaExpr.cpp reduction of SLocEntries by 26%. For the boost enum library: -SLocEntries -34% (note that this was -5% for r138129) -Memory consumption -50% -PCH size -31% Reduced SLocEntries also benefit the hot function SourceManager::getFileID, evident by the reduced "FileID scans". llvm-svn: 138380
2011-08-23Introduce SourceManager::isInSLocAddrSpace and use it in TokenLexer instead ↵Argyrios Kyrtzidis1-12/+9
of isInFileID since it is a bit more efficient. llvm-svn: 138379
2011-08-23Rename SourceManager::isBeforeInSourceLocationOffset -> isBeforeInSLocAddrSpace.Argyrios Kyrtzidis1-2/+1
llvm-svn: 138378