As an addition to CXTranslationUnit_SkipFunctionBodies, provide the
new option CXTranslationUnit_LimitSkipFunctionBodiesToPreamble,
which constraints the skipping of functions bodies to the preamble
only. Function bodies in the main file are not affected if this
option is set.
Skipping function bodies only in the preamble is what clangd already
does and the introduced flag implements it for libclang clients.
Patch by Nikolai Kosjar.
Differential Revision: https://reviews.llvm.org/D45815
llvm-svn: 332578
This commit relands r331904.
Adding a SrcMgr::CharacteristicKind parameter to the InclusionDirective
in PPCallbacks, and updating calls to that function. This will be useful
in https://reviews.llvm.org/D43778 to determine which includes are
system
headers.
Differential Revision: https://reviews.llvm.org/D46614
llvm-svn: 332021
Adding a SrcMgr::CharacteristicKind parameter to the InclusionDirective
in PPCallbacks, and updating calls to that function. This will be useful
in https://reviews.llvm.org/D43778 to determine which includes are system
headers.
Differential Revision: https://reviews.llvm.org/D46614
llvm-svn: 331904
This is similar to the LLVM change https://reviews.llvm.org/D46290.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
Differential Revision: https://reviews.llvm.org/D46320
llvm-svn: 331834
libclang exposes the type of 'int (Foo);' (a global variable of type int
called Foo) as CXType_Unexposed. This is because Clang represents Foo's
type as ParenType{BuiltinType{Int}}, and libclang does not handle
ParenType.
Make libclang return CXType_Int as the type of 'int (Foo);' by
unwrapping ParenType transparently.
Patch by Matt Glazar.
Differential Revision: https://reviews.llvm.org/D45713
llvm-svn: 331306
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
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in
HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the
default macro instead of a reinvented one.
See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev.
No intended behavior change.
llvm-svn: 331069
This patch is a tweak of changyu's patch: https://reviews.llvm.org/D40381. It differs in that the recognition of the 'concept' token is moved into the machinery that recognizes declaration-specifiers - this allows us to leverage the attribute handling machinery more seamlessly.
See the test file to get a sense of the basic parsing that this patch supports.
There is much more work to be done before concepts are usable...
Thanks Changyu!
llvm-svn: 330794
All attributes have a source range associated with it. However, implicit
attributes are added by the compiler, and not added because the user
wrote something in the input. So no token type should be set to
CXCursor_*Attr.
The problem was visible when a class gets marked by e.g.
MSInheritanceAttr, which has the full CXXRecordDecl's range as its
own range. The effect of marking that range as CXCursor_UnexposedAttr
was that all cursors for the record decl, including all child decls,
would become CXCursor_UnexposedAttr.
llvm-svn: 330692
Summary:
The FileID/Offset conversion is lossy. The code takes the fileLoc, which loses
e.g. the spelling location in some macro cases.
Instead, pass the original SourceLocation which preserves all information, and
update consumers to match current behavior.
This allows us to fix two bugs in clangd that need the spelling location.
Reviewers: akyrtzi, arphaman
Subscribers: ilya-biryukov, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D45014
llvm-svn: 329570
They were failing on Windows because the output YAML didn't parse:
YAML:1:664: error: Unrecognized escape code!
{"toolchain":"D:\\buildslave\\clang-x64-ninja-win7\\stage1",
"libclang.operation":"complete", "libclang.opts":1, "args":["clang",
"-fno-spell-checking",
"D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\test\Index\create-libclang-completion-reproducer.c",
"-Xclang", "-detailed-preprocessing-record",
"-fallow-editor-placeholders"],
"invocation-args":["-code-completion-at=D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\test\Index\create-libclang-completion-reproducer.c:10:1"],
"unsaved_file_hashes":[{"name":"D:\\buildslave\\clang-x64-ninja-win7\\llvm\\tools\\clang\\test\\Index\\create-libclang-completion-reproducer.c",
"md5":"aee23773de90e665992b48209351d70e"}]}
This adds some more escaping to try to make it work.
llvm-svn: 329558
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
-cc1gen-reproducer driver option
The recommit fixes:
- An MSAN failure (CCPrintOptions wasn't initialized in the Driver)
- Ensures that the strings in the libclang invocation files are escaped
Original message:
This commit is a follow up to the previous work that recorded Libclang invocations
into temporary files: r319702.
It adds a new -cc1 mode to clang: -cc1gen-reproducer. The goal of this mode is to generate
Clang reproducer files for Libclang tool invocation. The JSON format in the invocation
files is not really intended to be stable, so Libclang and Clang should be of the same version
when generating reproducers.
The new mode emits the information about the temporary files and Libclang-specific information
to stdout using JSON.
rdar://35322614
Differential Revision: https://reviews.llvm.org/D40983
llvm-svn: 329465
Found via codespell -q 3 -I ../clang-whitelist.txt
Where whitelist consists of:
archtype
cas
classs
checkk
compres
definit
frome
iff
inteval
ith
lod
methode
nd
optin
ot
pres
statics
te
thru
Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few
files that have dubious fixes reverted.)
Differential revision: https://reviews.llvm.org/D44188
llvm-svn: 329399
This reverts r328795 which introduced an issue with referencing __global__
function templates. More details in the original review D44747.
llvm-svn: 329099
This patch sets target specific calling convention for CUDA kernels in IR.
Patch by Greg Rodgers.
Revised and lit test added by Yaxun Liu.
Differential Revision: https://reviews.llvm.org/D44747
llvm-svn: 328795
r327219 added wrappers to std::sort which randomly shuffle the container before
sorting. This will help in uncovering non-determinism caused due to undefined
sorting order of objects having the same key.
To make use of that infrastructure we need to invoke llvm::sort instead of
std::sort.
llvm-svn: 328636
If the value returned by `malloc`, `calloc` or `realloc` is not checked
for null pointer, this change replaces them for `safe_malloc`,
`safe_calloc` or `safe_realloc`, which are defined in the namespace `llvm`.
These function report fatal error on out of memory.
In the plain C files, assertion statements are added to ensure that memory
is successfully allocated.
The aim of this change is to get better diagnostics of OOM on Windows.
Differential Revision: https://reviews.llvm.org/D43017
llvm-svn: 325661
Summary:
CXIdxEntityRefInfo contains the member `CXIdxEntityRefKind kind;` to
differentiate implicit and direct calls. However, there are more roles
defined in SymbolRole. Among them, `Read/Write` are probably the most
useful ones as they can be used to differentiate Read/Write occurrences
of a symbol for document highlight in a text document.
See `export namespace DocumentHighlightKind`
on https://microsoft.github.io/language-server-protocol/specification
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D42895
llvm-svn: 324914
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
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
Summary:
Enumerating the contents of a namespace or global scope will omit any
decls that aren't already loaded, instead of deserializing them from the
PCH.
This allows a fast hybrid code completion where symbols from headers are
provided by an external index. (Sema already exposes the information
needed to do a reasonabl job of filtering them).
Clangd plans to implement this hybrid.
This option is just a hint - callers still need to postfilter results if
they want to *avoid* completing decls outside the main file.
Reviewers: bkramer, ilya-biryukov
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D41989
llvm-svn: 322371
Summary:
DC may sometimes be NULL and getContainerInfo(DC, Container) will dereference a null pointer.
Default template arguments (the following example and many test files in https://github.com/nlohmann/json)
may cause null pointer dereference.
```c++
template <typename>
struct actor;
template <template <typename> class Actor = actor>
struct terminal;
```
In tools/libclang/CXIndexDataConsumer.cpp#L203
handleReference(ND, Loc, Cursor,
dyn_cast_or_null<NamedDecl>(ASTNode.Parent),
ASTNode.ContainerDC, ASTNode.OrigE, Kind);
`dyn_cast_or_null<NamedDecl>(ASTNode.Parent)` is somehow a null pointer and in tools/libclang/CXIndexDataConsumer.cpp:935
ContainerInfo Container;
getContainerInfo(DC, Container);
The null DC is casted `ContInfo.cursor = getCursor(cast<Decl>(DC));` and SIGSEGV.
```
See discussions in https://github.com/jacobdufault/cquery/issues/219https://github.com/jacobdufault/cquery/issues/192
Reviewers: akyrtzi, sammccall, yvvan
Reviewed By: sammccall
Subscribers: mehdi_amini, cfe-commits
Differential Revision: https://reviews.llvm.org/D41575
llvm-svn: 322017
This is useful for e.g. highlighting purposes in an IDE.
Note: First version of this patch was reverted due to failing tests in
opencl-types.cl with -target ppc64le-unknown-linux. These tests are
adapted now.
Patch by Nikolai Kosjar.
Differential Revision: https://reviews.llvm.org/D40072
llvm-svn: 321794
This one was rolled back as follow-up to the failing commit.
Second try.
For the function declaration
auto foo5(Foo) -> Foo;
the parameter tokens were mapped to cursors representing the
FunctionDecl:
Keyword: "auto" [1:1 - 1:5] FunctionDecl=test5:1:6
Identifier: "test5" [1:6 - 1:11] FunctionDecl=test5:1:6
Punctuation: "(" [1:11 - 1:12] FunctionDecl=test5:1:6
Identifier: "X" [1:12 - 1:13] FunctionDecl=test5:1:6 // Ops, not a TypeRef
Punctuation: ")" [1:13 - 1:14] FunctionDecl=test5:1:6
Punctuation: "->" [1:15 - 1:17] FunctionDecl=test5:1:6
Identifier: "X" [1:18 - 1:19] TypeRef=struct X:7:8
Punctuation: ";" [1:19 - 1:20]
Fix this by ensuring that the trailing return type is not visited as
first.
Patch by Nikolai Kosjar.
Differential Revision: https://reviews.llvm.org/D40561
llvm-svn: 321709
This broke test/Index/opencl-types.cl on several buildbots:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/3294http://lab.llvm.org:8011/builders/clang-ppc64be-linux-multistage/builds/6498http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/5239
> [libclang] Support querying whether a declaration is invalid
>
> This is useful for e.g. highlighting purposes in an IDE.
>
> Patch by Nikolai Kosjar.
>
> Differential Revision: https://reviews.llvm.org/D40072
Also reverting follow-ups that otherwise caused conflicts for the
revert:
r321700 "Fix line endings."
r321701 "Fix more line endings."
r321698 "[libclang] Fix cursors for functions with trailing return type"
> For the function declaration
>
> auto foo5(Foo) -> Foo;
> the parameter tokens were mapped to cursors representing the
> FunctionDecl:
>
> Keyword: "auto" [1:1 - 1:5] FunctionDecl=test5:1:6
> Identifier: "test5" [1:6 - 1:11] FunctionDecl=test5:1:6
> Punctuation: "(" [1:11 - 1:12] FunctionDecl=test5:1:6
> Identifier: "X" [1:12 - 1:13] FunctionDecl=test5:1:6 // Ops, not a TypeRef
> Punctuation: ")" [1:13 - 1:14] FunctionDecl=test5:1:6
> Punctuation: "->" [1:15 - 1:17] FunctionDecl=test5:1:6
> Identifier: "X" [1:18 - 1:19] TypeRef=struct X:7:8
> Punctuation: ";" [1:19 - 1:20]
>
> Fix this by ensuring that the trailing return type is not visited as
> first.
>
> Patch by Nikolai Kosjar.
>
> Differential Revision: https://reviews.llvm.org/D40561
llvm-svn: 321708
For the function declaration
auto foo5(Foo) -> Foo;
the parameter tokens were mapped to cursors representing the
FunctionDecl:
Keyword: "auto" [1:1 - 1:5] FunctionDecl=test5:1:6
Identifier: "test5" [1:6 - 1:11] FunctionDecl=test5:1:6
Punctuation: "(" [1:11 - 1:12] FunctionDecl=test5:1:6
Identifier: "X" [1:12 - 1:13] FunctionDecl=test5:1:6 // Ops, not a TypeRef
Punctuation: ")" [1:13 - 1:14] FunctionDecl=test5:1:6
Punctuation: "->" [1:15 - 1:17] FunctionDecl=test5:1:6
Identifier: "X" [1:18 - 1:19] TypeRef=struct X:7:8
Punctuation: ";" [1:19 - 1:20]
Fix this by ensuring that the trailing return type is not visited as
first.
Patch by Nikolai Kosjar.
Differential Revision: https://reviews.llvm.org/D40561
llvm-svn: 321698
This is useful for e.g. highlighting purposes in an IDE.
Patch by Nikolai Kosjar.
Differential Revision: https://reviews.llvm.org/D40072
llvm-svn: 321697
Summary:
This is currently 16 bytes, the patch reduces it to 4.
(Building with clang on linux x84, I guess others are similar)
The only subfield that might need a bigger type is SymbolPropertySet,
I've moved it to the end of the struct so if it grows, SymbolInfo will
only be 8 bytes.
With a full index of namespace-scope symbols from the LLVM project (200k)
loaded into clangd, this saves ~2MB of RAM.
Reviewers: akyrtzi
Subscribers: ilya-biryukov, cfe-commits
Differential Revision: https://reviews.llvm.org/D41514
llvm-svn: 321411
This patch allows checking whether a C++ record declaration is abstract through
libclang and clang.cindex (Python).
Patch by Johann Klähn!
Differential Revision: https://reviews.llvm.org/D36952
llvm-svn: 320748
requested by client
This is a follow up to r319702 which records parsing invocations.
These files are not emitted by default, and the client has to specify the
invocation emission path first.
rdar://35322543
llvm-svn: 320085
Summary:
This enables us to use information in Preprocessor when handling symbol
occurrences.
Reviewers: arphaman, hokein
Reviewed By: hokein
Subscribers: malaperle, cfe-commits
Differential Revision: https://reviews.llvm.org/D40884
llvm-svn: 320030
This can be used by clients in conjunction with an offset returned by
e.g. clang_getFileLocation. Now those clients do not need to also
open/read the file.
Differential Revision: https://reviews.llvm.org/D40643
llvm-svn: 319881
Storing the contents of unsaved files is too expensive.
Instead a hash is stored with a record invocation. When a reproducer is
generated, Clang will compare the stored hashes to the new hashes to determine
if the contents of a file has changed. This way we'll know when a reproducer was
generated for a different source to the one that triggered the original crash.
rdar://35322543
llvm-svn: 319729
by client
This patch extends libclang by allowing it to record parsing operations to a
temporary JSON file. The file is deleted after parsing succeeds. When a crash
happens during parsing, the file is preserved and the client will be able to use
it to generate a reproducer for the crash.
These files are not emitted by default, and the client has to specify the
invocation emission path first.
rdar://35322543
Differential Revision: https://reviews.llvm.org/D40527
llvm-svn: 319702
Use this function to create the install targets rather than doing so
manually, which gains us the `-stripped` install targets to perform
stripped installations.
Differential Revision: https://reviews.llvm.org/D40675
llvm-svn: 319489
These functions were defined as static members of TemplateSpecializationType.
Now they are moved to namespace level. Previously there were different
implementations for lists containing TemplateArgument and TemplateArgumentLoc,
now these implementations share the same code.
This change is a result of refactoring patch D40508. NFC.
llvm-svn: 319178
Enabled crash recovery for some libclang operations on a calling thread even
when LIBCLANG_NOTHREAD is specified.
Previously it would only run under crash recovery if LIBCLANG_NOTHREAD is not
set. Moved handling of LIBCLANG_NOTHREAD env variable into RunSafely from its
call sites.
llvm-svn: 318142
`LLVM_DISTRIBUTION_COMPONENTS` assumes that each component has both
`component` and `install-component` targets. Add a dummy no-op target
for `libclang-headers` to placate this check.
Differential Revision: https://reviews.llvm.org/D39524
llvm-svn: 317188