Skip to content

Commit

Permalink
fix build with Clang 15
Browse files Browse the repository at this point in the history
  • Loading branch information
fw-immunant committed Jan 17, 2023
1 parent e9e802a commit c951091
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions header-rewriter/DetermineAbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "clang/AST/AST.h"
#include "clang/AST/RecordLayout.h"
#include "clang/Basic/CodeGenOptions.h"
#if LLVM_VERSION_MAJOR >= 15
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
#endif
#include "clang/CodeGen/CGFunctionInfo.h"
#include "clang/CodeGen/CodeGenABITypes.h"
#include "clang/CodeGen/ModuleBuilder.h"
Expand Down Expand Up @@ -233,12 +237,23 @@ CAbiSignature determineAbiForDecl(const clang::FunctionDecl &fnDecl) {
// just `clang::CodeGen::CodeGenModule& cgm` could be passed in.
// doing so would add the precondition that the clang::AstContext of
// the passed fnDecl matches that of the passed CGM's CodeGenerator.
#if LLVM_VERSION_MAJOR >= 15
clang::FileSystemOptions fso{"."};
clang::FileManager fm(fso);
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
&fm.getVirtualFileSystem();
#endif

clang::HeaderSearchOptions hso;
clang::PreprocessorOptions ppo;
clang::CodeGenOptions cgo;
llvm::LLVMContext llvmCtx;
clang::CodeGenerator *codeGenerator = CreateLLVMCodeGen(
astContext.getDiagnostics(), llvm::StringRef(), hso, ppo, cgo, llvmCtx);
clang::CodeGenerator *codeGenerator =
CreateLLVMCodeGen(astContext.getDiagnostics(), llvm::StringRef(),
#if LLVM_VERSION_MAJOR >= 15
vfs,
#endif
hso, ppo, cgo, llvmCtx);

codeGenerator->Initialize(astContext);
clang::CodeGen::CodeGenModule &cgm = codeGenerator->CGM();
Expand All @@ -264,12 +279,23 @@ CAbiSignature determineAbiForProtoType(const clang::FunctionProtoType &fpt,
// FIXME: This is copied verbatim from determineAbiForDecl and could be
// factored out. This depends on what we do with PR #78 so I'm leaving it as
// is for now.
#if LLVM_VERSION_MAJOR >= 15
clang::FileSystemOptions fso{"."};
clang::FileManager fm(fso);
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> vfs =
&fm.getVirtualFileSystem();
#endif

clang::HeaderSearchOptions hso;
clang::PreprocessorOptions ppo;
clang::CodeGenOptions cgo;
llvm::LLVMContext llvmCtx;
clang::CodeGenerator *codeGenerator = CreateLLVMCodeGen(
astContext.getDiagnostics(), llvm::StringRef(), hso, ppo, cgo, llvmCtx);
clang::CodeGenerator *codeGenerator =
CreateLLVMCodeGen(astContext.getDiagnostics(), llvm::StringRef(),
#if LLVM_VERSION_MAJOR >= 15
vfs,
#endif
hso, ppo, cgo, llvmCtx);

codeGenerator->Initialize(astContext);
clang::CodeGen::CodeGenModule &cgm = codeGenerator->CGM();
Expand Down

0 comments on commit c951091

Please sign in to comment.