aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceLocation.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-11-17Refactor StaticAnalyzer to use `clang::SarifDocumentWriter`Vaibhav Yenamandra1-0/+4
Refactor StaticAnalyzer to use clang::SarifDocumentWriter for serializing sarif diagnostics. Uses clang::SarifDocumentWriter to generate SARIF output in the StaticAnalyzer. Various bugfixes are also made to clang::SarifDocumentWriter. Summary of changes: clang/lib/Basic/Sarif.cpp: * Fix bug in adjustColumnPos introduced from prev move, it now uses FullSourceLoc::getDecomposedExpansionLoc which provides the correct location (in the presence of macros) instead of FullSourceLoc::getDecomposedLoc. * Fix createTextRegion so that it handles caret ranges correctly, this should bring it to parity with the previous implementation. clang/test/Analysis/diagnostics/Inputs/expected-sarif: * Update the schema URL to the offical website * Add the emitted defaultConfiguration sections to all rules * Annotate results with the "level" property clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp: * Update SarifDiagnostics class to hold a clang::SarifDocumentWriter that it uses to convert diagnostics to SARIF.
2022-11-07[clang][NFC] Use c++17 style variable type traitsNathan James1-2/+2
This was done as a test for D137302 and it makes sense to push these changes Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D137491
2022-06-24Revert "[clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` ↵Aaron Ballman1-27/+0
interface" This reverts commit 6546fdbe36fd1227d7f23f89fd9a9825813b3de9. This broke some build bots due to a layering issue: https://lab.llvm.org/buildbot/#/builders/57/builds/19244
2022-06-24[clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interfaceVaibhav Yenamandra1-0/+27
Create an interface for writing SARIF documents from within clang: The primary intent of this change is to introduce the interface clang::SarifDocumentWriter, which allows incrementally adding diagnostic data to a JSON backed document. The proposed interface is not yet connected to the compiler internals, which will be covered in future work. As such this change will not change the input/output interface of clang. This change also introduces the clang::FullSourceRange type that is modeled after clang::SourceRange + clang::FullSourceLoc, this is useful for packaging a pair of clang::SourceLocation objects with their corresponding SourceManagers. Previous discussions: RFC for this change: https://lists.llvm.org/pipermail/cfe-dev/2021-March/067907.html https://lists.llvm.org/pipermail/cfe-dev/2021-July/068480.html SARIF Standard (2.1.0): https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html Differential Revision: https://reviews.llvm.org/D109701
2021-12-09[NFC][clang] Return underlying strings directly instead of OS.str()Logan Smith1-2/+2
This avoids an unnecessary copy required by 'return OS.str()', allowing instead for NRVO or implicit move. The .str() call (which flushes the stream) is no longer required since 65b13610a5226b84889b923bae884ba395ad084d, which made raw_string_ostream unbuffered by default. Differential Revision: https://reviews.llvm.org/D115374
2021-07-21[clang] Introduce SourceLocation::[U]IntTy typedefs.Simon Tatham1-1/+1
This is part of a patch series working towards the ability to make SourceLocation into a 64-bit type to handle larger translation units. NFC: this patch introduces typedefs for the integer type used by SourceLocation and makes all the boring changes to use the typedefs everywhere, but for the moment, they are unconditionally defined to uint32_t. Patch originally by Mikhail Maltsev. Reviewed By: tmatheson Differential Revision: https://reviews.llvm.org/D105492
2021-01-22[clang][Tooling] Get rid of a hack in SymbolOccurrences, NFCIMikhail Maltsev1-0/+8
The class `SymbolOccurrences` can store either a single `SourceRange` in-place or multiple `SourceRanges` on the heap. In the latter case the number of source ranges is stored in the internal representation of the beginning `SourceLocation` of the in-place `SourceRange` object. This change gets rid of such hack by placing `SourceRange` in a union which holds either a valid `SourceRange` or an `unsigned int` (a number of ranges). The change also adds `static_assert`s that check that `SourceRange` and `SourceLocation` are trivially destructible (this is required for the current patch and for D94237 which has already been committed). Reviewed By: MarkMurrayARM, simon_tatham Differential Revision: https://reviews.llvm.org/D94599
2020-10-27[clang][Basic] Integrate SourceLocation with FoldingSet, NFCIMikhail Maltsev1-0/+6
This patch removes the necessity to access the SourceLocation internal representation in several places that use FoldingSet objects. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D69844
2020-10-20[clang][Basic] Make SourceLocation usable as key in hash maps, NFCIMikhail Maltsev1-0/+5
This change creates a `DenseMapInfo` trait specialization for the SourceLocation class. The empty key, the tombstone key, and the hash function are identical to `DenseMapInfo<unsigned>`, because we already have hash maps that use raw the representation of `SourceLocation` as a key. The update of existing `DenseMap`s containing raw representation of `SourceLocation`s will be done in a follow-up patch. As an example the patch makes use of the new trait in one instance: clang-tidy/google/UpgradeGoogletestCaseCheck.{h,cpp} Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D89719
2020-10-14clang/Basic: Stop using SourceManager::getBuffer, NFCDuncan P. N. Exon Smith1-1/+1
Update clang/lib/Basic to stop relying on a `MemoryBuffer*`, using the `MemoryBufferRef` from `getBufferOrNone` or `getBufferOrFake` instead of `getBuffer`. Differential Revision: https://reviews.llvm.org/D89394
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
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
2018-08-30Add dump() method for SourceRangeStephen Kelly1-0/+54
Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50662 llvm-svn: 341140
2018-08-15Add a newline to SourceLocation dump outputStephen Kelly1-0/+1
Summary: Migrate callers to print(). dump() should be useful to downstreams and third parties as a debugging aid. Everyone trips up on this and creates confusing output. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50661 llvm-svn: 339810
2018-07-30Remove trailing spaceFangrui Song1-1/+1
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-04-30PR37189 Fix incorrect end source location and spelling for a split '>>' token.Richard Smith1-18/+0
When a '>>' token is split into two '>' tokens (in C++11 onwards), or (as an extension) when we do the same for other tokens starting with a '>', we can't just use a location pointing to the first '>' as the location of the split token, because that would result in our miscomputing the length and spelling for the token. As a consequence, for example, a refactoring replacing 'A<X>' with something else would sometimes replace one character too many, and similarly diagnostics highlighting a template-id source range would highlight one character too many. Fix this by creating an expansion range covering the first character of the '>>' token, whose spelling is '>'. For this to work, we generalize the expansion range of a macro FileID to be either a token range (the common case) or a character range (used in this new case). llvm-svn: 331155
2018-02-16[Basic] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-3/+9
other minor fixes (NFC). llvm-svn: 325412
2017-06-27Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc""Christof Douma1-0/+70
This reverts commit r305688 meaning it reintroduces r305684. To repeat: [NFC] Refactor DiagnosticRenderer to use FullSourceLoc Move the DiagnosticRenderer and its dependents to using FullSourceLocs instead of a SourceLocation and SourceManager pointer. The changeset is rather large but entirely mechanical. This is step one to allow DiagnosticRenderer to take either llvm::SMLocs or clang::SourceLocations. This breaks clang-tidy and clng-query which will be fixed in a commit soon after. Patch by Sanne Wouda Differential Revision: https://reviews.llvm.org/D31709 llvm-svn: 306384
2017-06-19Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"Christof Douma1-70/+0
This reverts commit 305684. This patch breaks extra/tools/clang-tidy llvm-svn: 305688
2017-06-19[NFC] Refactor DiagnosticRenderer to use FullSourceLocChristof Douma1-0/+70
Move the DiagnosticRenderer and its dependents to using FullSourceLocs instead of a SourceLocation and SourceManager pointer. The changeset is rather large but entirely mechanical. This is step one to allow DiagnosticRenderer to take either llvm::SMLocs or clang::SourceLocations. Patch by Sanne Wouda Review: https://reviews.llvm.org/D31709 Change-Id: If351a112cdf6718e2d3ef6721b8da9c6376b32dd llvm-svn: 305684
2016-07-18[NFC] Header cleanupMehdi Amini1-1/+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
2015-06-09Removing spurious semi colons; NFC.Aaron Ballman1-1/+1
llvm-svn: 239400
2014-08-18Inline function into only use.Rafael Espindola1-6/+2
llvm-svn: 215925
2014-01-04Only mark dump() function definitions 'used' in debug buildsAlp Toker1-3/+4
This has the dual effect of (1) enabling more dead-stripping in release builds and (2) ensuring that debug helper functions aren't stripped away in debug builds, as they're intended to be called from the debugger. Note that the attribute is applied to definitions rather than declarations in headers going forward because it's now conditional on NDEBUG: /// \brief Mark debug helper function definitions like dump() that should not be /// stripped from debug builds. Requires corresponding macro added in LLVM r198456. llvm-svn: 198489
2012-12-12PR14581: Make SourceLocation::printToString work, or it will always return ↵Benjamin Kramer1-1/+1
an empty string. No test case, this is debugging code. llvm-svn: 169980
2012-11-09Add a SourceLocation::printToString() that returns in a std::string what dump()Argyrios Kyrtzidis1-0/+7
writes to stderr; for debugging purposes. llvm-svn: 167629
2012-02-26Move FullSourceLoc::dump into the .cpp file, the used attribute made us emit ↵Benjamin Kramer1-0/+4
this into every TU that includes SourceLocation.h. llvm-svn: 151493
2011-07-26Clean up as many of the comments in Basic I can find to talk in terms ofChandler Carruth1-1/+1
'expansion' rather than 'instantiation' for macro source locations. llvm-svn: 136058
2011-07-25Rename getInstantiationLineNumber to getExpansionLineNumber in bothChandler Carruth1-2/+2
SourceManager and FullSourceLoc. llvm-svn: 135969
2011-07-25Rename getInstantiationColumnNumber to getExpansionColumnNumber in bothChandler Carruth1-2/+2
SourceManager and FullSourceLoc. llvm-svn: 135965
2011-07-25Mechanically rename SourceManager::getInstantiationLoc andChandler Carruth1-3/+3
FullSourceLoc::getInstantiationLoc to ...::getExpansionLoc. This is part of the API and documentation update from 'instantiation' as the term for macros to 'expansion'. llvm-svn: 135914
2011-07-23remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner1-3/+3
LLVM.h imports them into the clang namespace. llvm-svn: 135852
2010-12-15Fix diagnostic pragmas.Argyrios Kyrtzidis1-0/+5
Diagnostic pragmas are broken because we don't keep track of the diagnostic state changes and we only check the current/latest state. Problems manifest if a diagnostic is emitted for a source line that has different diagnostic state than the current state; this can affect a lot of places, like C++ inline methods, template instantiations, the lexer, etc. Fix the issue by having the Diagnostic object keep track of the source location of the pragmas so that it is able to know what is the diagnostic state at any given source location. Fixes rdar://8365684. llvm-svn: 121873
2010-11-12Make sure to always check the result ofDouglas Gregor1-0/+5
SourceManager::getPresumedLoc(), so that we don't try to make use of an invalid presumed location. Doing so can cause crashes. llvm-svn: 118885
2010-03-16Update get*LineNumber() and get*ColumnNumber() functions to pass theDouglas Gregor1-8/+8
Invalid bit through; there are no safety-critical callers of these functions. llvm-svn: 98674
2010-03-16Audit all callers of SourceManager::getCharacterData(); update some ofDouglas Gregor1-2/+2
them to recover more gracefully on failure. llvm-svn: 98672
2010-03-16Audit all getBuffer() callers (for both the FullSourceLoc andDouglas Gregor1-4/+4
SourceManager versions), updating those callers that need to recover gracefully from failure. llvm-svn: 98665
2010-03-16Switch another function to StringRef instead of char pointer pairs.Benjamin Kramer1-3/+2
llvm-svn: 98631
2009-09-09Remove tabs, and whitespace cleanups.Mike Stump1-2/+2
llvm-svn: 81346
2009-04-22Remove the serialization code that predates precompiledDouglas Gregor1-22/+0
headers. Future approaches to (de-)serializing ASTs will be based on the PCH infrastructure. llvm-svn: 69828
2009-03-10Remove some now-unneeded calls to llvm::errs().flush().Daniel Dunbar1-1/+0
llvm-svn: 66555
2009-03-10Add FullSourceLoc::getDecomposedLoc.Ted Kremenek1-0/+4
llvm-svn: 66522
2009-03-05Include information about compound statements when crashing in sema or theChris Lattner1-11/+35
parser. For example, we now print out: 0. t.c:5:10: in compound statement {} 1. t.c:3:12: in compound statement {} 2. clang t.c -fsyntax-only llvm-svn: 66108
2009-03-02improve compatibility with GCC 4.4, patch by Michel Salim (PR3697)Chris Lattner1-0/+1
llvm-svn: 65884
2009-02-04lower the interface to getLineNumber like we did forChris Lattner1-5/+0
getColumnNumber. This fixes a FIXME in SourceManager::getPresumedLoc because we now just decompose the sloc once. llvm-svn: 63701
2009-02-04make SM::getColumnNumber take a predecomposed FileID/offset, whichChris Lattner1-6/+0
makes it clear to clients that they have to pick an instantiation or spelling location before calling it and allows optimization based on that. llvm-svn: 63698
2009-01-28Add method FullSourceLoc::getBufferData().Ted Kremenek1-0/+6
llvm-svn: 63229
2009-01-27Introduce a new PresumedLoc class to represent the concept of a locationChris Lattner1-29/+23
as reported to the user and as manipulated by #line. This is what __FILE__, __INCLUDE_LEVEL__, diagnostics and other things should follow (but not dependency generation!). This patch also includes several cleanups along the way: - SourceLocation now has a dump method, and several other places that did similar things now use it. - I cleaned up some code in AnalysisConsumer, but it should probably be simplified further now that NamedDecl is better. - TextDiagnosticPrinter is now simplified and cleaned up a bit. This patch is a prerequisite for #line, but does not actually provide any #line functionality. llvm-svn: 63098
2009-01-19Rename SourceManager::getCanonicalFileID -> getFileID. There isChris Lattner1-2/+2
no longer such thing as a non-canonical FileID. llvm-svn: 62499
2009-01-19remove the SourceManager:: and FullSourceLoc::getFileEntryForLoc methods.Chris Lattner1-5/+0
llvm-svn: 62496
2009-01-19some minor cleanups to SourceManager, and eliminate the Chris Lattner1-1/+1
SourceManager::getBuffer(SourceLocation) method. llvm-svn: 62494