Skip to content

Commit 51de797

Browse files
committed
[clangd] check for synthesized symbols when tracking include locations
This fixes #75115 In C mode with MSVC compatibility, when the `assert` macro is defined, as a workaround, `static_assert` is implicitly defined as well, if not already so, in order to work around a broken `assert.h` implementation. This workaround was implemented in 8da0903 A synthesized symbol does not occur in source code, and therefore should not have valid source location, but this was not checked when inserting this into a `symbol -> include file` map. The invalid FileID value is used for empty key representation in the include file hash table, so it's not valid to insert it.
1 parent 7c18785 commit 51de797

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,11 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, SourceLocation DefLoc,
821821

822822
// Use the expansion location to get the #include header since this is
823823
// where the symbol is exposed.
824-
IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first;
824+
FileID FID = SM.getDecomposedExpansionLoc(DefLoc).first;
825+
if (FID.isInvalid())
826+
return;
827+
828+
IncludeFiles[S.ID] = FID;
825829

826830
// We update providers for a symbol with each occurence, as SymbolCollector
827831
// might run while parsing, rather than at the end of a translation unit.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// RUN: rm -rf %t.dir && mkdir -p %t.dir
22
// RUN: echo '[{"directory": "%/t.dir", "command": "clang --target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > %t.dir/compile_commands.json
3-
// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck -strict-whitespace %s
4-
5-
// FIXME: Crashes
3+
// RUN: clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck -strict-whitespace %s
64

75
// CHECK: Building preamble...
86
// CHECK-NEXT: Built preamble
97
// CHECK-NEXT: Indexing headers...
10-
// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
8+
// CHECK-NEXT: Building AST...
9+
// CHECK-NEXT: Indexing AST...
10+
// CHECK-NEXT: Building inlay hints
11+
// CHECK-NEXT: semantic highlighting
12+
// CHECK-NEXT: Testing features at each token
13+
// CHECK-NEXT: All checks completed, 0 errors
1114

1215
#define assert

0 commit comments

Comments
 (0)