Skip to content

Commit 0be4956

Browse files
Update LLVM to 21
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c678e-fdd8-73e5-9dd9-23885d68d3f1
1 parent 482bc69 commit 0be4956

29 files changed

+225
-150
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: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ _BAZEL_SKYLIB_VERSION = "1.3.0"
44
_PLATFORMS_VERSION = "1.0.0"
55
_BAZEL_TOOLCHAIN_VERSION = "1.6.0"
66
_RULES_BOOST_COMMIT = "00b9b9ecb9b43564de44ea0b10e22b29dcf84d79"
7-
_LLVM_COMMIT = "e0f3110b854a476c16cce7b44472cd7838d344e9" # Keep in sync with Version.h
8-
_ABSL_COMMIT = "4ffaea74c1f5408e0757547a1ca0518ad43fa9f1"
7+
_LLVM_COMMIT = "2078da43e25a4623cab2d0d60decddf709aaea28" # Keep in sync with Version.h
8+
_ABSL_VERSION = "20240722.0"
99
_CXXOPTS_VERSION = "3.0.0"
1010
_RAPIDJSON_COMMIT = "a98e99992bd633a2736cc41f96ec85ef0c50e44d"
1111
_WYHASH_COMMIT = "ea3b25e1aef55d90f707c3a292eeb9162e2615d8"
12-
_SPDLOG_COMMIT = "edc51df1bdad8667b628999394a1e7c4dc6f3658"
13-
_PROTOBUF_VERSION = "3.21.12"
12+
_SPDLOG_COMMIT = "486b55554f11c9cccc913e11a87085b2a91f706f" # v1.16.0
13+
_PROTOBUF_VERSION = "25.3"
1414
_SCIP_COMMIT = "aa0e511dcfefbacc3b96dcc2fe2abd9894416b1e"
1515
_UTFCPP_VERSION = "4.0.5"
1616
# ^ When bumping this version, check if any new fields are introduced
@@ -82,14 +82,14 @@ def fetch_direct_dependencies():
8282
# Keep the name 'zlib' so that Protobuf doesn't pull in another copy.
8383
#
8484
# https://sourcegraph.com/github.com/protocolbuffers/protobuf/-/blob/protobuf_deps.bzl?L48-58
85+
# Using zlib 1.3.1 to fix macro conflicts with macOS headers in zlib 1.2.11
8586
http_archive(
8687
name = "zlib",
8788
build_file = "@scip_clang//third_party:zlib.BUILD",
88-
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
89-
strip_prefix = "zlib-1.2.11",
89+
sha256 = "17e88863f3600672ab49182f217281b6fc4d3c762bde361935e436a95214d05c",
90+
strip_prefix = "zlib-1.3.1",
9091
urls = [
91-
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
92-
"https://zlib.net/zlib-1.2.11.tar.gz",
92+
"https://github.com/madler/zlib/archive/refs/tags/v1.3.1.tar.gz",
9393
],
9494
)
9595

@@ -103,17 +103,33 @@ def fetch_direct_dependencies():
103103
],
104104
)
105105

106+
# LLVM 18+ uses zlib-ng instead of zlib
107+
http_archive(
108+
name = "llvm_zlib",
109+
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
110+
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
111+
strip_prefix = "zlib-ng-2.0.7",
112+
urls = [
113+
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
114+
],
115+
)
116+
117+
# Cherry-pick fix for CUDA assertion failure from
118+
# https://github.com/llvm/llvm-project/pull/173762
119+
# Can be removed once LLVM merges the fix and we update the commit.
106120
http_archive(
107121
name = "llvm-raw",
108-
sha256 = "04b76a5be88331f71a4e4fe96bccfebec302ddd0dbd9418fd5c186a7361c54fb",
122+
sha256 = "536a4d64ab21bc85bf95ae4dc412b36e8a9c72d487a476839f3c31c3ded69e96",
109123
strip_prefix = "llvm-project-%s" % _LLVM_COMMIT,
110124
build_file_content = "# empty",
111125
urls = ["https://github.com/llvm/llvm-project/archive/%s.tar.gz" % _LLVM_COMMIT],
126+
patch_args = ["-p1"],
127+
patches = ["//third_party:llvm-cuda-tooling.patch"],
112128
)
113129

114130
http_archive(
115131
name = "com_google_protobuf",
116-
sha256 = "f7042d540c969b00db92e8e1066a9b8099c8379c33f40f360eb9e1d98a36ca26",
132+
sha256 = "5156b22536feaa88cf95503153a6b2cd67cc80f20f1218f154b84a12c288a220",
117133
urls = ["https://github.com/protocolbuffers/protobuf/archive/v%s.zip" % _PROTOBUF_VERSION],
118134
strip_prefix = "protobuf-%s" % _PROTOBUF_VERSION,
119135
)
@@ -132,11 +148,9 @@ def fetch_direct_dependencies():
132148
# https://sourcegraph.com/github.com/protocolbuffers/protobuf/-/blob/protobuf_deps.bzl?L39-46
133149
http_archive(
134150
name = "com_google_absl",
135-
sha256 = "fee8ec623d8bbf0ecb9563a8e08ae319d1ca9fdf8c1c84384520a6992f571659",
136-
strip_prefix = "abseil-cpp-%s" % _ABSL_COMMIT,
137-
urls = ["https://github.com/abseil/abseil-cpp/archive/%s.zip" % _ABSL_COMMIT],
138-
patch_args = ["-p1"],
139-
patches = ["//third_party:abseil.patch"],
151+
sha256 = "95e90be7c3643e658670e0dd3c1b27092349c34b632c6e795686355f67eca89f",
152+
strip_prefix = "abseil-cpp-%s" % _ABSL_VERSION,
153+
urls = ["https://github.com/abseil/abseil-cpp/archive/%s.zip" % _ABSL_VERSION],
140154
)
141155

142156
# Abseil also has a flags/argument parsing library, but let's
@@ -168,7 +182,7 @@ def fetch_direct_dependencies():
168182
# NOTE: fmt also comes through spdlog, we don't have an explicit dep on fmt.
169183
http_archive(
170184
name = "spdlog",
171-
sha256 = "93a270dd7ec8fa672eb4feaef443dc14a4a9edc7b59aea998ae5da6cbf7b7119",
185+
sha256 = "d2fef585c9879dd239dc498e2e8a1e22982b3ed67b2d14e78622b7ef25bdfdfa",
172186
build_file = "@scip_clang//third_party:spdlog.BUILD",
173187
strip_prefix = "spdlog-%s" % _SPDLOG_COMMIT,
174188
urls = ["https://github.com/gabime/spdlog/archive/%s.tar.gz" % _SPDLOG_COMMIT],

indexer/ApproximateNameResolver.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "clang/AST/DeclTemplate.h"
44
#include "clang/AST/DeclarationName.h"
55
#include "clang/AST/Type.h"
6+
#include "clang/Sema/HeuristicResolver.h"
67
#include "llvm/ADT/SmallPtrSet.h"
78
#include "llvm/ADT/SmallVector.h"
89

@@ -13,7 +14,6 @@
1314
#include "spdlog/spdlog.h"
1415

1516
namespace scip_clang {
16-
1717
MemberLookupKey::MemberLookupKey(const clang::Type *type,
1818
const clang::DeclarationNameInfo &declNameInfo)
1919
: canonicalTypePtr(type->getCanonicalTypeInternal().getTypePtrOrNull()),
@@ -65,8 +65,9 @@ ApproximateNameResolver::tryResolveMember(
6565
continue;
6666
}
6767
cxxRecordDecl = cxxRecordDecl->getDefinition();
68-
auto lookupResults =
69-
cxxRecordDecl->lookupDependentName(declNameInfo.getName(), filter);
68+
clang::HeuristicResolver resolver(this->astContext);
69+
auto lookupResults = resolver.lookupDependentName(
70+
cxxRecordDecl, declNameInfo.getName(), filter);
7071
for (auto *namedDecl : lookupResults) {
7172
auto *unresolvedUsingValueDecl =
7273
llvm::dyn_cast<clang::UnresolvedUsingValueDecl>(namedDecl);

indexer/ApproximateNameResolver.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,23 @@ class MemberLookupKey {
3636
DERIVE_CMP_ALL(MemberLookupKey)
3737
};
3838

39-
/// Type similar to clangd's HeuristicResolver, used for performing
40-
/// best-effort name resolution when encountered unresolved names.
41-
///
42-
/// We don't directly reuse the code from clangd, since it's not that
43-
/// much code (<300 lines), and having own code let's us evolve it
44-
/// independently and add different heuristics.
45-
///
46-
/// (Named differently to reduce risk of confusion.)
39+
/// Wrapper around clang's HeuristicResolver for performing best-effort
40+
/// name resolution for unresolved names in template code.
41+
/// Adds caching and handling of UnresolvedUsingValueDecl chains.
4742
class ApproximateNameResolver {
48-
[[maybe_unused]] const clang::ASTContext &astContext; // for debugging
43+
clang::ASTContext &astContext;
4944
using Self = ApproximateNameResolver;
5045
using ResultVec = llvm::SmallVector<const clang::NamedDecl *, 1>;
5146
absl::flat_hash_map<MemberLookupKey, ResultVec> dependentNameLookupCache;
5247

5348
public:
54-
ApproximateNameResolver(const clang::ASTContext &astContext)
49+
ApproximateNameResolver(clang::ASTContext &astContext)
5550
: astContext(astContext), dependentNameLookupCache() {}
5651

5752
ResultVec tryResolveMember(const clang::Type *,
5853
const clang::DeclarationNameInfo &);
5954

6055
private:
61-
// Analog to HeuristicResolver.cc's resolveTypeToRecordDecl
6256
static clang::CXXRecordDecl *tryFindDeclForType(const clang::Type *);
6357
};
6458

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: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void ForwardDeclMap::emit(bool deterministic, scip::ForwardDeclIndex &index) {
386386

387387
TuIndexer::TuIndexer(const clang::SourceManager &sourceManager,
388388
const clang::LangOptions &langOptions,
389-
const clang::ASTContext &astContext,
389+
clang::ASTContext &astContext,
390390
const FileIdsToBeIndexedSet &fileIdsToBeIndexed,
391391
SymbolFormatter &symbolFormatter,
392392
FileMetadataMap &fileMetadataMap)
@@ -530,7 +530,8 @@ void TuIndexer::saveFunctionDecl(const clang::FunctionDecl &functionDecl) {
530530
}
531531
auto symbol = optSymbol.value();
532532

533-
if (functionDecl.isPure() || functionDecl.isThisDeclarationADefinition()) {
533+
if (functionDecl.isPureVirtual()
534+
|| functionDecl.isThisDeclarationADefinition()) {
534535
scip::SymbolInformation symbolInfo{};
535536
this->getDocComment(functionDecl).addTo(symbolInfo);
536537
if (auto *cxxMethodDecl =
@@ -671,33 +672,6 @@ void TuIndexer::saveNestedNameSpecifierLoc(
671672
case Kind::NamespaceAlias:
672673
case Kind::Global:
673674
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.
701675
break;
702676
}
703677
nameSpecLoc = nameSpecLoc.getPrefix();
@@ -834,6 +808,17 @@ void TuIndexer::saveTemplateSpecializationTypeLoc(
834808
const clang::TemplateSpecializationTypeLoc &templateSpecializationTypeLoc) {
835809
auto *templateSpecializationType = templateSpecializationTypeLoc.getTypePtr();
836810
auto templateName = templateSpecializationType->getTemplateName();
811+
812+
// Unwrap QualifiedTemplateName and DeducedTemplateStorage to get the
813+
// underlying template. These wrappers preserve source-level qualifications
814+
// but we need the actual template declaration for indexing.
815+
if (auto *qualifiedName = templateName.getAsQualifiedTemplateName()) {
816+
templateName = qualifiedName->getUnderlyingTemplate();
817+
}
818+
if (auto *deducedStorage = templateName.getAsDeducedTemplateName()) {
819+
templateName = deducedStorage->getUnderlying();
820+
}
821+
837822
using Kind = clang::TemplateName::NameKind;
838823
switch (templateName.getKind()) {
839824
case Kind::Template: {
@@ -871,6 +856,7 @@ void TuIndexer::saveTemplateSpecializationTypeLoc(
871856
case Kind::OverloadedTemplate:
872857
case Kind::AssumedTemplate:
873858
case Kind::QualifiedTemplate:
859+
case Kind::DeducedTemplate:
874860
case Kind::DependentTemplate:
875861
case Kind::SubstTemplateTemplateParm:
876862
case Kind::SubstTemplateTemplateParmPack:

indexer/Indexer.h

Lines changed: 2 additions & 3 deletions
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);
@@ -299,7 +298,7 @@ using FileIdsToBeIndexedSet =
299298
class TuIndexer final {
300299
const clang::SourceManager &sourceManager;
301300
const clang::LangOptions &langOptions;
302-
[[maybe_unused]] const clang::ASTContext &astContext;
301+
clang::ASTContext &astContext;
303302
const FileIdsToBeIndexedSet &fileIdsToBeIndexed;
304303
SymbolFormatter &symbolFormatter;
305304
ApproximateNameResolver approximateNameResolver;
@@ -314,7 +313,7 @@ class TuIndexer final {
314313

315314
public:
316315
TuIndexer(const clang::SourceManager &, const clang::LangOptions &,
317-
const clang::ASTContext &, const FileIdsToBeIndexedSet &,
316+
clang::ASTContext &, const FileIdsToBeIndexedSet &,
318317
SymbolFormatter &, FileMetadataMap &);
319318

320319
/// Emit a fake 'definition' for a file, which can be used as a target

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"

0 commit comments

Comments
 (0)