summaryrefslogtreecommitdiff
path: root/lib/Basic/SourceManager.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix the location of the fixit for -Wnewline-eof.Jordan Rose2012-06-191-2/+3
| | | | | | | It turns out SourceManager treating the "one-past-the-end" location as invalid, but then failing to set the invalid flag properly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158699 91177308-0d34-0410-b5e6-96231b3b80d8
* Documentation cleanup: escaped # characters in Doxygen comments.James Dennett2012-06-171-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158614 91177308-0d34-0410-b5e6-96231b3b80d8
* Documentation cleanup: escape # in a Doxygen comment.James Dennett2012-06-151-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158549 91177308-0d34-0410-b5e6-96231b3b80d8
* Switch LineTableInfo to use FileID instead of int for file references,Douglas Gregor2012-06-081-8/+8
| | | | | | | | from Tom Honermann! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158211 91177308-0d34-0410-b5e6-96231b3b80d8
* Add pedantic warning -Wempty-translation-unit (C11 6.9p1).Jordan Rose2012-06-061-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> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158085 91177308-0d34-0410-b5e6-96231b3b80d8
* [PCH] When validating that the files coming from PCH did not change, alsoArgyrios Kyrtzidis2012-05-031-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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156107 91177308-0d34-0410-b5e6-96231b3b80d8
* SourceManager: Vectorize ComputeLineNumbers for SSE2.Benjamin Kramer2012-04-061-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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154204 91177308-0d34-0410-b5e6-96231b3b80d8
* [PCH] Recover gracefully if the ASTReader detects that a file is differentArgyrios Kyrtzidis2012-02-201-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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151004 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix bugs in SourceManager::computeMacroArgsCache() and add a unit test for it.Argyrios Kyrtzidis2011-12-211-5/+22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147057 91177308-0d34-0410-b5e6-96231b3b80d8
* For SourceManager::isBeforeInTranslationUnit(), have it consider macro arg ↵Argyrios Kyrtzidis2011-12-211-1/+1
| | | | | | | | | | expanded token locations as coming before the closing ')' of a function macro expansion. Include a unit test for SourceManager. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147056 91177308-0d34-0410-b5e6-96231b3b80d8
* SourceManager: use getBufferSize()Dylan Noblesmith2011-12-191-4/+5
| | | | | | | | | Forming an out of bounds pointer to check if it's out of bounds was undefined behavior. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146861 91177308-0d34-0410-b5e6-96231b3b80d8
* In SourceManager::~SourceManager do a sanity check to make sure weArgyrios Kyrtzidis2011-12-151-4/+8
| | | | | | | | don't try to destruct a null ContentCache. rdar://10567159 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146707 91177308-0d34-0410-b5e6-96231b3b80d8
* In ContentCache::replaceBuffer, add sanity check to make sure that we do not ↵Argyrios Kyrtzidis2011-12-101-1/+5
| | | | | | | | free a buffer and then continue using it. rdar://10359140. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146308 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a sanity check in SourceManager::getColumnNumber, make sureArgyrios Kyrtzidis2011-12-101-1/+8
| | | | | | we don't try to access beyond the buffer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146305 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement (de-)serialization of the buffer contents for an overriddenDouglas Gregor2011-11-161-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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144830 91177308-0d34-0410-b5e6-96231b3b80d8
* Use assert(0) instead of duplicating the check, suggestion by Anna.Argyrios Kyrtzidis2011-10-251-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142886 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce SourceManager::getFileLoc which returns a file locationArgyrios Kyrtzidis2011-10-121-0/+10
| | | | | | taking into account macro arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141771 91177308-0d34-0410-b5e6-96231b3b80d8
* Make sure SourceManager::getFileIDLoaded doesn't hang in release build ↵Argyrios Kyrtzidis2011-10-031-0/+4
| | | | | | | | because of invalid passed parameter. rdar://10210140 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141048 91177308-0d34-0410-b5e6-96231b3b80d8
* Break SourceManager::translateFileLineCol into translateFile, no ↵Argyrios Kyrtzidis2011-09-271-5/+16
| | | | | | functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140610 91177308-0d34-0410-b5e6-96231b3b80d8
* Associate the macro arguments location map with a FileID insteadArgyrios Kyrtzidis2011-09-261-17/+17
| | | | | | | of a ContentCache, since multiple FileIDs can have the same ContentCache but the expanded macro arguments locations will be different. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140521 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename Diagnostic to DiagnosticsEngine as per issue 5397David Blaikie2011-09-251-4/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140478 91177308-0d34-0410-b5e6-96231b3b80d8
* In SourceManager::translateLineCol, handle the case where we are pointingArgyrios Kyrtzidis2011-09-201-4/+9
| | | | | | directly at the end of the source file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140192 91177308-0d34-0410-b5e6-96231b3b80d8
* [libclang] When getting a source location from a file:line:col tripletArgyrios Kyrtzidis2011-09-191-4/+8
| | | | | | | check whether the requested location points inside the precompiled preamble, in which case the returned source location will be a "loaded" one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140060 91177308-0d34-0410-b5e6-96231b3b80d8
* Break SourceManager::translateFileLineCol into translateLineCol that returns theArgyrios Kyrtzidis2011-09-191-7/+22
| | | | | | source location of line:col of a specific FileID. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140059 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename SourceLocation::getFileLocWithOffset -> getLocWithOffset.Argyrios Kyrtzidis2011-09-191-8/+8
| | | | | | It already works (and is useful with) macro locs as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140057 91177308-0d34-0410-b5e6-96231b3b80d8
* For SourceManager::isBeforeInTranslationUnit, a location pointingArgyrios Kyrtzidis2011-09-191-1/+1
| | | | | | | inside a macro argument should be regarded as coming before the location of the expanded tokens. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140053 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove one SourceManager::isInFileID overload and use isOffsetInFileID for ↵Argyrios Kyrtzidis2011-08-231-24/+0
| | | | | | the other. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138381 91177308-0d34-0410-b5e6-96231b3b80d8
* Amend r138129 (reduction of SLocEntries) which introduced performance ↵Argyrios Kyrtzidis2011-08-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | 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". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138380 91177308-0d34-0410-b5e6-96231b3b80d8
* Move a couple of SourceManager functions out-of-line; no functionality change.Argyrios Kyrtzidis2011-08-231-0/+43
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138375 91177308-0d34-0410-b5e6-96231b3b80d8
* Boost the efficiency of SourceManager::getMacroArgExpandedLocation.Argyrios Kyrtzidis2011-08-211-39/+101
| | | | | | | | | | | | | | | | | | Currently getMacroArgExpandedLocation is very inefficient and for the case of a location pointing at the main file it will end up checking almost all of the SLocEntries. Make it faster: -Use a map of macro argument chunks to their expanded source location. The map is for a single source file, it's stored in the file's ContentCache and lazily computed, like the source lines cache. -In SLocEntry's FileInfo add an 'unsigned NumCreatedFIDs' field that keeps track of the number of FileIDs (files and macros) that were created during preprocessing of that particular file SLocEntry. This is useful when computing the macro argument map in skipping included files while scanning for macro arg FileIDs that lexed from a specific source file. Due to padding, the new field does not increase the size of SLocEntry. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138225 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor common functionality into SourceManager::getFileIDSize, no ↵Argyrios Kyrtzidis2011-08-191-14/+1
| | | | | | functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138127 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce SourceManager::getMacroArgExpandedLocation function.Argyrios Kyrtzidis2011-08-171-6/+75
| | | | | | | | | | | | | | | | If we pass it a source location that points inside a function macro argument, the returned location will be the macro location in which the argument was expanded. If a macro argument is used multiple times, the expanded location will be at the first expansion of the argument. e.g. MY_MACRO(foo); ^ Passing a file location pointing at 'foo', will yield a macro location where 'foo' was expanded into. Make SourceManager::getLocation call getMacroArgExpandedLocation as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137794 91177308-0d34-0410-b5e6-96231b3b80d8
* Make SourceManager::isBeforeInTranslationUnit handle macro locations correctly.Argyrios Kyrtzidis2011-08-171-7/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137793 91177308-0d34-0410-b5e6-96231b3b80d8
* Change SourceManager::getDataStructureSizes() to use llvm::capacity_in_bytes().Ted Kremenek2011-07-271-7/+8
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136236 91177308-0d34-0410-b5e6-96231b3b80d8
* clang_getCXTUResourceUsage: Report memory used by data structures in ↵Ted Kremenek2011-07-261-0/+8
| | | | | | SourceManager. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136189 91177308-0d34-0410-b5e6-96231b3b80d8
* Clean up as many of the comments in Basic I can find to talk in terms ofChandler Carruth2011-07-261-28/+25
| | | | | | 'expansion' rather than 'instantiation' for macro source locations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136058 91177308-0d34-0410-b5e6-96231b3b80d8
* Migrate 'Instantiation' data and API bits of SLocEntry to 'Expansion'Chandler Carruth2011-07-261-17/+15
| | | | | | | | etc. With this I think essentially all of the SourceManager APIs are converted. Comments and random other bits of cleanup should be all thats left. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136057 91177308-0d34-0410-b5e6-96231b3b80d8
* Convert InstantiationInfo and much of the related code to ExpansionInfoChandler Carruth2011-07-261-17/+17
| | | | | | | | | and various other 'expansion' based terms. I've tried to reformat where appropriate and catch as many references in comments but I'm going to do several more passes. Also I've tried to expand parameter names to be more clear where appropriate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136056 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename create(MacroArg)InstantiationLoc to create(MacroArg)ExpansionLoc.Chandler Carruth2011-07-261-18/+20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136054 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename SourceManager (and InstantiationInfo) isMacroArgInstantiation APIChandler Carruth2011-07-261-2/+2
| | | | | | to isMacroArgExpansion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136053 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename getInstantiationLineNumber to getExpansionLineNumber in bothChandler Carruth2011-07-251-2/+2
| | | | | | SourceManager and FullSourceLoc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135969 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename getInstantiationColumnNumber to getExpansionColumnNumber in bothChandler Carruth2011-07-251-2/+2
| | | | | | SourceManager and FullSourceLoc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135965 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename getDecomposedInstantiationLoc to getDecomposedExpansionLoc.Chandler Carruth2011-07-251-7/+7
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135962 91177308-0d34-0410-b5e6-96231b3b80d8
* getInstantiationLocSlowCase -> getExpansionLocSlowCaseChandler Carruth2011-07-251-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135961 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename SourceManager::getImmediateInstantiationRange toChandler Carruth2011-07-251-5/+5
| | | | | | getImmediateExpansionRange. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135960 91177308-0d34-0410-b5e6-96231b3b80d8
* Rename SourceManager::getInstantiationRange to getExpansionRange.Chandler Carruth2011-07-251-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135915 91177308-0d34-0410-b5e6-96231b3b80d8
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-231-7/+7
| | | | | | | | | LLVM.h imports them into the clang namespace. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135852 91177308-0d34-0410-b5e6-96231b3b80d8
* Revamp the SourceManager to separate the representation of parsedDouglas Gregor2011-07-191-170/+214
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | source locations from source locations loaded from an AST/PCH file. Previously, loading an AST/PCH file involved carefully pre-allocating space at the beginning of the source manager for the source locations and FileIDs that correspond to the prefix, and then appending the source locations/FileIDs used for parsing the remaining translation unit. This design forced us into loading PCH files early, as a prefix, whic has become a rather significant limitation. This patch splits the SourceManager space into two parts: for source location "addresses", the lower values (growing upward) are used to describe parsed code, while upper values (growing downward) are used for source locations loaded from AST/PCH files. Similarly, positive FileIDs are used to describe parsed code while negative FileIDs are used to file/macro locations loaded from AST/PCH files. As a result, we can load PCH/AST files even during parsing, making various improvemnts in the future possible, e.g., teaching #include <foo.h> to look for and load <foo.h.gch> if it happens to be already available. This patch was originally written by Sebastian Redl, then brought forward to the modern age by Jonathan Turner, and finally polished/finished by me to be committed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135484 91177308-0d34-0410-b5e6-96231b3b80d8
* Keep track of which source locations are part of a macro argumentChandler Carruth2011-07-071-4/+27
| | | | | | | | | | | | | | | | | | | | instantiation and improve diagnostics which are stem from macro arguments to trace the argument itself back through the layers of macro expansion. This requires some tricky handling of the source locations, as the argument appears to be expanded in the opposite direction from the surrounding macro. This patch provides helper routines that encapsulate the logic and explain the reasoning behind how we step through macros during diagnostic printing. This fixes the rest of the test cases originially in PR9279, and later split out into PR10214 and PR10215. There is still some more work we can do here to improve the macro backtrace, but those will follow as separate patches. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134660 91177308-0d34-0410-b5e6-96231b3b80d8
* Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the ↵Argyrios Kyrtzidis2011-07-071-55/+0
| | | | | | Lexer, since they depend on it now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134644 91177308-0d34-0410-b5e6-96231b3b80d8