Compare commits

..

5 Commits

Author SHA1 Message Date
rherilier
779cd86a06
Merge 84b3c69ff5 into d31cc9f076 2025-12-02 12:33:26 +08:00
Fangrui Song
d31cc9f076 Adapt llvm 22 changes
Type::Elaborated is removed by llvmorg-22-init-3166-g91cdd35008e9

llvm::sys::fs and clang functions are changed due to
https://discourse.llvm.org/t/rfc-file-system-sandboxing-in-clang-llvm/88791
2025-11-29 21:53:40 -08:00
zhscn
a7068f13ec indexer: Resolve the type alias correctly (#988)
The struct derived from an alias is missing from type hierarchy before this fix:
```cpp
struct Base {};
struct Derived : Base {};
using BaseAlias = Base;
struct DerivedAlias : BaseAlias {};
```
```
Derive from
Base
└╸Derived
```
The expected output is:
```
Derive from
Base
├╸Derived
└╸DerivedAlias
```
2025-11-15 14:27:19 -08:00
Fangrui Song
344e2e6557 Add clang.prependArgs option
To specify arguments that are inserted immediately after the compiler
driver name. For example, initialization options
`{"clang":{"prependArgs":["--gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/13"]}}`
transforms `clang -c a.cc` into `clang --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/13 -c a.cc`.
This allows users to provide default arguments that can be overridden as
needed.
2025-08-15 12:00:00 -07:00
Fangrui Song
791f6ba974 indexer: Support Decl::Concept
Fix indexer.cc:802 "Unhandled 72" when compiling `#include <chrono>`
functions with -std=c++20.
2025-11-15 14:03:07 -08:00
3 changed files with 21 additions and 25 deletions

View File

@ -325,6 +325,9 @@ try_again:
switch (tp->getTypeClass()) {
case Type::Typedef:
d = cast<TypedefType>(tp)->getDecl();
tp = cast<TypedefType>(tp)->getDecl()->getUnderlyingType().getTypePtrOrNull();
if (tp)
goto try_again;
break;
case Type::ObjCObject:
d = cast<ObjCObjectType>(tp)->getInterface();
@ -334,11 +337,7 @@ try_again:
break;
case Type::Record:
case Type::Enum:
#if LLVM_VERSION_MAJOR >= 22 // llvmorg-22-init-3166-g91cdd35008e9
d = cast<TagType>(tp)->getOriginalDecl();
#else
d = cast<TagType>(tp)->getDecl();
#endif
break;
case Type::TemplateTypeParm:
d = cast<TemplateTypeParmType>(tp)->getDecl();
@ -346,15 +345,10 @@ try_again:
case Type::TemplateSpecialization:
if (specialization)
*specialization = true;
if (const RecordType *record = tp->getAs<RecordType>()) {
#if LLVM_VERSION_MAJOR >= 22 // llvmorg-22-init-3166-g91cdd35008e9
d = record->getOriginalDecl();
#else
if (const RecordType *record = tp->getAs<RecordType>())
d = record->getDecl();
#endif
} else {
else
d = cast<TemplateSpecializationType>(tp)->getTemplateName().getAsTemplateDecl();
}
break;
case Type::Auto:
@ -365,11 +359,7 @@ try_again:
break;
case Type::InjectedClassName:
#if LLVM_VERSION_MAJOR >= 22 // llvmorg-22-init-3166-g91cdd35008e9
d = cast<InjectedClassNameType>(tp)->getOriginalDecl();
#else
d = cast<InjectedClassNameType>(tp)->getDecl();
#endif
break;
// FIXME: Template type parameters!
@ -427,11 +417,7 @@ bool validateRecord(const RecordDecl *rd) {
if (fqt->isIncompleteType() || fqt->isDependentType())
return false;
if (const RecordType *childType = i->getType()->getAs<RecordType>())
#if LLVM_VERSION_MAJOR >= 22 // llvmorg-22-init-3166-g91cdd35008e9
if (const RecordDecl *child = childType->getOriginalDecl())
#else
if (const RecordDecl *child = childType->getDecl())
#endif
if (!validateRecord(child))
return false;
}
@ -705,11 +691,7 @@ public:
if (fd->getIdentifier())
type.def.vars.emplace_back(getUsr(fd), offset1);
else if (const auto *rt1 = fd->getType()->getAs<RecordType>()) {
#if LLVM_VERSION_MAJOR >= 22 // llvmorg-22-init-3166-g91cdd35008e9
if (const RecordDecl *rd1 = rt1->getOriginalDecl())
#else
if (const RecordDecl *rd1 = rt1->getDecl())
#endif
if (seen.insert(rd1).second)
stack.push_back({rd1, offset1});
}
@ -1286,7 +1268,7 @@ IndexResult index(WorkingFiles *wfiles, VFS *vfs, const std::string &opt_wdir, c
clang->setInvocation(std::move(ci));
#endif
clang->createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
#if LLVM_VERSION_MAJOR >= 20 && LLVM_VERSION_MAJOR < 22
*fs,
#endif
&dc, false);
@ -1299,7 +1281,12 @@ IndexResult index(WorkingFiles *wfiles, VFS *vfs, const std::string &opt_wdir, c
if (!clang->hasTarget())
return {};
clang->getPreprocessorOpts().RetainRemappedFileBuffers = true;
#if LLVM_VERSION_MAJOR >= 22
clang->setVirtualFileSystem(fs);
clang->createFileManager();
#else
clang->createFileManager(fs);
#endif
clang->setSourceManager(new SourceManager(clang->getDiagnostics(), clang->getFileManager(), true));
IndexParam param(*vfs, no_linkage);

View File

@ -345,7 +345,11 @@ void do_initialize(MessageHandler *m, InitializeParam &param, ReplyOnce &reply)
if (g_config->cache.directory.size()) {
SmallString<256> path(g_config->cache.directory);
#if LLVM_VERSION_MAJOR >= 22
sys::path::make_absolute(project_path, path);
#else
sys::fs::make_absolute(project_path, path);
#endif
// Use upper case for the Driver letter on Windows.
g_config->cache.directory = normalizePath(path.str());
ensureEndsInSlash(g_config->cache.directory);

View File

@ -268,7 +268,7 @@ std::unique_ptr<CompilerInstance> buildCompilerInstance(Session &session, std::u
clang->setInvocation(std::move(ci));
#endif
clang->createDiagnostics(
#if LLVM_VERSION_MAJOR >= 20
#if LLVM_VERSION_MAJOR >= 20 && LLVM_VERSION_MAJOR < 22
*fs,
#endif
&dc, false);
@ -283,7 +283,12 @@ std::unique_ptr<CompilerInstance> buildCompilerInstance(Session &session, std::u
// Construct SourceManager with UserFilesAreVolatile: true because otherwise
// RequiresNullTerminator: true may cause out-of-bounds read when a file is
// mmap'ed but is saved concurrently.
#if LLVM_VERSION_MAJOR >= 22
clang->setVirtualFileSystem(fs);
clang->createFileManager();
#else
clang->createFileManager(fs);
#endif
clang->setSourceManager(new SourceManager(clang->getDiagnostics(), clang->getFileManager(), true));
auto &isec = clang->getFrontendOpts().Inputs;
if (isec.size()) {