aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/libclang/LibclangTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-04-23[libclang/C++] Fix clang_File_isEqual for in-memory files (#135773)Jannick Kremer1-0/+49
Add tests for `clang_File_isEqual` (on-disk and in-memory)
2024-04-24[libclang] Compute the right spelling location (#72400)Sebastian Poeplau1-0/+31
Locations inside macro expansions have different spelling/expansion locations. Apply a FIXME to make the libclang function clang_getSpellingLocation return the right spelling location, and adapt the testsuite driver code to use the file location rather than the spelling location to compute source ranges. Co-authored-by: Matthieu Eyraud <eyraud@adacore.com>
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-3/+3
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-08-11[libclang] Expose arguments of clang::annotatefridtjof1-0/+46
This enables easy consumption of arbitrary data added to this annotation in addition to the annotation category, which was already exposed. This is a re-application of the changes in 5aa06b18940c9b96cbf1c31da6aee3fbb92183ed which were reverted in 332a34c71e7675ab4e0ebd28b0d2c15302a81a51. Differential Revision: https://reviews.llvm.org/D151373
2023-08-10Revert "[libclang] Expose arguments of clang::annotate"Vitaly Buka1-44/+0
Introduced a memory leak. This reverts commit 5aa06b18940c9b96cbf1c31da6aee3fbb92183ed.
2023-08-10[libclang] Expose arguments of clang::annotatefridtjof1-0/+44
This enables easy consumption of arbitrary data added to this annotation in addition to the annotation category, which was already exposed. Differential Revision: https://reviews.llvm.org/D151373
2023-07-25[Clang] use unsigned integer constants in unit-test | fixes build error on ↵Kai Stierand1-2/+2
ppc64le-lld-multistage-test Fixes: /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11: warning: comparison of integer expressions of different signedness: ‘const unsigned int’ and ‘const int’ [-Wsign-compare] /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11: warning: comparison of integer expressions of different signedness: ‘const long unsigned int’ and ‘const int’ [-Wsign-compare] Reviewed By: cor3ntin Differential Revision: https://reviews.llvm.org/D156224
2023-07-25[Clang] Fix crash in CIndex, when visiting a static_assert without messageKai Stierand1-0/+74
After implementation of "[Clang] Implement P2741R3 - user-generated static_assert messages" (47ccfd7a89e2a9a747a7114db18db1376324799c) the c indexer crashes when handling a `static_assert` w/o any message. This is caused by using `dyn_cast` to get the literal string, which isn't working on `nullptr`. Reviewed By: cor3ntin Differential Revision: https://reviews.llvm.org/D156053
2023-06-09[libclang] Add CXBinaryOperatorKind and CXUnaryOperatorKindMineGame1591-0/+34
Adds 2 new functions to the C libclang api for retrieving operator kinds for binary and unary operators from cursors. Also adds 2 functions for retrieving the spelling of the new enums. Fixes https://github.com/llvm/llvm-project/issues/29138 Differential Revision: https://reviews.llvm.org/D150910
2023-03-15[libclang] Add index option to store preambles in memoryIgor Kushnir1-0/+25
This commit allows libclang API users to opt into storing PCH in memory instead of temporary files. The option can be set only during CXIndex construction to avoid multithreading issues and confusion or bugs if some preambles are stored in temporary files and others - in memory. The added API works as expected in KDevelop: https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/283 Differential Revision: https://reviews.llvm.org/D145974
2023-03-07Fix build failures with libclang unittest; NFCAaron Ballman1-1/+2
This addresses the issue found by: https://lab.llvm.org/buildbot/#/builders/57/builds/25217 https://lab.llvm.org/buildbot/#/builders/36/builds/31018
2023-03-07[libclang] Add API to override preamble storage pathIgor Kushnir1-1/+164
TempPCHFile::create() calls llvm::sys::fs::createTemporaryFile() to create a file named preamble-*.pch in a system temporary directory. This commit allows overriding the directory where these often many and large preamble-*.pch files are stored. The referenced bug report requests the ability to override the temporary directory path used by libclang. However, overriding the return value of llvm::sys::path::system_temp_directory() was rejected during code review as improper and because it would negatively affect multithreading performance. Finding all places where libclang uses the temporary directory is very difficult. Therefore this commit is limited to override libclang's single known use of the temporary directory. This commit allows to override the preamble storage path only during CXIndex construction to avoid multithreading issues and ensure that all preambles are stored in the same directory. For the same multithreading and consistency reasons, this commit deprecates clang_CXIndex_setGlobalOptions() and clang_CXIndex_setInvocationEmissionPathOption() in favor of specifying these options during CXIndex construction. Adding a new CXIndex constructor function each time a new initialization argument is needed leads to either a large number of function parameters unneeded by most libclang users or to an exponential number of overloads that support different usage requirements. Therefore this commit introduces a new extensible struct CXIndexOptions and a general function clang_createIndexWithOptions(). A libclang user passes a desired preamble storage path to clang_createIndexWithOptions(), which stores it in CIndexer::PreambleStoragePath. Whenever clang_parseTranslationUnit_Impl() is called, it passes CIndexer::PreambleStoragePath to ASTUnit::LoadFromCommandLine(), which stores this argument in ASTUnit::PreambleStoragePath. Whenever ASTUnit::getMainBufferWithPrecompiledPreamble() is called, it passes ASTUnit::PreambleStoragePath to PrecompiledPreamble::Build(). PrecompiledPreamble::Build() forwards the corresponding StoragePath argument to TempPCHFile::create(). If StoragePath is not empty, TempPCHFile::create() stores the preamble-*.pch file in the directory at the specified path rather than in the system temporary directory. The analysis below proves that this passing around of the PreambleStoragePath string is sufficient to guarantee that the libclang user override is used in TempPCHFile::create(). The analysis ignores API uses in test code. TempPCHFile::create() is called only in PrecompiledPreamble::Build(). PrecompiledPreamble::Build() is called only in two places: one in clangd, which is not used by libclang, and one in ASTUnit::getMainBufferWithPrecompiledPreamble(). ASTUnit::getMainBufferWithPrecompiledPreamble() is called in 3 places: ASTUnit::LoadFromCompilerInvocation() [analyzed below]. ASTUnit::Reparse(), which in turn is called only from clang_reparseTranslationUnit_Impl(), which in turn is called only from clang_reparseTranslationUnit(). clang_reparseTranslationUnit() is never called in LLVM code, but is part of public libclang API. This function's documentation requires its translation unit argument to have been built with clang_createTranslationUnitFromSourceFile(). clang_createTranslationUnitFromSourceFile() delegates its work to clang_parseTranslationUnit(), which delegates to clang_parseTranslationUnit2(), which delegates to clang_parseTranslationUnit2FullArgv(), which delegates to clang_parseTranslationUnit_Impl(), which passes CIndexer::PreambleStoragePath to the ASTUnit it creates. ASTUnit::CodeComplete() passes AllowRebuild = false to ASTUnit::getMainBufferWithPrecompiledPreamble(), which makes it return nullptr before calling PrecompiledPreamble::Build(). Both ASTUnit::LoadFromCompilerInvocation() overloads (one of which delegates its work to another) call ASTUnit::getMainBufferWithPrecompiledPreamble() only if their argument PrecompilePreambleAfterNParses > 0. LoadFromCompilerInvocation() is called in: ASTBuilderAction::runInvocation() keeps the default parameter value of PrecompilePreambleAfterNParses = 0, meaning that the preamble file is never created from here. ASTUnit::LoadFromCommandLine(). ASTUnit::LoadFromCommandLine() is called in two places: CrossTranslationUnitContext::ASTLoader::loadFromSource() keeps the default parameter value of PrecompilePreambleAfterNParses = 0, meaning that the preamble file is never created from here. clang_parseTranslationUnit_Impl(), which passes CIndexer::PreambleStoragePath to the ASTUnit it creates. Therefore, the overridden preamble storage path is always used in TempPCHFile::create(). TempPCHFile::create() uses PreambleStoragePath in the same way as LibclangInvocationReporter() uses InvocationEmissionPath. The existing documentation for clang_CXIndex_setInvocationEmissionPathOption() does not specify ownership, encoding, separator or relative vs absolute path requirements. So the documentation for CXIndexOptions::PreambleStoragePath doesn't either. The assumptions are: no ownership transfer; UTF-8 encoding; native separators. Both relative and absolute paths are supported. The added API works as expected in KDevelop: https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/283 Fixes: https://github.com/llvm/llvm-project/issues/51847 Differential Revision: https://reviews.llvm.org/D143418
2023-03-01LibclangTest: remove libclang-test-* tmp dir reliablyIgor Kushnir1-0/+2
Temporary directories created by two LibclangReparseTest tests - ReparseWithModule and clang_parseTranslationUnit2FullArgv - remained in the system temporary directory after running libclangTests, because not all files and subdirectories created in TestDir were added to set LibclangParseTest::Files. Differential Revision: https://reviews.llvm.org/D143415
2023-01-02[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-1/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-26[clang] Use std::size (NFC)Kazu Hirata1-3/+3
std::size, introduced in C++17, allows us to directly obtain the number of elements of an array.
2022-10-11[libclang] CIndex: Visit UsingTypeLoc as TypeRefKai Stierand1-22/+37
Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D135555
2022-09-02Expose QualType::getNonReferenceType in libclangLuca Di Sera1-0/+40
The method is now wrapped by clang_getNonReferenceType. A declaration for clang_getNonReferenceType was added to clang-c/Index.h to expose it to user of the library. An implementation for clang_getNonReferenceType was introduced in CXType.cpp, wrapping the equivalent method of the underlying QualType of a CXType. An export symbol for the new function was added to libclang.map under the LLVM_16 version entry. A test was added to LibclangTest.cpp that tests the removal of ref-qualifiers for some CXTypes. The release-notes for the clang project was updated to include a notification of the new addition under the "libclang" section. Differential Revision: https://reviews.llvm.org/D133195
2022-08-29Expose QualType::getUnqualifiedType in libclangLuca Di Sera1-0/+48
The method is now wrapped by clang_getUnqualifiedType. A declaration for clang_getUnqualifiedType was added to clang-c/Index.h to expose it to user of the library. An implementation for clang_getUnqualifiedType was introduced in CXType.cpp that wraps the equivalent method of the underlying QualType of a CXType. An export symbol was added to libclang.map under the new version entry LLVM_16. A test was added to LibclangTest.cpp that tests the removal of qualifiers for some CXTypes. Differential Revision: https://reviews.llvm.org/D132749
2020-09-04[libclang] Add CXRewriter to libclang APIJan Korous1-0/+88
Differential Revision: https://reviews.llvm.org/D86992
2020-09-04[libclang] Expose couple more AST details via cursorsJan Korous1-0/+106
Differential Revision: https://reviews.llvm.org/D86991
2019-09-03[libclang][test][NFC] Split off fixture from tests.Jan Korous1-71/+1
llvm-svn: 370825
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
2019-01-08[libclang] Recommit r336590 with a fix for the memory leak in the testAlex Lorenz1-0/+42
The original commit had a memory leak in the test has a leak as it doesn't dispose of the evaluated cursor result. This also contains the follow-up NFC refactoring commit r336591. rdar://45893054 Original commit message: [libclang] evalute compound statement cursors before trying to evaluate the cursor like a declaration This change fixes a bug in libclang in which it tries to evaluate a statement cursor as a declaration cursor, because that statement still has a pointer to the declaration parent. rdar://38888477 Differential Revision: https://reviews.llvm.org/D49051 llvm-svn: 350666
2018-07-10Revert r336590 "[libclang] evalute compound statement cursors before trying ↵Evgeniy Stepanov1-41/+0
to evaluate" New memory leaks in LibclangParseTest_EvaluateChildExpression_Test::TestBody() llvm-svn: 336716
2018-07-09[libclang] evalute compound statement cursors before trying to evaluateAlex Lorenz1-0/+41
the cursor like a declaration This change fixes a bug in libclang in which it tries to evaluate a statement cursor as a declaration cursor, because that statement still has a pointer to the declaration parent. rdar://38888477 Differential Revision: https://reviews.llvm.org/D49051 llvm-svn: 336590
2018-05-15[clang] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen1-5/+7
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Explicitly avoided changing the strings in the clang-format tests. Differential Revision: https://reviews.llvm.org/D44975 llvm-svn: 332350
2018-04-21[libclang] Fix LibclangReparseTest.FileName when TMPDIR is set to a symlinkPetr Pavlu1-2/+3
Fix testing of clang_File_tryGetRealPathName() in LibclangReparseTest.FileName when executing in an environment which has TMPDIR set to a symbolic link that points to an actual directory. The test would fail because the name returned by clang_File_tryGetRealPathName() has the symlink resolved but the test compared it to the original filename of a temporary file. The patch addresses the problem by checking only that the value returned by clang_File_tryGetRealPathName() ends with "main.cpp". Additionally, the patch makes the previous assertion in the test that checks result of clang_getFileName() stricter. It newly verifies that the name returned by the function is exactly same as what was given to clang_parseTranslationUnit()/clang_getFile(). Differential Revision: https://reviews.llvm.org/D45807 llvm-svn: 330507
2018-04-16Defer adding keywords to the identifier table until after the language ↵Aaron Ballman1-0/+64
options have been loaded from the AST file. This fixes issues with "class" being reported as an identifier in "enum class" because the construct is not present when using default language options. Patch by Johann Klähn. llvm-svn: 330159
2018-04-07[libclang] Add clang_File_tryGetRealPathNameFangrui Song1-0/+15
Summary: clang_getFileName() may return a path relative to WorkingDir. On Arch Linux, during clang_indexTranslationUnit(), clang_getFileName() on CXIdxIncludedIncludedFileInfo::file may return "/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/string", for `#include <string>`. I presume WorkingDir is somehow changed to /usr/lib or /usr/include and clang_getFileName() returns a path relative to WorkingDir. clang_File_tryGetRealPathName() returns "/usr/include/c++/7.3.0/string" which is more useful for the indexer in this case. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42893 llvm-svn: 329515
2018-01-16[libclang] Add PrintingPolicy for pretty printing declarationsJonathan Coe1-0/+30
Summary: Introduce clang_getCursorPrettyPrinted() for pretty printing declarations. Expose also PrintingPolicy, so the user gets more fine-grained control of the entities being printed. The already existing clang_getCursorDisplayName() is pretty limited - for example, it does not handle return types, parameter names or default arguments for function declarations. Addressing these issues in clang_getCursorDisplayName() would mean to duplicate existing code (e.g. clang::DeclPrinter), so rather expose new API to access the existing functionality. Reviewed By: jbcoe Subscribers: cfe-commits Tags: #clang Patch by nik (Nikolai Kosjar) Differential Revision: https://reviews.llvm.org/D39903 llvm-svn: 322540
2018-01-15Fixed memory leak in unit test introduced in my previous commit r322503Cameron Desrochers1-0/+3
llvm-svn: 322513
2018-01-15[PCH] Serialize skipped preprocessor rangesCameron Desrochers1-0/+78
The skipped preprocessor ranges are now serialized in the AST PCH file. This fixes, for example, libclang's clang_getSkippedRanges() returning zero ranges after reparsing a translation unit. Differential Revision: https://reviews.llvm.org/D20124 llvm-svn: 322503
2017-12-11Revert 320391: Certain targets are failing, pulling back to diagnose.Erich Keane1-3/+1
llvm-svn: 320398
2017-12-11For Linux/gnu compatibility, preinclude <stdc-predef.h> if the file is availableErich Keane1-1/+3
As reported in llvm bugzilla 32377. Here’s a patch to add preinclude of stdc-predef.h. The gcc documentation says “On GNU/Linux, <stdc-predef.h> is pre-included.” See https://gcc.gnu.org/gcc-4.8/porting_to.html; The preinclude is inhibited with –ffreestanding. Basically I fixed the failing test cases by adding –ffreestanding which inhibits this behavior. I fixed all the failing tests, including some in extra/test, there's a separate patch for that which is linked here Note: this is a recommit after a test failure took down the original (r318669) Patch By: mibintc Differential Revision: https://reviews.llvm.org/D34158 llvm-svn: 320391
2016-08-18Fixed more signed/unsigned mismatch warnings introduced in my change at r279076Cameron Desrochers1-5/+5
llvm-svn: 279145
2016-08-18Removed use of 'emplace' on std::map, since not all buildbot slaves support itCameron Desrochers1-2/+2
llvm-svn: 279114
2016-08-18[libclang] Fixed signed/unsigned comparison warning introduced in my ↵Cameron Desrochers1-1/+1
revision r279076 llvm-svn: 279085
2016-08-18[libclang] Add clang_getAllSkippedRanges functionCameron Desrochers1-2/+80
This complements the clang_getSkippedRanges function which returns skipped ranges filtered by a specific file. This function is useful when all the ranges are desired (and a lot more efficient than the equivalent of asking for the ranges file by file, since the implementation of clang_getSkippedRanges iterates over all ranges anyway). Differential Revision: https://reviews.llvm.org/D20132 llvm-svn: 279076
2016-02-12tests: Add explicit -stdlib=libstdc++ to tests that require itJonas Hahnfeld1-1/+1
This will be needed for the next commit that allows to switch the default C++ library which would otherwise make these tests fail. llvm-svn: 260661
2015-12-01Avoid picking up system headers in unittest by providing a fake libstdc++ ↵Benjamin Kramer1-2/+4
with a ridiculously high version number. The host libstdc++ may be horribly broken and we want the fake one to be picked up. This workaround is lame but I don't see a better way. llvm-svn: 254446
2015-11-30Add --gcc-toolchain= to one of the libclang unitests to fix issue related to Samuel Antao1-1/+2
the gcc libraries clang picks for when it was configures with a user defined path. llvm-svn: 254306
2015-11-18[libclang] Add entry points that take a full command line including argv[0].Benjamin Kramer1-0/+26
This provides both a more uniform interface and makes libclang behave like clang tooling wrt relative paths against argv[0]. This is necessary for finding paths to a c++ standard library relative to a clang binary given in a compilation database. It can also be used to find paths relative to libclang.so if the full path to it is passed in. Differential Revision: http://reviews.llvm.org/D14695 llvm-svn: 253466
2015-07-09Add clang_free to libclang to free memory allocated in libclang.Yaron Keren1-2/+2
One of the problems libclang tests has running under Windows is memory allocated in libclang.dll but being freed in the test executable, possibly by a different memory manager. This patch exposes a new export function, clang_free(), used to free any allocated memory with the same libclang.dll memory manager that allocated the memory. http://reviews.llvm.org/D10949 Reviewed by Reid Kleckner, Douglas Gregor. llvm-svn: 241789
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-1/+1
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-1/+1
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
2015-04-11Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko1-2/+2
Summary: The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix Reviewers: dblaikie Reviewed By: dblaikie Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D8926 llvm-svn: 234678
2015-01-14[cleanup] Re-sort the #include lines using llvm/utils/sort_includes.pyChandler Carruth1-1/+1
No functionality changed, this is a purely mechanical cleanup to ensure the #include order remains consistent across the project. llvm-svn: 225975
2014-07-15VirtualFileSystem: Correctly generate the mapping for an empty VFSJustin Bogner1-0/+10
In r209332 I accidentally broke generation of empty VFS maps. This fixes the issue and adds a test. llvm-svn: 213028
2014-07-07Use temporary module cache in testBen Langmuir1-1/+3
llvm-svn: 212467
2014-06-30Consider module depedencies when checking a preamble in libclangBen Langmuir1-1/+34
Add module dependencies (header files, module map files) to the list of files to check when deciding whether to rebuild a preamble. That fixes using preambles with module imports so long as they are in non-overridden files. My intent is to use to unify the existing dependency collectors to the new “DependencyCollectory” interface from this commit, starting with the DependencyFileGenerator. llvm-svn: 212060