aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
AgeCommit message (Collapse)AuthorFilesLines
2013-11-24Fix a typo: "SLocEnty" should read "SLocEntry".James Dennett1-1/+1
llvm-svn: 195563
2013-11-18Adding an assert to help catch possible buffer underruns.Aaron Ballman1-0/+4
llvm-svn: 195024
2013-09-27SourceManager: Open code isInMainFile.Benjamin Kramer1-0/+30
- We really shouldn't compute line numbers for every file that is asked if it's the main file, it destroys the lazy computation. - Invalid locations are no longer accounted to the main file, no other functionality change. llvm-svn: 191535
2013-07-29Simplified SourceManager::translateLineCol a bit.Alexander Kornienko1-6/+3
Reviewers: rsmith Reviewed By: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1183 llvm-svn: 187386
2013-07-29Update for llvm api change.Rafael Espindola1-5/+8
llvm-svn: 187379
2013-07-29Convert a use of status with llvm::sys::fs::getUniqueID.Rafael Espindola1-17/+16
llvm-svn: 187367
2013-06-07Thread the 'Invalid' out parameter through SourceManager::getSLocEntry() and ↵Argyrios Kyrtzidis1-1/+4
callees of SourceManager::getSLocEntryByID(). Also add an 'Invalid' check in SourceManager::computeMacroArgsCache(). llvm-svn: 183538
2013-05-25Make isBeforeInTranslationUnit consistent in the face of failures to get a ↵Argyrios Kyrtzidis1-1/+1
valid FileID (V2). llvm-svn: 182698
2013-05-24Make isBeforeInTranslationUnit consistent in the face of failures to get a ↵Argyrios Kyrtzidis1-1/+4
valid FileID. Suggested by Jordan. llvm-svn: 182695
2013-05-24Add some safety checks in a couple of SourceManager functions.Argyrios Kyrtzidis1-5/+14
This is to address crash in rdar://13932308 llvm-svn: 182681
2013-05-24Replace Count{Leading,Trailing}Zeros_{32,64} with count{Leading,Trailing}Zeros.Michael J. Spencer1-1/+1
llvm-svn: 182675
2013-05-16[Lexer] Improve Lexer::getSourceText() when the given range deals with ↵Argyrios Kyrtzidis1-0/+108
function macro arguments. This is a modified version of a patch by Manuel Klimek. llvm-svn: 182055
2013-04-13Introduce SourceManager::getDecomposedIncludedLoc, that returns the ↵Argyrios Kyrtzidis1-11/+30
"included/expanded in" decomposed location of the given FileID. The main benefit is to speed-up SourceManager::isBeforeInTranslationUnit which is common to query the included/expanded location of the same FileID multiple times. llvm-svn: 179435
2013-03-01Add one more sanity check in SourceManager::getFileIDLoaded().Argyrios Kyrtzidis1-0/+5
llvm-svn: 176333
2013-03-01In SourceManager::getFileIDLoaded(), add some sanity checks to make sure we ↵Argyrios Kyrtzidis1-0/+7
don't enter an infinite loop. rdar://13120919 llvm-svn: 176331
2013-02-27Refine SourceManager's isBeforeInTranslationUnit() cache to have more entries.Ted Kremenek1-1/+31
isBeforeInTranslationUnit() uses a cache to reduce the expensive work to compute a common ancestor for two FileIDs. This work is very expensive, so even caching the latest used FileIDs was a big win. A closer analysis of the cache before, however, shows that the cache access pattern would oscillate between a working set of FileIDs, and thus caching more pairs would be profitable. This patch adds a side table for extending caching. This side table is bounded in size (experimentally determined in this case from a simple Objective-C project), and when the table gets too large we fall back to the single entry caching before as before. On Sketch (a small example Objective-C project), this optimization reduces -fsyntax-only time on SKTGraphicView.m by 5%. This is for a project that is already using PCH. Fixes <rdar://problem/13299847> llvm-svn: 176142
2013-02-22Replace some typically large vectors with SmallVector.Benjamin Kramer1-1/+1
This may seem counter-intuitive but the POD-like optimization helps when the vectors grow into multimegabyte buffers. SmallVector calls realloc which knows how to twiddle virtual memory bits and avoids large copies. llvm-svn: 175906
2013-02-21Use None rather than Optional<T>() where possible.David Blaikie1-2/+2
llvm-svn: 175705
2013-02-20Include llvm::Optional in clang/Basic/LLVM.hDavid Blaikie1-8/+7
Post-commit CR feedback from Jordan Rose regarding r175594. llvm-svn: 175679
2013-01-12Fix -Wunused-comparison for comparisons in arguments to function-like macros.Matt Beaumont-Gay1-2/+9
Previously, -Wunused-comparison ignored comparisons in both macro bodies and macro arguments, but we would still emit a -Wunused-value warning for either. Now we correctly emit -Wunused-comparison for expressions in macro arguments. Also, add isMacroBodyExpansion to SourceManager, to go along with isMacroArgExpansion. llvm-svn: 172279
2012-12-16Don't use SourceLineCache in getColumnNumber if LastLineNoResult is past the ↵Craig Topper1-1/+2
end of the cache. Fixes PR14570. llvm-svn: 170281
2012-12-04Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth1-5/+5
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-11-14Add -cc1 option -fno-diagnostics-use-presumed-location, a handy mode forRichard Smith1-2/+3
working with preprocessed testcases. This causes source locations in diagnostics to point at the spelling location instead of the presumed location, while still keeping the semantic effects of the line directives (entering and leaving system-header mode, primarily). llvm-svn: 168004
2012-10-20When associating file ranges of macro arguments with theirArgyrios Kyrtzidis1-37/+82
macro expansion ranges, make sure to check all the FileID entries that are contained in the spelling range of the expansion for the macro argument. Fixes rdar://12537982 llvm-svn: 166359
2012-10-19Teach getColumnNumber to use the line cache to get the start of the line if ↵Craig Topper1-0/+11
its on the same line as the last call to getLineNumber. Prevents needing to scan backwards for the new line. Fixes PR14106. llvm-svn: 166265
2012-10-12Silence dead store warning. It is conceptually possible we willTed Kremenek1-0/+1
add more code that references SourceFile, so removing the dead store doesn't seem appropriate for the long term. llvm-svn: 165837
2012-09-06Dont cast away const needlessly. Found by gcc48 -Wcast-qual.Roman Divacky1-1/+1
llvm-svn: 163325
2012-07-11Introduce a flag in SourceManager to treat non-system source filesArgyrios Kyrtzidis1-3/+11
as "volatile", meaning there's a high enough chance that they may change while we are trying to use them. This flag is only enabled by libclang. Currently "volatile" source files will be stat'ed immediately before opening them, because the file size stat info may not be accurate since when we got it (e.g. from the PCH). This avoids crashes when trying to reference mmap'ed memory from a file whose size is not what we expect. Note that there's still a window for a racing issue to occur but the window for it should be way smaller than before. We can consider later on to avoid mmap completely on such files. rdar://11612916 llvm-svn: 160074
2012-07-02Documentation cleanup: Delete a duplicated/malformed doc comment.James Dennett1-2/+0
llvm-svn: 159628
2012-06-19Revert predefined decl tracking.Meador Inge1-1/+0
r158085 added some logic to track predefined declarations. The main reason we had predefined declarations in the input was because the __builtin_va_list declarations were injected into the preprocessor input. As of r158592 we explicitly build the __builtin_va_list declarations. Therefore the predefined decl tracking is no longer needed. llvm-svn: 158732
2012-06-19Fix the location of the fixit for -Wnewline-eof.Jordan Rose1-2/+3
It turns out SourceManager treating the "one-past-the-end" location as invalid, but then failing to set the invalid flag properly. llvm-svn: 158699
2012-06-17Documentation cleanup: escaped # characters in Doxygen comments.James Dennett1-3/+3
llvm-svn: 158614
2012-06-15Documentation cleanup: escape # in a Doxygen comment.James Dennett1-1/+1
llvm-svn: 158549
2012-06-08Switch LineTableInfo to use FileID instead of int for file references,Douglas Gregor1-8/+8
from Tom Honermann! llvm-svn: 158211
2012-06-06Add pedantic warning -Wempty-translation-unit (C11 6.9p1).Jordan Rose1-0/+1
In standard C since C89, a 'translation-unit' is syntactically defined to have at least one "external-declaration", which is either a decl or a function definition. In Clang the latter gives us a declaration as well. The tricky bit about this warning is that our predefines can contain external declarations (__builtin_va_list and the 128-bit integer types). Therefore our AST parser now makes sure we have at least one declaration that doesn't come from the predefines buffer. Also, remove bogus warning about empty source files. This doesn't catch source files that only contain comments, and never fired anyway because of our predefines. PR12665 and <rdar://problem/9165548> llvm-svn: 158085
2012-05-03[PCH] When validating that the files coming from PCH did not change, alsoArgyrios Kyrtzidis1-14/+37
validate that we didn't override the contents of any of such files. If this is detected, emit a diagnostic error and recover gracefully by using the contents of the original file that the PCH was built from. Part of rdar://11305263 llvm-svn: 156107
2012-04-06SourceManager: Vectorize ComputeLineNumbers for SSE2.Benjamin Kramer1-2/+39
This method is very hot, it is called when emitting diagnostics, in -E mode and for many #pragma handlers. It scans through the whole source file to count newlines, records and caches them in a vector. The speedup from vectorization isn't very large, as we fall back to bytewise scanning when we hit a newline. There might be a way to avoid leaving the sse loop but everything I tried didn't work out because a call to push_back clobbers xmm registers. About 2% speedup on average on "clang -E > /dev/null" of all .cpp files in clang's lib/Sema. llvm-svn: 154204
2012-02-20[PCH] Recover gracefully if the ASTReader detects that a file is differentArgyrios Kyrtzidis1-1/+34
from the one stored in the PCH/AST, while trying to load a SLocEntry. We verify that all files of the PCH did not change before loading it but this is not enough because: - The AST may have been 1) kept around, 2) to do queries on it. - We may have 1) verified the PCH and 2) started parsing. Between 1) and 2) files may change and we are going to have crashes because the rest of clang cannot deal with the ASTReader failing to read a SLocEntry. Handle this by recovering gracefully in such a case, by initializing the SLocEntry with the info from the PCH/AST as well as reporting failure by the ASTReader. rdar://10888929 llvm-svn: 151004
2011-12-21Fix bugs in SourceManager::computeMacroArgsCache() and add a unit test for it.Argyrios Kyrtzidis1-5/+22
llvm-svn: 147057
2011-12-21For SourceManager::isBeforeInTranslationUnit(), have it consider macro arg ↵Argyrios Kyrtzidis1-1/+1
expanded token locations as coming before the closing ')' of a function macro expansion. Include a unit test for SourceManager. llvm-svn: 147056
2011-12-19SourceManager: use getBufferSize()Dylan Noblesmith1-4/+5
Forming an out of bounds pointer to check if it's out of bounds was undefined behavior. llvm-svn: 146861
2011-12-15In SourceManager::~SourceManager do a sanity check to make sure weArgyrios Kyrtzidis1-4/+8
don't try to destruct a null ContentCache. rdar://10567159 llvm-svn: 146707
2011-12-10In ContentCache::replaceBuffer, add sanity check to make sure that we do not ↵Argyrios Kyrtzidis1-1/+5
free a buffer and then continue using it. rdar://10359140. llvm-svn: 146308
2011-12-10Add a sanity check in SourceManager::getColumnNumber, make sureArgyrios Kyrtzidis1-1/+8
we don't try to access beyond the buffer. llvm-svn: 146305
2011-11-16Implement (de-)serialization of the buffer contents for an overriddenDouglas Gregor1-0/+1
file in the source manager. This allows us to properly create and use modules described by module map files without umbrella headers (or with incompletely umbrella headers). More generally, we can actually build a PCH file that makes use of file -> buffer remappings, which could be useful in libclang in the future. llvm-svn: 144830
2011-10-25Use assert(0) instead of duplicating the check, suggestion by Anna.Argyrios Kyrtzidis1-3/+3
llvm-svn: 142886
2011-10-12Introduce SourceManager::getFileLoc which returns a file locationArgyrios Kyrtzidis1-0/+10
taking into account macro arguments. llvm-svn: 141771
2011-10-03Make sure SourceManager::getFileIDLoaded doesn't hang in release build ↵Argyrios Kyrtzidis1-0/+4
because of invalid passed parameter. rdar://10210140 llvm-svn: 141048
2011-09-27Break SourceManager::translateFileLineCol into translateFile, no ↵Argyrios Kyrtzidis1-5/+16
functionality change. llvm-svn: 140610
2011-09-26Associate the macro arguments location map with a FileID insteadArgyrios Kyrtzidis1-17/+17
of a ContentCache, since multiple FileIDs can have the same ContentCache but the expanded macro arguments locations will be different. llvm-svn: 140521