Merge branch 'master' into Trick-ify

This commit is contained in:
Hong Chen 2025-04-08 16:58:34 -05:00
commit aa10fecd47
2 changed files with 22 additions and 0 deletions

View File

@ -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 ) ;

View File

@ -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);