diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index e88d71d4..2fec3836 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -218,7 +218,12 @@ bool FieldVisitor::VisitFieldDecl( clang::FieldDecl *field ) { if ( field->isBitField()) { fdes->setBitField(true) ; +#if (LIBCLANG_MAJOR >= 20) + // llvm 20+ gets the bit width directly from the FieldDecl without needing the ASTContext argument + fdes->setBitFieldWidth(field->getBitWidthValue()) ; +#else fdes->setBitFieldWidth(field->getBitWidthValue(field->getASTContext())) ; +#endif unsigned int field_offset_bits = field->getASTContext().getFieldOffset(field) + fdes->getBaseClassOffset() * 8 ; fdes->setBitFieldStart( 32 - (field_offset_bits % 32) - fdes->getBitFieldWidth()) ; fdes->setBitFieldByteOffset((field_offset_bits / 32) * 4 ) ; diff --git a/trick_source/codegen/Interface_Code_Gen/main.cpp b/trick_source/codegen/Interface_Code_Gen/main.cpp index 41d26c4a..9833cf04 100644 --- a/trick_source/codegen/Interface_Code_Gen/main.cpp +++ b/trick_source/codegen/Interface_Code_Gen/main.cpp @@ -14,6 +14,10 @@ #endif #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" +// Ensure to include VFS header for libclang versions >= 20 for createDiagnostics call +#if (LIBCLANG_MAJOR >= 20) +#include "llvm/Support/VirtualFileSystem.h" +#endif #include "clang/Basic/Builtins.h" #include "clang/Frontend/CompilerInstance.h" @@ -187,7 +191,20 @@ int main(int argc, char * argv[]) { clang::CompilerInvocation::setLangDefaults(ci.getLangOpts() , clang::IK_CXX) ; #endif +#if (LIBCLANG_MAJOR >= 20) + // Create a virtual file system + // This is required for llvm 20+ to create diagnostics properly + // llvm::IntrusiveRefCntPtr is LLVM's reference counting smart pointer + // The smart pointer is used to manage objects that require reference counting such as VFS + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs = llvm::vfs::getRealFileSystem(); + // createDiagnostics(llvm::vfs::FileSystem &VFS, + // DiagnosticConsumer * Client = nullptr, + // bool ShouldOwnClient = true) + // DiagnosticConsumer is set later in the code to our ICGDiagnosticConsumer and here is nullptr + ci.createDiagnostics(*vfs); // Create diagnostics for clang 20+ +#else ci.createDiagnostics(); +#endif ci.getDiagnosticOpts().ShowColors = 1 ; ci.getDiagnostics().setIgnoreAllWarnings(true) ; set_lang_opts(ci);