Skip to content

Commit 41926df

Browse files
CU-2083 Update scip-clang to newer Clang version
Amp-Thread-ID: https://ampcode.com/threads/T-019b7003-fbd1-73b0-84e1-30b1483d9aed Co-authored-by: Amp <amp@ampcode.com>
1 parent b61229a commit 41926df

30 files changed

+117
-148
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# scip-clang: SCIP indexer for C and C++ ![(Status: Beta)](https://img.shields.io/badge/status-beta-yellow?style=flat)
22

3-
scip-clang is a precise code indexer based on Clang 16,
3+
scip-clang is a precise code indexer based on Clang 21,
44
which supports cross-repository code navigation for C, C++ and CUDA
55
in Sourcegraph.
66

@@ -201,7 +201,7 @@ scip-clang --compdb-path=build/small_compdb.json --show-compiler-diagnostics
201201
<summary>Known diagnostics when indexing CUDA</summary>
202202

203203
1. If you see an error related to the `texture` template, that is likely
204-
because of the Clang version not being Clang 16 or newer.
204+
because of the Clang version not being Clang 21 or newer.
205205
See https://github.com/llvm/llvm-project/issues/61340
206206
2. If you see any errors related to GCC headers, that's a
207207
[known issue](https://github.com/sourcegraph/scip-clang/issues/440).

fetch_deps.bzl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ _BAZEL_SKYLIB_VERSION = "1.3.0"
44
_PLATFORMS_COMMIT = "3fbc687756043fb58a407c2ea8c944bc2fe1d922" # 2022 Nov 10
55
_BAZEL_TOOLCHAIN_VERSION = "0.10.3"
66
_RULES_BOOST_COMMIT = "00b9b9ecb9b43564de44ea0b10e22b29dcf84d79"
7-
_LLVM_COMMIT = "e0f3110b854a476c16cce7b44472cd7838d344e9" # Keep in sync with Version.h
7+
_LLVM_COMMIT = "2078da43e25a4623cab2d0d60decddf709aaea28" # Keep in sync with Version.h
88
_ABSL_COMMIT = "4ffaea74c1f5408e0757547a1ca0518ad43fa9f1"
99
_CXXOPTS_VERSION = "3.0.0"
1010
_RAPIDJSON_COMMIT = "a98e99992bd633a2736cc41f96ec85ef0c50e44d"
1111
_WYHASH_COMMIT = "ea3b25e1aef55d90f707c3a292eeb9162e2615d8"
12-
_SPDLOG_COMMIT = "edc51df1bdad8667b628999394a1e7c4dc6f3658"
12+
_SPDLOG_COMMIT = "486b55554f11c9cccc913e11a87085b2a91f706f" # v1.16.0
1313
_PROTOBUF_VERSION = "3.21.12"
1414
_SCIP_COMMIT = "aa0e511dcfefbacc3b96dcc2fe2abd9894416b1e"
1515
_UTFCPP_VERSION = "4.0.5"
@@ -22,7 +22,7 @@ _UTFCPP_VERSION = "4.0.5"
2222
# See https://github.com/google/perfetto/issues/271#issuecomment-1527691232
2323
_PERFETTO_VERSION = "33.1" # Keep in sync with docs/Development.md
2424
_DOCTEST_VERSION = "2.4.9"
25-
_DTL_VERSION = "1.20"
25+
_DTL_VERSION = "1.21"
2626
_RULES_PYTHON_VERSION = "0.18.1"
2727

2828
def fetch_direct_dependencies():
@@ -100,9 +100,20 @@ def fetch_direct_dependencies():
100100
],
101101
)
102102

103+
# LLVM 18+ uses zlib-ng instead of zlib
104+
http_archive(
105+
name = "llvm_zlib",
106+
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
107+
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
108+
strip_prefix = "zlib-ng-2.0.7",
109+
urls = [
110+
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
111+
],
112+
)
113+
103114
http_archive(
104115
name = "llvm-raw",
105-
sha256 = "04b76a5be88331f71a4e4fe96bccfebec302ddd0dbd9418fd5c186a7361c54fb",
116+
sha256 = "536a4d64ab21bc85bf95ae4dc412b36e8a9c72d487a476839f3c31c3ded69e96",
106117
strip_prefix = "llvm-project-%s" % _LLVM_COMMIT,
107118
build_file_content = "# empty",
108119
urls = ["https://github.com/llvm/llvm-project/archive/%s.tar.gz" % _LLVM_COMMIT],
@@ -165,7 +176,7 @@ def fetch_direct_dependencies():
165176
# NOTE: fmt also comes through spdlog, we don't have an explicit dep on fmt.
166177
http_archive(
167178
name = "spdlog",
168-
sha256 = "93a270dd7ec8fa672eb4feaef443dc14a4a9edc7b59aea998ae5da6cbf7b7119",
179+
sha256 = "d2fef585c9879dd239dc498e2e8a1e22982b3ed67b2d14e78622b7ef25bdfdfa",
169180
build_file = "@scip_clang//third_party:spdlog.BUILD",
170181
strip_prefix = "spdlog-%s" % _SPDLOG_COMMIT,
171182
urls = ["https://github.com/gabime/spdlog/archive/%s.tar.gz" % _SPDLOG_COMMIT],
@@ -180,7 +191,7 @@ def fetch_direct_dependencies():
180191

181192
http_archive(
182193
name = "dtl",
183-
sha256 = "579f81bca88f4b9760a59d99c5a95bd8dd5dc2f20f33f1f9b5f64cb08979f54d",
194+
sha256 = "90ed2dbf4e6d687737fe25f118bbcb6aed778cecc3f2115d191a032bf8643dbd",
184195
build_file = "@scip_clang//third_party:dtl.BUILD",
185196
strip_prefix = "dtl-%s" % _DTL_VERSION,
186197
urls = ["https://github.com/cubicdaiya/dtl/archive/v%s.tar.gz" % _DTL_VERSION],

indexer/ApproximateNameResolver.cc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@
1414

1515
namespace scip_clang {
1616

17+
namespace {
18+
// Reimplementation of the removed CXXRecordDecl::lookupDependentName
19+
llvm::SmallVector<clang::NamedDecl *, 4>
20+
lookupDependentName(clang::CXXRecordDecl *record, clang::DeclarationName name,
21+
llvm::function_ref<bool(const clang::NamedDecl *)> filter) {
22+
llvm::SmallVector<clang::NamedDecl *, 4> results;
23+
for (auto *decl : record->lookup(name)) {
24+
if (filter(decl)) {
25+
results.push_back(decl);
26+
}
27+
}
28+
if (!results.empty())
29+
return results;
30+
31+
// Search in base classes
32+
for (const auto &base : record->bases()) {
33+
auto *baseType = base.getType()->getAs<clang::RecordType>();
34+
if (!baseType)
35+
continue;
36+
auto *baseRecord =
37+
llvm::dyn_cast<clang::CXXRecordDecl>(baseType->getDecl());
38+
if (!baseRecord || !baseRecord->hasDefinition())
39+
continue;
40+
auto baseResults =
41+
lookupDependentName(baseRecord->getDefinition(), name, filter);
42+
results.append(baseResults.begin(), baseResults.end());
43+
}
44+
return results;
45+
}
46+
} // namespace
47+
1748
MemberLookupKey::MemberLookupKey(const clang::Type *type,
1849
const clang::DeclarationNameInfo &declNameInfo)
1950
: canonicalTypePtr(type->getCanonicalTypeInternal().getTypePtrOrNull()),
@@ -66,7 +97,7 @@ ApproximateNameResolver::tryResolveMember(
6697
}
6798
cxxRecordDecl = cxxRecordDecl->getDefinition();
6899
auto lookupResults =
69-
cxxRecordDecl->lookupDependentName(declNameInfo.getName(), filter);
100+
lookupDependentName(cxxRecordDecl, declNameInfo.getName(), filter);
70101
for (auto *namedDecl : lookupResults) {
71102
auto *unresolvedUsingValueDecl =
72103
llvm::dyn_cast<clang::UnresolvedUsingValueDecl>(namedDecl);

indexer/CompilationDatabase.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "rapidjson/rapidjson.h"
2121
#include "rapidjson/reader.h"
2222
#include "spdlog/fmt/fmt.h"
23+
#include "spdlog/fmt/ranges.h"
2324

2425
#include "indexer/CommandLineCleaner.h"
2526
#include "indexer/CompilationDatabase.h"
@@ -97,7 +98,7 @@ struct ClangToolchainInfo : public ToolchainInfo {
9798
findResourceDirInvocation(findResourceDirInvocation),
9899
compilerDriverPath(compilerDriverPath),
99100
findDriverInvocation(findDriverInvocation),
100-
cleaner(std::move(cleaner)){};
101+
cleaner(std::move(cleaner)) {};
101102

102103
virtual CompilerKind kind() const override {
103104
return CompilerKind::Clang;

indexer/DebugHelpers.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ std::string formatKind(clang::NestedNameSpecifier::SpecifierKind kind) {
175175
HANDLE_KIND(Namespace)
176176
HANDLE_KIND(NamespaceAlias)
177177
HANDLE_KIND(TypeSpec)
178-
HANDLE_KIND(TypeSpecWithTemplate)
179178
HANDLE_KIND(Global)
180179
HANDLE_KIND(Super)
181180
}

indexer/Driver.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "rapidjson/error/en.h"
3232
#include "rapidjson/filereadstream.h"
3333
#include "spdlog/fmt/fmt.h"
34+
#include "spdlog/fmt/ranges.h"
3435
#include "spdlog/sinks/stdout_sinks.h"
3536
#include "spdlog/spdlog.h"
3637

@@ -231,8 +232,8 @@ struct DriverOptions {
231232
projectRootPath(AbsolutePath("/"), RootKind::Project), compdbPath(),
232233
indexOutputPath(), statsFilePath(), packageMapPath(),
233234
showCompilerDiagnostics(cliOpts.showCompilerDiagnostics),
234-
showProgress(cliOpts.showProgress), ipcOptions{cliOpts.ipcSizeHintBytes,
235-
cliOpts.receiveTimeout},
235+
showProgress(cliOpts.showProgress),
236+
ipcOptions{cliOpts.ipcSizeHintBytes, cliOpts.receiveTimeout},
236237
numWorkers(cliOpts.numWorkers), deterministic(cliOpts.deterministic),
237238
preprocessorRecordHistoryFilterRegex(
238239
cliOpts.preprocessorRecordHistoryFilterRegex),
@@ -257,7 +258,7 @@ struct DriverOptions {
257258
: (llvm::sys::path::is_absolute(path)
258259
? AbsolutePath(std::string(path))
259260
: this->projectRootPath.makeAbsolute(
260-
RootRelativePathRef(path, RootKind::Project)));
261+
RootRelativePathRef(path, RootKind::Project)));
261262
};
262263

263264
// Strictly speaking, there is a TOCTOU problem here, as scip-clang

indexer/Indexer.cc

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void TuIndexer::saveFunctionDecl(const clang::FunctionDecl &functionDecl) {
530530
}
531531
auto symbol = optSymbol.value();
532532

533-
if (functionDecl.isPure() || functionDecl.isThisDeclarationADefinition()) {
533+
if (functionDecl.isPureVirtual() || functionDecl.isThisDeclarationADefinition()) {
534534
scip::SymbolInformation symbolInfo{};
535535
this->getDocComment(functionDecl).addTo(symbolInfo);
536536
if (auto *cxxMethodDecl =
@@ -671,33 +671,6 @@ void TuIndexer::saveNestedNameSpecifierLoc(
671671
case Kind::NamespaceAlias:
672672
case Kind::Global:
673673
case Kind::Super:
674-
case Kind::TypeSpecWithTemplate:
675-
// FIXME(def: template-specialization-support)
676-
// Adding support for TypeSpecWithTemplate needs extra care
677-
// for (partial) template specializations. Example code:
678-
//
679-
// template <typename T0>
680-
// struct X {
681-
// template <typename T1>
682-
// struct Y {};
683-
// };
684-
//
685-
// template <>
686-
// struct X {
687-
// template <typename A>
688-
// struct Y { int[42] magic; };
689-
// };
690-
//
691-
// template <typename U0> void f() {
692-
// typename X<U0>::template Y<U0> y{};
693-
// //^^^^^^^^^^^^^^ TypeSpecWithTemplate
694-
// std::cout << sizeof(y) << '\n';
695-
// }
696-
//
697-
// In 'template Y<U0>', clangd will navigate to 'Y' in the body of 'X',
698-
// even when there is partial template specialization of X
699-
// (so calling f<int>() will print a different value).
700-
// Ideally, we should surface such specializations too.
701674
break;
702675
}
703676
nameSpecLoc = nameSpecLoc.getPrefix();

indexer/Indexer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct FileLocalSourceRange {
8080
r.endLine);
8181
}
8282
DERIVE_CMP_ALL(FileLocalSourceRange)
83-
DERIVE_EQ_ALL(FileLocalSourceRange)
8483

8584
static std::pair<FileLocalSourceRange, clang::FileID>
8685
fromNonEmpty(const clang::SourceManager &, clang::SourceRange inclusiveRange);

indexer/JsonIpcQueue.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "boost/interprocess/ipc/message_queue.hpp"
1212
#pragma clang diagnostic pop
1313

14-
#include "llvm/ADT/Optional.h"
1514
#include "llvm/Support/Error.h"
1615
#include "llvm/Support/JSON.h"
1716
#include "llvm/Support/raw_ostream.h"

indexer/PackageMap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ PackageMap::PackageMap(const RootPath &projectRootPath,
6464

6565
void PackageMap::populate(const StdPath &packageMapPath) {
6666
std::error_code error;
67-
auto path = std::string_view(packageMapPath.c_str());
67+
std::string path(packageMapPath.c_str());
6868
if (!llvm::sys::fs::exists(path)) {
6969
spdlog::error("package map not found at path: {}", path);
7070
std::exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)