From 14b01fa0c8f7de2f234cf30d8bca29094986194b Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Wed, 5 Jun 2019 20:11:13 +0800 Subject: [PATCH 1/8] Fix a type mismatch bug in `specialize_template_clang` Fixed No.6 and No.14 in https://github.com/JuliaInterop/Cxx.jl/issues/409#issuecomment-495243790 --- src/typetranslation.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typetranslation.jl b/src/typetranslation.jl index afc6e04e..53bc5cde 100644 --- a/src/typetranslation.jl +++ b/src/typetranslation.jl @@ -179,7 +179,7 @@ function specialize_template_clang(C,cxxt::pcpp"clang::ClassTemplateDecl",targs) end end d = pcpp"clang::ClassTemplateSpecializationDecl"(ccall((:SpecializeClass,libcxxffi),Ptr{Cvoid}, - (Ref{ClangCompiler},Ptr{Cvoid},Ptr{Cvoid},Ptr{UInt64},Ptr{UInt8},UInt32),C, + (Ref{ClangCompiler},Ptr{Cvoid},Ptr{Cvoid},Ptr{UInt64},Ptr{Int8},Csize_t),C, convert(Ptr{Cvoid},cxxt),[convert(Ptr{Cvoid},p) for p in ts], integralValues,integralValuesPresent,length(ts))) d From 5a9dbb607dad7e7e0415562d0f207b0bd3e5d0ef Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Wed, 5 Jun 2019 20:38:01 +0800 Subject: [PATCH 2/8] Disable exception handling related tests on Windows --- appveyor.yml | 6 +++--- deps/build_libcxxffi.jl | 2 +- test/misc.jl | 3 ++- test/std.jl | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d79190d6..46072d58 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,9 +33,9 @@ build_script: - echo "%JL_BUILD_SCRIPT%" - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" -# test_script: -# - echo "%JL_TEST_SCRIPT%" -# - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" +test_script: + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" # # Uncomment to support code coverage upload. Should only be enabled for packages # # which would have coverage gaps without running on Windows diff --git a/deps/build_libcxxffi.jl b/deps/build_libcxxffi.jl index 77f04f80..6d441c4c 100644 --- a/deps/build_libcxxffi.jl +++ b/deps/build_libcxxffi.jl @@ -14,7 +14,7 @@ bin_prefix = "https://github.com/JuliaInterop/Cxx.jl/releases/download/libcxxffi download_info = Dict( Linux(:x86_64, libc=:glibc) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-linux-gnu-gcc7.tar.gz", "cc53946f4867d95f543ad112db6a5ce40bbdf9f5b9a8982906a14c1cff5aaced"), MacOS(:x86_64) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-apple-darwin14-gcc7.tar.gz", "76aa1dfc7ecb97069043ed6e19b685371e04daf92d73201aaf054678e2a11cf1"), - Windows(:x86_64) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-w64-mingw32-gcc7.tar.gz", "9730c0c438e3cfcfc793d05e511b428e01aebf75085bd36582c822e220532790"), + Windows(:x86_64) => ("https://github.com/Gnimuc/CxxBuilder/releases/download/v0.0.5-3/libcxxffi.v0.0.0.x86_64-w64-mingw32-gcc7.tar.gz", "de0dc5990e34a6a77984996936a15c4e2e8d57adaa61b7c74847b263cc52d38a"), FreeBSD(:x86_64) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-unknown-freebsd11.1-gcc7.tar.gz", "930df7bf7ecded6936dd9f637787b7eade402c07c0c2b2b49c4e72329d6bd9ef"), ) diff --git a/test/misc.jl b/test/misc.jl index b36b5ceb..f7127b76 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -180,6 +180,7 @@ cxx""" enum myCoolEnum { OneValue = 1 }; """ @assert icxx" OneValue; " == 1 # Exception handling +@static if !Sys.iswindows() try icxx" throw 20; " @assert false @@ -211,7 +212,7 @@ catch e showerror(buf,e) @assert String(take!(buf)) == "5" end - +end # Sys.iswindows # Memory management cxx""" diff --git a/test/std.jl b/test/std.jl index 67fe8a6d..6411dd7c 100644 --- a/test/std.jl +++ b/test/std.jl @@ -239,7 +239,7 @@ end end end end - +@static if !Sys.iswindows() @testset "Exceptions" begin @testset "std::length_error&" begin v = icxx"std::vector<$Int>{1, 2, 3};" @@ -252,3 +252,4 @@ end end end end +end From 78908a1dc7cf6ce683a0b0ffbb07cabb00a45497 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Sat, 6 Jul 2019 13:02:15 +0800 Subject: [PATCH 3/8] Update AddressSpace --- src/bootstrap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index a5b56377..41e4ba5a 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -130,9 +130,12 @@ static llvm::Type *T_prjlvalue; // From julia's codegen_shared.h enum AddressSpace { Generic = 0, - Tracked = 10, Derived = 11, CalleeRooted = 12, + Tracked = 10, + Derived = 11, + CalleeRooted = 12, + Loaded = 13, FirstSpecial = Tracked, - LastSpecial = CalleeRooted, + LastSpecial = Loaded, }; #define JLCALL_CC (CallingConv::ID)36 From 7eb9ea77deb6078e6a75344cf69341e83c9b69d7 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Sat, 6 Jul 2019 13:06:37 +0800 Subject: [PATCH 4/8] Fix pch paths on Windows not sure why `/xxx` can't work --- src/bootstrap.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 41e4ba5a..6b66cfa6 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -6,6 +6,11 @@ #include #include +#if defined(_WIN32) || defined(_WIN64) +#define _OS_WINDOWS_ +#endif + + #ifdef NDEBUG #define OLD_NDEBUG #endif @@ -1491,16 +1496,26 @@ static void finish_clang_init(C, bool EmitPCH, const char *PCHBuffer, size_t PCH clang::vfs::getRealFileSystem())); llvm::IntrusiveRefCntPtr IMFS( new clang::vfs::InMemoryFileSystem); +#ifdef _OS_WINDOWS_ + IMFS->addFile("C:/Cxx.pch", PCHTime, llvm::MemoryBuffer::getMemBuffer( + StringRef(PCHBuffer, PCHBufferSize), "Cxx.pch", false + )); +#else IMFS->addFile("/Cxx.pch", PCHTime, llvm::MemoryBuffer::getMemBuffer( StringRef(PCHBuffer, PCHBufferSize), "Cxx.pch", false )); +#endif Overlay->pushOverlay(IMFS); Cxx->CI->setVirtualFileSystem(Overlay); } Cxx->CI->createFileManager(); Cxx->CI->createSourceManager(Cxx->CI->getFileManager()); if (PCHBuffer) { +#ifdef _OS_WINDOWS_ + Cxx->CI->getPreprocessorOpts().ImplicitPCHInclude = "C:/Cxx.pch"; +#else Cxx->CI->getPreprocessorOpts().ImplicitPCHInclude = "/Cxx.pch"; +#endif } Cxx->CI->createPreprocessor(clang::TU_Prefix); Cxx->CI->createASTContext(); @@ -1557,7 +1572,11 @@ static void finish_clang_init(C, bool EmitPCH, const char *PCHBuffer, size_t PCH Cxx->CI->getASTConsumer().GetASTDeserializationListener(); bool DeleteDeserialListener = false; Cxx->CI->createPCHExternalASTSource( +#ifdef _OS_WINDOWS_ + "C:/Cxx.pch", +#else "/Cxx.pch", +#endif Cxx->CI->getPreprocessorOpts().DisablePCHValidation, Cxx->CI->getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener, DeleteDeserialListener); @@ -1583,7 +1602,11 @@ static void finish_clang_init(C, bool EmitPCH, const char *PCHBuffer, size_t PCH pp.enableIncrementalProcessing(); clang::SourceManager &sm = Cxx->CI->getSourceManager(); +#ifdef _OS_WINDOWS_ + const char *fname = PCHBuffer ? "C:/Cxx.cpp" : "C:/Cxx.h"; +#else const char *fname = PCHBuffer ? "/Cxx.cpp" : "/Cxx.h"; +#endif const clang::FileEntry *MainFile = Cxx->CI->getFileManager().getVirtualFile(fname, 0, time(0)); sm.overrideFileContents(MainFile, llvm::MemoryBuffer::getNewMemBuffer(0, fname)); sm.setMainFileID(sm.createFileID(MainFile, clang::SourceLocation(), clang::SrcMgr::C_User)); @@ -3072,8 +3095,8 @@ JL_DLLEXPORT void *getTypeName(C, void *Ty) extern void jl_error(const char *str); #include "unwind.h" -void __attribute__((noreturn)) (*process_cxx_exception)(uint64_t exceptionClass, _Unwind_Exception* unwind_exception); -_Unwind_Reason_Code __cxxjl_personality_v0 +JL_DLLEXPORT void __attribute__((noreturn)) (*process_cxx_exception)(uint64_t exceptionClass, _Unwind_Exception* unwind_exception); +JL_DLLEXPORT _Unwind_Reason_Code __cxxjl_personality_v0 (int version, _Unwind_Action actions, uint64_t exceptionClass, _Unwind_Exception* unwind_exception, _Unwind_Context* context) { From 487e30be39be005415a2481ed12c82ea627f5620 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Sat, 6 Jul 2019 13:08:23 +0800 Subject: [PATCH 5/8] Fix a LLVM bitcast error on Windows --- src/bootstrap.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 6b66cfa6..50403ee3 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -121,6 +121,25 @@ #undef NDEBUG #endif +#if defined(_CPU_X86_64_) +# define _P64 +#elif defined(_CPU_X86_) +# define _P32 +#elif defined(_OS_WINDOWS_) +/* Not sure how to determine pointer size on Windows running ARM. */ +# if _WIN64 +# define _P64 +# else +# define _P32 +# endif +#elif __SIZEOF_POINTER__ == 8 +# define _P64 +#elif __SIZEOF_POINTER__ == 4 +# define _P32 +#else +# error pointer size not known for your platform / compiler +#endif + // From julia using namespace llvm; #ifdef LLVM39 @@ -176,13 +195,13 @@ extern "C" { TYPE_ACCESS(cT_uint16,UnsignedShortTy) TYPE_ACCESS(cT_int32,IntTy) TYPE_ACCESS(cT_uint32,UnsignedIntTy) -#ifdef _P32 +//#ifdef _P32 TYPE_ACCESS(cT_int64,LongLongTy) TYPE_ACCESS(cT_uint64,UnsignedLongLongTy) -#else - TYPE_ACCESS(cT_int64,LongTy) - TYPE_ACCESS(cT_uint64,UnsignedLongTy) -#endif +//#else +// TYPE_ACCESS(cT_int64,LongTy) +// TYPE_ACCESS(cT_uint64,UnsignedLongTy) +//#endif TYPE_ACCESS(cT_size,getSizeType()) TYPE_ACCESS(cT_int128,Int128Ty) TYPE_ACCESS(cT_uint128,UnsignedInt128Ty) From 41b6312041f30b2d61c7a3f97f14accc0ce40de1 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Sat, 6 Jul 2019 13:10:24 +0800 Subject: [PATCH 6/8] Exception handling method should be SEH on Windows --- src/bootstrap.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 50403ee3..9753a8e9 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -1456,6 +1456,9 @@ static void set_default_clang_options(C, bool CCompiler, const char *Triple, con Cxx->CI->getLangOpts().Exceptions = 1; // exception handling Cxx->CI->getLangOpts().ObjCExceptions = 1; // Objective-C exceptions Cxx->CI->getLangOpts().CXXExceptions = 1; // C++ exceptions +#ifdef _OS_WINDOWS_ + Cxx->CI->getLangOpts().SEHExceptions = 1; // Julia uses SEH exception handling on Windows +#endif Cxx->CI->getLangOpts().CXXOperatorNames = 1; Cxx->CI->getLangOpts().DoubleSquareBracketAttributes = 1; Cxx->CI->getHeaderSearchOpts().UseLibcxx = 1; From a5aa4e8c8151a8b38fca199aeb1c8988cb9e7366 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Sat, 6 Jul 2019 13:10:54 +0800 Subject: [PATCH 7/8] `C` => `CxxInstance *Cxx` --- src/bootstrap.cpp | 241 +++++++++++++++++++++++----------------------- 1 file changed, 120 insertions(+), 121 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 9753a8e9..574e24fa 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -178,11 +178,10 @@ struct CxxInstance { JuliaPCHGenerator *PCHGenerator; }; const clang::InputKind CKind = clang::InputKind::C; -#define C CxxInstance *Cxx extern "C" { #define TYPE_ACCESS(EX,IN) \ - JL_DLLEXPORT const clang::Type *EX(C) { \ + JL_DLLEXPORT const clang::Type *EX(CxxInstance *Cxx) { \ return Cxx->CI->getASTContext().IN.getTypePtrOrNull(); \ } @@ -214,7 +213,7 @@ extern "C" { } // Utilities -clang::SourceLocation getTrivialSourceLocation(C) +clang::SourceLocation getTrivialSourceLocation(CxxInstance *Cxx) { clang::SourceManager &sm = Cxx->CI->getSourceManager(); return sm.getLocForStartOfFile(sm.getMainFileID()); @@ -227,7 +226,7 @@ extern "C" { extern void jl_error(const char *str); // For initialization.jl -JL_DLLEXPORT void add_directory(C, int kind, int isFramework, const char *dirname) +JL_DLLEXPORT void add_directory(CxxInstance *Cxx, int kind, int isFramework, const char *dirname) { clang::SrcMgr::CharacteristicKind flag = (clang::SrcMgr::CharacteristicKind)kind; clang::FileManager &fm = Cxx->CI->getFileManager(); @@ -239,14 +238,14 @@ JL_DLLEXPORT void add_directory(C, int kind, int isFramework, const char *dirnam pp.getHeaderSearchInfo().AddSearchPath(clang::DirectoryLookup(dir,flag,isFramework),flag == clang::SrcMgr::C_System || flag == clang::SrcMgr::C_ExternCSystem); } -JL_DLLEXPORT int isCCompiler(C) +JL_DLLEXPORT int isCCompiler(CxxInstance *Cxx) { return Cxx->CI->getLangOpts().CPlusPlus == 0 && Cxx->CI->getLangOpts().ObjC1 == 0 && Cxx->CI->getLangOpts().ObjC2 == 0; } -JL_DLLEXPORT int _cxxparse(C) +JL_DLLEXPORT int _cxxparse(CxxInstance *Cxx) { clang::Sema &S = Cxx->CI->getSema(); clang::ASTConsumer *Consumer = &S.getASTConsumer(); @@ -270,7 +269,7 @@ JL_DLLEXPORT int _cxxparse(C) return 1; } -JL_DLLEXPORT void *ParseDeclaration(C, clang::DeclContext *DCScope) +JL_DLLEXPORT void *ParseDeclaration(CxxInstance *Cxx, clang::DeclContext *DCScope) { auto *P = Cxx->Parser; auto *S = &Cxx->CI->getSema(); @@ -288,7 +287,7 @@ JL_DLLEXPORT void *ParseDeclaration(C, clang::DeclContext *DCScope) return S->HandleDeclarator(TheScope, D, clang::MultiTemplateParamsArg()); } -JL_DLLEXPORT void ParseParameterList(C, void **params, size_t nparams) { +JL_DLLEXPORT void ParseParameterList(CxxInstance *Cxx, void **params, size_t nparams) { auto *P = Cxx->Parser; auto *S = &Cxx->CI->getSema(); if (P->getPreprocessor().isIncrementalProcessingEnabled() && @@ -315,7 +314,7 @@ JL_DLLEXPORT void ParseParameterList(C, void **params, size_t nparams) { } -JL_DLLEXPORT void *ParseTypeName(C, int ParseAlias = false) +JL_DLLEXPORT void *ParseTypeName(CxxInstance *Cxx, int ParseAlias = false) { if (Cxx->Parser->getPreprocessor().isIncrementalProcessingEnabled() && Cxx->Parser->getCurToken().is(clang::tok::eof)) @@ -328,7 +327,7 @@ JL_DLLEXPORT void *ParseTypeName(C, int ParseAlias = false) return (void*)QT.getAsOpaquePtr(); } -JL_DLLEXPORT int cxxinclude(C, char *fname, int isAngled) +JL_DLLEXPORT int cxxinclude(CxxInstance *Cxx, char *fname, int isAngled) { const clang::DirectoryLookup *CurDir; clang::FileManager &fm = Cxx->CI->getFileManager(); @@ -359,7 +358,7 @@ typedef llvm::IRBuilder CxxIRBuilder; * Collect all global initializers into one llvm::Function, which * we can then call. */ -JL_DLLEXPORT llvm::Function *CollectGlobalConstructors(C) +JL_DLLEXPORT llvm::Function *CollectGlobalConstructors(CxxInstance *Cxx) { clang::CodeGen::CodeGenModule::CtorList &ctors = Cxx->CGM->getGlobalCtors(); GlobalVariable *GV = Cxx->shadow->getGlobalVariable("llvm.global_ctors"); @@ -409,7 +408,7 @@ JL_DLLEXPORT llvm::Function *CollectGlobalConstructors(C) return InitF; } -JL_DLLEXPORT void EnterSourceFile(C, char *data, size_t length) +JL_DLLEXPORT void EnterSourceFile(CxxInstance *Cxx, char *data, size_t length) { const clang::DirectoryLookup *CurDir = nullptr; clang::FileManager &fm = Cxx->CI->getFileManager(); @@ -420,7 +419,7 @@ JL_DLLEXPORT void EnterSourceFile(C, char *data, size_t length) P.EnterSourceFile(FID, CurDir, sm.getLocForStartOfFile(sm.getMainFileID())); } -JL_DLLEXPORT void EnterVirtualFile(C, char *data, size_t length, char *VirtualPath, size_t PathLength) +JL_DLLEXPORT void EnterVirtualFile(CxxInstance *Cxx, char *data, size_t length, char *VirtualPath, size_t PathLength) { const clang::DirectoryLookup *CurDir = nullptr; clang::FileManager &fm = Cxx->CI->getFileManager(); @@ -437,13 +436,13 @@ JL_DLLEXPORT void EnterVirtualFile(C, char *data, size_t length, char *VirtualPa P.EnterSourceFile(FID, CurDir, sm.getLocForStartOfFile(sm.getMainFileID())); } -JL_DLLEXPORT int cxxparse(C, char *data, size_t length) +JL_DLLEXPORT int cxxparse(CxxInstance *Cxx, char *data, size_t length) { EnterSourceFile(Cxx, data, length); return _cxxparse(Cxx); } -JL_DLLEXPORT void defineMacro(C,const char *Name) +JL_DLLEXPORT void defineMacro(CxxInstance *Cxx,const char *Name) { clang::Preprocessor &PP = Cxx->Parser->getPreprocessor(); // Get the identifier. @@ -455,7 +454,7 @@ JL_DLLEXPORT void defineMacro(C,const char *Name) } // For typetranslation.jl -JL_DLLEXPORT bool BuildNNS(C, clang::CXXScopeSpec *spec, const char *Name) +JL_DLLEXPORT bool BuildNNS(CxxInstance *Cxx, clang::CXXScopeSpec *spec, const char *Name) { clang::Preprocessor &PP = Cxx->CI->getPreprocessor(); // Get the identifier. @@ -488,7 +487,7 @@ JL_DLLEXPORT bool BuildNNS(C, clang::CXXScopeSpec *spec, const char *Name) #endif } -JL_DLLEXPORT void *lookup_name(C, char *name, clang::DeclContext *ctx) +JL_DLLEXPORT void *lookup_name(CxxInstance *Cxx, char *name, clang::DeclContext *ctx) { clang::SourceManager &sm = Cxx->CI->getSourceManager(); clang::CXXScopeSpec spec; @@ -506,7 +505,7 @@ JL_DLLEXPORT void *lookup_name(C, char *name, clang::DeclContext *ctx) return R.empty() ? NULL : R.getRepresentativeDecl(); } -JL_DLLEXPORT void *SpecializeClass(C, clang::ClassTemplateDecl *tmplt, void **types, uint64_t *integralValues,int8_t *integralValuePresent, size_t nargs) +JL_DLLEXPORT void *SpecializeClass(CxxInstance *Cxx, clang::ClassTemplateDecl *tmplt, void **types, uint64_t *integralValues,int8_t *integralValuePresent, size_t nargs) { clang::TemplateArgument *targs = new clang::TemplateArgument[nargs]; for (size_t i = 0; i < nargs; ++i) { @@ -597,7 +596,7 @@ JL_DLLEXPORT char *simple_decl_name(clang::NamedDecl *decl) } // For cxxstr -JL_DLLEXPORT void *createNamespace(C,char *name) +JL_DLLEXPORT void *createNamespace(CxxInstance *Cxx,char *name) { clang::IdentifierInfo *Id = Cxx->CI->getPreprocessor().getIdentifierInfo(name); return (void*)clang::NamespaceDecl::Create( @@ -611,7 +610,7 @@ JL_DLLEXPORT void *createNamespace(C,char *name) ); } -JL_DLLEXPORT void SetDeclInitializer(C, clang::VarDecl *D, llvm::Constant *CI) +JL_DLLEXPORT void SetDeclInitializer(CxxInstance *Cxx, clang::VarDecl *D, llvm::Constant *CI) { llvm::Constant *Const = Cxx->CGM->GetAddrOfGlobalVar(D); if (!isa(Const)) @@ -621,12 +620,12 @@ JL_DLLEXPORT void SetDeclInitializer(C, clang::VarDecl *D, llvm::Constant *CI) GV->setConstant(true); } -JL_DLLEXPORT void *GetAddrOfFunction(C, clang::FunctionDecl *D) +JL_DLLEXPORT void *GetAddrOfFunction(CxxInstance *Cxx, clang::FunctionDecl *D) { return (void*)Cxx->CGM->GetAddrOfFunction(D); } -size_t cxxsizeofType(C, void *t); +size_t cxxsizeofType(CxxInstance *Cxx, void *t); typedef struct cppcall_state { // Save previous globals llvm::Module *module; @@ -639,10 +638,10 @@ typedef struct cppcall_state { llvm::Instruction *alloca_bb_ptr; } cppcall_state_t; -void *setup_cpp_env(C, void *jlfunc); -void cleanup_cpp_env(C, cppcall_state_t *); +void *setup_cpp_env(CxxInstance *Cxx, void *jlfunc); +void cleanup_cpp_env(CxxInstance *Cxx, cppcall_state_t *); extern void jl_(void*); -static Function *CloneFunctionAndAdjust(C, Function *F, FunctionType *FTy, +static Function *CloneFunctionAndAdjust(CxxInstance *Cxx, Function *F, FunctionType *FTy, bool ModuleLevelChanges, ClonedCodeInfo *CodeInfo, const clang::CodeGen::CGFunctionInfo &FI, @@ -902,7 +901,7 @@ JL_DLLEXPORT void *DeleteUnusedArguments(llvm::Function *F, uint64_t *dtodelete, } -JL_DLLEXPORT void ReplaceFunctionForDecl(C,clang::FunctionDecl *D, llvm::Function *F, bool DoInline, bool specsig, bool firstIsEnv, bool *needsbox, void *retty, void **juliatypes, bool newgc) +JL_DLLEXPORT void ReplaceFunctionForDecl(CxxInstance *Cxx,clang::FunctionDecl *D, llvm::Function *F, bool DoInline, bool specsig, bool firstIsEnv, bool *needsbox, void *retty, void **juliatypes, bool newgc) { const clang::CodeGen::CGFunctionInfo &FI = Cxx->CGM->getTypes().arrangeGlobalDeclaration(D); llvm::FunctionType *Ty = Cxx->CGM->getTypes().GetFunctionType(FI); @@ -946,14 +945,14 @@ JL_DLLEXPORT void ReplaceFunctionForDecl(C,clang::FunctionDecl *D, llvm::Functio } } -JL_DLLEXPORT void *ActOnStartOfFunction(C, clang::FunctionDecl *D, bool ScopeIsNull = false) +JL_DLLEXPORT void *ActOnStartOfFunction(CxxInstance *Cxx, clang::FunctionDecl *D, bool ScopeIsNull = false) { clang::Sema &sema = Cxx->CI->getSema(); //ContextRAII SavedContext(sema, DC); return (void*)sema.ActOnStartOfFunctionDef(ScopeIsNull ? nullptr : Cxx->Parser->getCurScope(), D); } -JL_DLLEXPORT bool ParseFunctionStatementBody(C, clang::Decl *D) +JL_DLLEXPORT bool ParseFunctionStatementBody(CxxInstance *Cxx, clang::Decl *D) { clang::Parser::ParseScope BodyScope(Cxx->Parser, clang::Scope::FnScope|clang::Scope::DeclScope); Cxx->Parser->ConsumeToken(); @@ -1018,7 +1017,7 @@ JL_DLLEXPORT bool ParseFunctionStatementBody(C, clang::Decl *D) return true; } -JL_DLLEXPORT void *ActOnStartNamespaceDef(C, char *name) +JL_DLLEXPORT void *ActOnStartNamespaceDef(CxxInstance *Cxx, char *name) { Cxx->Parser->EnterScope(clang::Scope::DeclScope); clang::ParsedAttributes attrs(Cxx->Parser->getAttrFactory()); @@ -1039,7 +1038,7 @@ JL_DLLEXPORT void *ActOnStartNamespaceDef(C, char *name) ); } -JL_DLLEXPORT void ActOnFinishNamespaceDef(C, clang::Decl *D) +JL_DLLEXPORT void ActOnFinishNamespaceDef(CxxInstance *Cxx, clang::Decl *D) { Cxx->Parser->ExitScope(); Cxx->CI->getSema().ActOnFinishNamespaceDef( @@ -1049,7 +1048,7 @@ JL_DLLEXPORT void ActOnFinishNamespaceDef(C, clang::Decl *D) // For codegen.jl -JL_DLLEXPORT int typeconstruct(C,void *type, clang::Expr **rawexprs, size_t nexprs, void **ret) +JL_DLLEXPORT int typeconstruct(CxxInstance *Cxx,void *type, clang::Expr **rawexprs, size_t nexprs, void **ret) { clang::QualType Ty = clang::QualType::getFromOpaquePtr(type); clang::MultiExprArg Exprs(rawexprs,nexprs); @@ -1105,7 +1104,7 @@ JL_DLLEXPORT int typeconstruct(C,void *type, clang::Expr **rawexprs, size_t nexp return true; } -JL_DLLEXPORT void *BuildCXXNewExpr(C, clang::Type *type, clang::Expr **exprs, size_t nexprs) +JL_DLLEXPORT void *BuildCXXNewExpr(CxxInstance *Cxx, clang::Type *type, clang::Expr **exprs, size_t nexprs) { clang::QualType Ty = clang::QualType::getFromOpaquePtr(type); clang::SourceManager &sm = Cxx->CI->getSourceManager(); @@ -1124,13 +1123,13 @@ JL_DLLEXPORT void *BuildCXXNewExpr(C, clang::Type *type, clang::Expr **exprs, si //return (clang_astcontext) new clang::CXXNewExpr(clang_astcontext, false, nE, dE, ) } -JL_DLLEXPORT void *EmitCXXNewExpr(C, clang::Expr *E) +JL_DLLEXPORT void *EmitCXXNewExpr(CxxInstance *Cxx, clang::Expr *E) { assert(isa(E)); return (void*)Cxx->CGF->EmitCXXNewExpr(cast(E)); } -JL_DLLEXPORT void *build_call_to_member(C, clang::Expr *MemExprE,clang::Expr **exprs, size_t nexprs) +JL_DLLEXPORT void *build_call_to_member(CxxInstance *Cxx, clang::Expr *MemExprE,clang::Expr **exprs, size_t nexprs) { if (MemExprE->getType() == Cxx->CI->getASTContext().BoundMemberTy || MemExprE->getType() == Cxx->CI->getASTContext().OverloadTy) @@ -1147,7 +1146,7 @@ JL_DLLEXPORT void *build_call_to_member(C, clang::Expr *MemExprE,clang::Expr **e } } -JL_DLLEXPORT void *PerformMoveOrCopyInitialization(C, void *rt, clang::Expr *expr) +JL_DLLEXPORT void *PerformMoveOrCopyInitialization(CxxInstance *Cxx, void *rt, clang::Expr *expr) { clang::InitializedEntity Entity = clang::InitializedEntity::InitializeTemporary( clang::QualType::getFromOpaquePtr(rt)); @@ -1156,11 +1155,11 @@ JL_DLLEXPORT void *PerformMoveOrCopyInitialization(C, void *rt, clang::Expr *exp } // For CxxREPL -JL_DLLEXPORT void *clang_compiler(C) +JL_DLLEXPORT void *clang_compiler(CxxInstance *Cxx) { return (void*)Cxx->CI; } -JL_DLLEXPORT void *clang_parser(C) +JL_DLLEXPORT void *clang_parser(CxxInstance *Cxx) { return (void*)Cxx->Parser; } @@ -1274,7 +1273,7 @@ class ValidatingASTVisitor : public clang::DeclVisitor, class JuliaCodeGenerator : public clang::ASTConsumer { public: - JuliaCodeGenerator(C) : Cxx(*Cxx) {} + JuliaCodeGenerator(CxxInstance *Cxx) : Cxx(*Cxx) {} CxxInstance Cxx; ValidatingASTVisitor Visitor; @@ -1403,7 +1402,7 @@ extern "C" { -static void set_common_options(C) +static void set_common_options(CxxInstance *Cxx) { Cxx->CI->getDiagnosticOpts().ShowColors = 1; Cxx->CI->getDiagnosticOpts().ShowPresumedLoc = 1; @@ -1417,7 +1416,7 @@ static void set_common_options(C) ); } -static void set_default_clang_options(C, bool CCompiler, const char *Triple, const char *CPU, const char *SysRoot, Type *_T_pvalue_llvmt) +static void set_default_clang_options(CxxInstance *Cxx, bool CCompiler, const char *Triple, const char *CPU, const char *SysRoot, Type *_T_pvalue_llvmt) { T_pvalue_llvmt = _T_pvalue_llvmt; T_pjlvalue = PointerType::get( @@ -1501,13 +1500,13 @@ static void set_default_clang_options(C, bool CCompiler, const char *Triple, con } } -JL_DLLEXPORT int set_access_control_enabled(C, int enabled) { +JL_DLLEXPORT int set_access_control_enabled(CxxInstance *Cxx, int enabled) { int enabled_before = Cxx->CI->getLangOpts().AccessControl; Cxx->CI->getLangOpts().AccessControl = enabled; return enabled_before; } -static void finish_clang_init(C, bool EmitPCH, const char *PCHBuffer, size_t PCHBufferSize, time_t PCHTime) { +static void finish_clang_init(CxxInstance *Cxx, bool EmitPCH, const char *PCHBuffer, size_t PCHBufferSize, time_t PCHTime) { Cxx->CI->setTarget(clang::TargetInfo::CreateTargetInfo( Cxx->CI->getDiagnostics(), std::make_shared(Cxx->CI->getTargetOpts()))); @@ -1642,12 +1641,12 @@ static void finish_clang_init(C, bool EmitPCH, const char *PCHBuffer, size_t PCH _cxxparse(Cxx); - f_julia_type_to_llvm = (llvm::Type *(*)(void *, bool *)) - dlsym(RTLD_DEFAULT, "julia_type_to_llvm"); + f_julia_type_to_llvm = (llvm::Type *(*)(void *, bool *))dlsym(RTLD_DEFAULT, "julia_type_to_llvm"); + assert(f_julia_type_to_llvm); } -JL_DLLEXPORT void init_clang_instance(C, const char *Triple, const char *CPU, const char *SysRoot, bool EmitPCH, +JL_DLLEXPORT void init_clang_instance(CxxInstance *Cxx, const char *Triple, const char *CPU, const char *SysRoot, bool EmitPCH, bool CCompiler, const char *PCHBuffer, size_t PCHBufferSize, struct tm *PCHTime, Type *_T_pvalue_llvmt) { Cxx->CI = new clang::CompilerInstance; set_common_options(Cxx); @@ -1658,7 +1657,7 @@ JL_DLLEXPORT void init_clang_instance(C, const char *Triple, const char *CPU, co finish_clang_init(Cxx, EmitPCH, PCHBuffer, PCHBufferSize, t); } -JL_DLLEXPORT void init_clang_instance_from_invocation(C, clang::CompilerInvocation *Inv) +JL_DLLEXPORT void init_clang_instance_from_invocation(CxxInstance *Cxx, clang::CompilerInvocation *Inv) { Cxx->CI = new clang::CompilerInstance; #ifdef LLVM40 @@ -1673,7 +1672,7 @@ JL_DLLEXPORT void init_clang_instance_from_invocation(C, clang::CompilerInvocati #define xstringify(s) stringify(s) #define stringify(s) #s -JL_DLLEXPORT void apply_default_abi(C) +JL_DLLEXPORT void apply_default_abi(CxxInstance *Cxx) { #if defined(_GLIBCXX_USE_CXX11_ABI) char define[] = "#define _GLIBCXX_USE_CXX11_ABI " xstringify(_GLIBCXX_USE_CXX11_ABI); @@ -1681,12 +1680,12 @@ JL_DLLEXPORT void apply_default_abi(C) #endif } -JL_DLLEXPORT size_t getPCHSize(C) { +JL_DLLEXPORT size_t getPCHSize(CxxInstance *Cxx) { Cxx->PCHGenerator->HandleTranslationUnit(Cxx->CI->getASTContext()); return Cxx->PCHGenerator->getPCHSize(); } -void decouple_pch(C, char *data) +JL_DLLEXPORT void decouple_pch(CxxInstance *Cxx, char *data) { Cxx->PCHGenerator->getPCHData(data); Cxx->JCodeGen = new JuliaCodeGenerator(Cxx); @@ -1698,7 +1697,7 @@ static llvm::Module *cur_module = NULL; static llvm::Function *cur_func = NULL; -JL_DLLEXPORT void *setup_cpp_env(C, void *jlfunc) +JL_DLLEXPORT void *setup_cpp_env(CxxInstance *Cxx, void *jlfunc) { //assert(in_cpp == false); //in_cpp = true; @@ -1746,12 +1745,12 @@ JL_DLLEXPORT void *setup_cpp_env(C, void *jlfunc) return state; } -JL_DLLEXPORT bool EmitTopLevelDecl(C, clang::Decl *D) +JL_DLLEXPORT bool EmitTopLevelDecl(CxxInstance *Cxx, clang::Decl *D) { return Cxx->JCodeGen->EmitTopLevelDecl(D); } -JL_DLLEXPORT void cleanup_cpp_env(C, cppcall_state_t *state) +JL_DLLEXPORT void cleanup_cpp_env(CxxInstance *Cxx, cppcall_state_t *state) { //assert(in_cpp == true); //in_cpp = false; @@ -1815,13 +1814,13 @@ ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, 04468 Expr *ExecConfig, bool IsExecConfig) { 04469 // Since this might be a postfix expression, get rid of Pare */ -JL_DLLEXPORT void *CreateCallExpr(C, clang::Expr *Fn,clang::Expr **exprs, size_t nexprs) +JL_DLLEXPORT void *CreateCallExpr(CxxInstance *Cxx, clang::Expr *Fn,clang::Expr **exprs, size_t nexprs) { return Cxx->CI->getSema().ActOnCallExpr(NULL, Fn, getTrivialSourceLocation(Cxx), clang::MultiExprArg(exprs,nexprs), getTrivialSourceLocation(Cxx), NULL, false).get(); } -JL_DLLEXPORT void *CreateVarDecl(C, void *DC, char* name, void *type) +JL_DLLEXPORT void *CreateVarDecl(CxxInstance *Cxx, void *DC, char* name, void *type) { clang::QualType T = clang::QualType::getFromOpaquePtr(type); clang::VarDecl *D = clang::VarDecl::Create(Cxx->CI->getASTContext(), (clang::DeclContext *)DC, @@ -1831,7 +1830,7 @@ JL_DLLEXPORT void *CreateVarDecl(C, void *DC, char* name, void *type) return D; } -JL_DLLEXPORT void *CreateFunctionDecl(C, void *DC, char* name, void *type, int isextern) +JL_DLLEXPORT void *CreateFunctionDecl(CxxInstance *Cxx, void *DC, char* name, void *type, int isextern) { clang::QualType T = clang::QualType::getFromOpaquePtr(type); clang::FunctionDecl *D = clang::FunctionDecl::Create(Cxx->CI->getASTContext(), (clang::DeclContext *)DC, @@ -1846,7 +1845,7 @@ JL_DLLEXPORT void *CreateFunctionDecl(C, void *DC, char* name, void *type, int i return D; } -JL_DLLEXPORT void *CreateCxxCallMethodDecl(C, clang::CXXRecordDecl *TheClass, void *QT) +JL_DLLEXPORT void *CreateCxxCallMethodDecl(CxxInstance *Cxx, clang::CXXRecordDecl *TheClass, void *QT) { clang::DeclarationName MethodName = Cxx->CI->getASTContext().DeclarationNames.getCXXOperatorName(clang::OO_Call); @@ -1867,7 +1866,7 @@ JL_DLLEXPORT void *CreateCxxCallMethodDecl(C, clang::CXXRecordDecl *TheClass, vo return Method; } -JL_DLLEXPORT void *CreateParmVarDecl(C, void *type, char *name, int used) +JL_DLLEXPORT void *CreateParmVarDecl(CxxInstance *Cxx, void *type, char *name, int used) { clang::QualType T = clang::QualType::getFromOpaquePtr(type); clang::ParmVarDecl *d = clang::ParmVarDecl::Create( @@ -1884,7 +1883,7 @@ JL_DLLEXPORT void *CreateParmVarDecl(C, void *type, char *name, int used) return (void*)d; } -JL_DLLEXPORT void *CreateTypeDefDecl(C, clang::DeclContext *DC, char *name, void *type) +JL_DLLEXPORT void *CreateTypeDefDecl(CxxInstance *Cxx, clang::DeclContext *DC, char *name, void *type) { clang::QualType T = clang::QualType::getFromOpaquePtr(type); return (void*)clang::TypedefDecl::Create(Cxx->CI->getASTContext(),DC,getTrivialSourceLocation(Cxx), @@ -1906,7 +1905,7 @@ JL_DLLEXPORT void SetFDParams(clang::FunctionDecl *FD, clang::ParmVarDecl **PVDs } } -JL_DLLEXPORT void AssociateValue(C, clang::Decl *d, void *type, llvm::Value *V) +JL_DLLEXPORT void AssociateValue(CxxInstance *Cxx, clang::Decl *d, void *type, llvm::Value *V) { clang::VarDecl *vd = dyn_cast(d); clang::QualType T = clang::QualType::getFromOpaquePtr(type); @@ -1927,12 +1926,12 @@ JL_DLLEXPORT void AddDeclToDeclCtx(clang::DeclContext *DC, clang::Decl *D) DC->addDecl(D); } -JL_DLLEXPORT void AddTopLevelDecl(C, clang::NamedDecl *D) +JL_DLLEXPORT void AddTopLevelDecl(CxxInstance *Cxx, clang::NamedDecl *D) { Cxx->CI->getSema().pushExternalDeclIntoScope(D, D->getDeclName()); } -JL_DLLEXPORT void *CreateDeclRefExpr(C,clang::ValueDecl *D, clang::CXXScopeSpec *scope, int islvalue) +JL_DLLEXPORT void *CreateDeclRefExpr(CxxInstance *Cxx,clang::ValueDecl *D, clang::CXXScopeSpec *scope, int islvalue) { clang::QualType T = D->getType(); return (void*)clang::DeclRefExpr::Create(Cxx->CI->getASTContext(), scope ? @@ -1941,7 +1940,7 @@ JL_DLLEXPORT void *CreateDeclRefExpr(C,clang::ValueDecl *D, clang::CXXScopeSpec T.getNonReferenceType(), islvalue ? clang::VK_LValue : clang::VK_RValue); } -JL_DLLEXPORT void *EmitDeclRef(C, clang::DeclRefExpr *DRE) +JL_DLLEXPORT void *EmitDeclRef(CxxInstance *Cxx, clang::DeclRefExpr *DRE) { #ifdef LLVM38 return Cxx->CGF->EmitDeclRefLValue(DRE).getPointer(); @@ -1955,7 +1954,7 @@ JL_DLLEXPORT void *DeduceReturnType(clang::Expr *expr) return expr->getType().getAsOpaquePtr(); } -JL_DLLEXPORT void *CreateFunction(C, llvm::Type *rt, llvm::Type** argt, size_t nargs) +JL_DLLEXPORT void *CreateFunction(CxxInstance *Cxx, llvm::Type *rt, llvm::Type** argt, size_t nargs) { llvm::FunctionType *ft = llvm::FunctionType::get(rt,llvm::ArrayRef(argt,nargs),false); return (void*)llvm::Function::Create(ft, llvm::GlobalValue::ExternalLinkage, "cxxjl", Cxx->shadow); @@ -1982,7 +1981,7 @@ JL_DLLEXPORT unsigned extractCVR(void *QT) return clang::QualType::getFromOpaquePtr(QT).getCVRQualifiers(); } -JL_DLLEXPORT void *emitcallexpr(C, clang::Expr *E, llvm::Value *rslot) +JL_DLLEXPORT void *emitcallexpr(CxxInstance *Cxx, clang::Expr *E, llvm::Value *rslot) { if (isa(E)) E = cast(E)->getSubExpr(); @@ -2007,7 +2006,7 @@ JL_DLLEXPORT void *emitcallexpr(C, clang::Expr *E, llvm::Value *rslot) #endif } -JL_DLLEXPORT void emitexprtomem(C,clang::Expr *E, llvm::Value *addr, int isInit) +JL_DLLEXPORT void emitexprtomem(CxxInstance *Cxx,clang::Expr *E, llvm::Value *addr, int isInit) { Cxx->CGF->EmitAnyExprToMem(E, #ifdef LLVM38 @@ -2018,7 +2017,7 @@ JL_DLLEXPORT void emitexprtomem(C,clang::Expr *E, llvm::Value *addr, int isInit) clang::Qualifiers(), isInit); } -JL_DLLEXPORT void *EmitAnyExpr(C, clang::Expr *E, llvm::Value *rslot) +JL_DLLEXPORT void *EmitAnyExpr(CxxInstance *Cxx, clang::Expr *E, llvm::Value *rslot) { clang::CodeGen::RValue ret = Cxx->CGF->EmitAnyExpr(E); if (ret.isScalar()) @@ -2043,7 +2042,7 @@ JL_DLLEXPORT void *get_nth_argument(Function *f, size_t n) return NULL; } -JL_DLLEXPORT void *create_extract_value(C, Value *agg, size_t idx) +JL_DLLEXPORT void *create_extract_value(CxxInstance *Cxx, Value *agg, size_t idx) { return Cxx->CGF->Builder.CreateExtractValue(agg,ArrayRef((unsigned)idx)); } @@ -2062,7 +2061,7 @@ JL_DLLEXPORT void *CreatePtrToInt(CxxIRBuilder *builder, Value *TheInt, Type *Ty { return builder->CreatePtrToInt(TheInt, Ty); } -JL_DLLEXPORT void *tu_decl(C) +JL_DLLEXPORT void *tu_decl(CxxInstance *Cxx) { return Cxx->CI->getASTContext().getTranslationUnitDecl(); } @@ -2118,7 +2117,7 @@ JL_DLLEXPORT void *GetFunctionReturnType(clang::FunctionDecl *FD) return FD->getReturnType().getAsOpaquePtr(); } -JL_DLLEXPORT void *BuildDecltypeType(C, clang::Expr *E) +JL_DLLEXPORT void *BuildDecltypeType(CxxInstance *Cxx, clang::Expr *E) { clang::QualType T = Cxx->CI->getSema().BuildDecltypeType(E,E->getLocStart()); return Cxx->CI->getASTContext().getCanonicalType(T).getAsOpaquePtr(); @@ -2234,50 +2233,50 @@ JL_DLLEXPORT void *getOriginalType(clang::ParmVarDecl *d) return (void*)d->getOriginalType().getAsOpaquePtr(); } -JL_DLLEXPORT void *getPointerTo(C, void *T) +JL_DLLEXPORT void *getPointerTo(CxxInstance *Cxx, void *T) { return Cxx->CI->getASTContext().getPointerType(clang::QualType::getFromOpaquePtr(T)).getAsOpaquePtr(); } -JL_DLLEXPORT void *getReferenceTo(C, void *T) +JL_DLLEXPORT void *getReferenceTo(CxxInstance *Cxx, void *T) { return Cxx->CI->getASTContext().getLValueReferenceType(clang::QualType::getFromOpaquePtr(T)).getAsOpaquePtr(); } -JL_DLLEXPORT void *getRvalueReferenceTo(C, void *T) +JL_DLLEXPORT void *getRvalueReferenceTo(CxxInstance *Cxx, void *T) { return Cxx->CI->getASTContext().getRValueReferenceType(clang::QualType::getFromOpaquePtr(T)).getAsOpaquePtr(); } -JL_DLLEXPORT void *getIncompleteArrayType(C, void *T) +JL_DLLEXPORT void *getIncompleteArrayType(CxxInstance *Cxx, void *T) { return Cxx->CI->getASTContext().getIncompleteArrayType( clang::QualType::getFromOpaquePtr(T), clang::ArrayType::Normal, 0).getAsOpaquePtr(); } -JL_DLLEXPORT void *createDerefExpr(C, clang::Expr *expr) +JL_DLLEXPORT void *createDerefExpr(CxxInstance *Cxx, clang::Expr *expr) { return (void*)Cxx->CI->getSema().CreateBuiltinUnaryOp(getTrivialSourceLocation(Cxx),clang::UO_Deref,expr).get(); } -JL_DLLEXPORT void *createAddrOfExpr(C, clang::Expr *expr) +JL_DLLEXPORT void *createAddrOfExpr(CxxInstance *Cxx, clang::Expr *expr) { return (void*)Cxx->CI->getSema().CreateBuiltinUnaryOp(getTrivialSourceLocation(Cxx),clang::UO_AddrOf,expr).get(); } -JL_DLLEXPORT void *createCast(C,clang::Expr *expr, clang::Type *t, int kind) +JL_DLLEXPORT void *createCast(CxxInstance *Cxx,clang::Expr *expr, clang::Type *t, int kind) { return clang::ImplicitCastExpr::Create(Cxx->CI->getASTContext(),clang::QualType(t,0), (clang::CastKind)kind,expr,NULL,clang::VK_RValue); } -JL_DLLEXPORT void *CreateBinOp(C, clang::Scope *S, int opc, clang::Expr *LHS, clang::Expr *RHS) +JL_DLLEXPORT void *CreateBinOp(CxxInstance *Cxx, clang::Scope *S, int opc, clang::Expr *LHS, clang::Expr *RHS) { return (void*)Cxx->CI->getSema().BuildBinOp(S,clang::SourceLocation(),(clang::BinaryOperatorKind)opc,LHS,RHS).get(); } -JL_DLLEXPORT void *BuildMemberReference(C, clang::Expr *base, clang::Type *t, int IsArrow, char *name) +JL_DLLEXPORT void *BuildMemberReference(CxxInstance *Cxx, clang::Expr *base, clang::Type *t, int IsArrow, char *name) { clang::DeclarationName DName(&Cxx->CI->getASTContext().Idents.get(name)); clang::Sema &sema = Cxx->CI->getSema(); @@ -2286,7 +2285,7 @@ JL_DLLEXPORT void *BuildMemberReference(C, clang::Expr *base, clang::Type *t, in getTrivialSourceLocation(Cxx), nullptr, clang::DeclarationNameInfo(DName, getTrivialSourceLocation(Cxx)), nullptr, nullptr).get(); } -JL_DLLEXPORT void *BuildDeclarationNameExpr(C, char *name, clang::DeclContext *ctx) +JL_DLLEXPORT void *BuildDeclarationNameExpr(CxxInstance *Cxx, char *name, clang::DeclContext *ctx) { clang::Sema &sema = Cxx->CI->getSema(); clang::SourceManager &sm = Cxx->CI->getSourceManager(); @@ -2300,7 +2299,7 @@ JL_DLLEXPORT void *BuildDeclarationNameExpr(C, char *name, clang::DeclContext *c return (void*)sema.BuildDeclarationNameExpr(spec,R,false).get(); } -JL_DLLEXPORT void *clang_get_builder(C) +JL_DLLEXPORT void *clang_get_builder(CxxInstance *Cxx) { return (void*)&Cxx->CGF->Builder; } @@ -2456,7 +2455,7 @@ JL_DLLEXPORT void *CreateBitCast(CxxIRBuilder *builder, llvm::Value *val, llvm:: return (void*)builder->CreateBitCast(val,type); } -JL_DLLEXPORT void *CreatePointerFromObjref(C, CxxIRBuilder *builder, llvm::Value *val) +JL_DLLEXPORT void *CreatePointerFromObjref(CxxInstance *Cxx, CxxIRBuilder *builder, llvm::Value *val) { Type *T_pdjlvalue = PointerType::get( cast(T_prjlvalue)->getElementType(), AddressSpace::Derived); @@ -2481,7 +2480,7 @@ JL_DLLEXPORT void *getConstantIntToPtr(llvm::Constant *CC, llvm::Type *type) return (void*)ConstantExpr::getIntToPtr(CC,type); } -JL_DLLEXPORT size_t cxxsizeof(C, clang::CXXRecordDecl *decl) +JL_DLLEXPORT size_t cxxsizeof(CxxInstance *Cxx, clang::CXXRecordDecl *decl) { clang::CodeGen::CodeGenTypes *cgt = &Cxx->CGM->getTypes(); #ifdef LLVM38 @@ -2495,7 +2494,7 @@ JL_DLLEXPORT size_t cxxsizeof(C, clang::CXXRecordDecl *decl) return dl.getTypeSizeInBits(t)/8; } -JL_DLLEXPORT size_t cxxsizeofType(C, void *t) +JL_DLLEXPORT size_t cxxsizeofType(CxxInstance *Cxx, void *t) { auto dl = Cxx->shadow->getDataLayout(); clang::CodeGen::CodeGenTypes *cgt = &Cxx->CGM->getTypes(); @@ -2503,7 +2502,7 @@ JL_DLLEXPORT size_t cxxsizeofType(C, void *t) cgt->ConvertTypeForMem(clang::QualType::getFromOpaquePtr(t)))/8; } -JL_DLLEXPORT void *ConvertTypeForMem(C, void *t) +JL_DLLEXPORT void *ConvertTypeForMem(CxxInstance *Cxx, void *t) { return (void*)Cxx->CGM->getTypes().ConvertTypeForMem(clang::QualType::getFromOpaquePtr(t)); } @@ -2556,7 +2555,7 @@ JL_DLLEXPORT void *getCalleeReturnType(clang::CallExpr *e) return (void*)fd->getReturnType().getAsOpaquePtr(); } -JL_DLLEXPORT void *newCXXScopeSpec(C) +JL_DLLEXPORT void *newCXXScopeSpec(CxxInstance *Cxx) { clang::CXXScopeSpec *scope = new clang::CXXScopeSpec(); scope->MakeGlobal(Cxx->CI->getASTContext(),getTrivialSourceLocation(Cxx)); @@ -2568,12 +2567,12 @@ JL_DLLEXPORT void deleteCXXScopeSpec(clang::CXXScopeSpec *spec) delete spec; } -JL_DLLEXPORT void ExtendNNS(C,clang::NestedNameSpecifierLocBuilder *builder, clang::NamespaceDecl *d) +JL_DLLEXPORT void ExtendNNS(CxxInstance *Cxx,clang::NestedNameSpecifierLocBuilder *builder, clang::NamespaceDecl *d) { builder->Extend(Cxx->CI->getASTContext(),d,getTrivialSourceLocation(Cxx),getTrivialSourceLocation(Cxx)); } -JL_DLLEXPORT void ExtendNNSIdentifier(C,clang::NestedNameSpecifierLocBuilder *builder, const char *Name) +JL_DLLEXPORT void ExtendNNSIdentifier(CxxInstance *Cxx,clang::NestedNameSpecifierLocBuilder *builder, const char *Name) { clang::Preprocessor &PP = Cxx->Parser->getPreprocessor(); // Get the identifier. @@ -2581,7 +2580,7 @@ JL_DLLEXPORT void ExtendNNSIdentifier(C,clang::NestedNameSpecifierLocBuilder *bu builder->Extend(Cxx->CI->getASTContext(),Id,getTrivialSourceLocation(Cxx),getTrivialSourceLocation(Cxx)); } -JL_DLLEXPORT void ExtendNNSType(C,clang::NestedNameSpecifierLocBuilder *builder, void *t) +JL_DLLEXPORT void ExtendNNSType(CxxInstance *Cxx,clang::NestedNameSpecifierLocBuilder *builder, void *t) { clang::TypeLocBuilder TLBuilder; clang::QualType T = clang::QualType::getFromOpaquePtr(t); @@ -2593,7 +2592,7 @@ JL_DLLEXPORT void ExtendNNSType(C,clang::NestedNameSpecifierLocBuilder *builder, getTrivialSourceLocation(Cxx)); } -JL_DLLEXPORT void *makeFunctionType(C, void *rt, void **argts, size_t nargs) +JL_DLLEXPORT void *makeFunctionType(CxxInstance *Cxx, void *rt, void **argts, size_t nargs) { clang::QualType T; if (rt == NULL) { @@ -2614,7 +2613,7 @@ JL_DLLEXPORT void *makeFunctionType(C, void *rt, void **argts, size_t nargs) return Cxx->CI->getASTContext().getFunctionType(T, llvm::ArrayRef(qargs, nargs), EPI).getAsOpaquePtr(); } -JL_DLLEXPORT void *makeMemberFunctionType(C, void *FT, clang::Type *cls) +JL_DLLEXPORT void *makeMemberFunctionType(CxxInstance *Cxx, void *FT, clang::Type *cls) { return Cxx->CI->getASTContext().getMemberPointerType(clang::QualType::getFromOpaquePtr(FT), cls).getAsOpaquePtr(); } @@ -2659,7 +2658,7 @@ JL_DLLEXPORT void *getLLVMStructType(llvm::Type **ts, size_t nts) return (void*)llvm::StructType::get(jl_LLVMContext,ArrayRef(ts,nts)); } -JL_DLLEXPORT void MarkDeclarationsReferencedInExpr(C,clang::Expr *e) +JL_DLLEXPORT void MarkDeclarationsReferencedInExpr(CxxInstance *Cxx,clang::Expr *e) { clang::Sema &sema = Cxx->CI->getSema(); sema.MarkDeclarationsReferencedInExpr(e, true); @@ -2695,23 +2694,23 @@ JL_DLLEXPORT int isDeclInvalid(clang::Decl *D) } // Test Support -JL_DLLEXPORT void *clang_get_cgt(C) +JL_DLLEXPORT void *clang_get_cgt(CxxInstance *Cxx) { return (void*)&Cxx->CGM->getTypes(); } -JL_DLLEXPORT void *clang_shadow_module(C) +JL_DLLEXPORT void *clang_shadow_module(CxxInstance *Cxx) { return (void*)Cxx->shadow; } -JL_DLLEXPORT int RequireCompleteType(C,clang::Type *t) +JL_DLLEXPORT int RequireCompleteType(CxxInstance *Cxx,clang::Type *t) { clang::Sema &sema = Cxx->CI->getSema(); return sema.RequireCompleteType(getTrivialSourceLocation(Cxx),clang::QualType(t,0),0); } -JL_DLLEXPORT void *CreateTemplatedFunction(C, char *Name, clang::TemplateParameterList** args, size_t nargs) +JL_DLLEXPORT void *CreateTemplatedFunction(CxxInstance *Cxx, char *Name, clang::TemplateParameterList** args, size_t nargs) { clang::DeclSpec DS(Cxx->Parser->getAttrFactory()); clang::Declarator D(DS, clang::DeclaratorContext::PrototypeContext); @@ -2721,7 +2720,7 @@ JL_DLLEXPORT void *CreateTemplatedFunction(C, char *Name, clang::TemplateParamet return sema.ActOnTemplateDeclarator(nullptr,clang::MultiTemplateParamsArg(args,nargs),D); } -JL_DLLEXPORT void *ActOnTypeParameter(C, char *Name, unsigned Position) +JL_DLLEXPORT void *ActOnTypeParameter(CxxInstance *Cxx, char *Name, unsigned Position) { clang::Sema &sema = Cxx->CI->getSema(); clang::ParsedType DefaultArg; @@ -2734,7 +2733,7 @@ JL_DLLEXPORT void *ActOnTypeParameter(C, char *Name, unsigned Position) return ret; } -JL_DLLEXPORT void *CreateAnonymousClass(C, clang::Decl *Scope) +JL_DLLEXPORT void *CreateAnonymousClass(CxxInstance *Cxx, clang::Decl *Scope) { clang::CXXRecordDecl *RD = clang::CXXRecordDecl::Create( Cxx->CI->getASTContext(), clang::TTK_Class, @@ -2752,7 +2751,7 @@ JL_DLLEXPORT void *AddCallOpToClass(clang::CXXRecordDecl *TheClass, clang::CXXMe return Method; } -JL_DLLEXPORT void FinalizeAnonClass(C, clang::CXXRecordDecl *TheClass) +JL_DLLEXPORT void FinalizeAnonClass(CxxInstance *Cxx, clang::CXXRecordDecl *TheClass) { llvm::SmallVector Fields; Cxx->CI->getSema().ActOnFields(nullptr, clang::SourceLocation(), TheClass, @@ -2761,12 +2760,12 @@ JL_DLLEXPORT void FinalizeAnonClass(C, clang::CXXRecordDecl *TheClass) } -JL_DLLEXPORT void EnterParserScope(C) +JL_DLLEXPORT void EnterParserScope(CxxInstance *Cxx) { Cxx->Parser->EnterScope(clang::Scope::TemplateParamScope); } -JL_DLLEXPORT void *ActOnTypeParameterParserScope(C, char *Name, unsigned Position) +JL_DLLEXPORT void *ActOnTypeParameterParserScope(CxxInstance *Cxx, char *Name, unsigned Position) { clang::Sema &sema = Cxx->CI->getSema(); clang::ParsedType DefaultArg; @@ -2778,12 +2777,12 @@ JL_DLLEXPORT void *ActOnTypeParameterParserScope(C, char *Name, unsigned Positio return ret; } -JL_DLLEXPORT void ExitParserScope(C) +JL_DLLEXPORT void ExitParserScope(CxxInstance *Cxx) { Cxx->Parser->ExitScope(); } -JL_DLLEXPORT void *CreateTemplateParameterList(C, clang::NamedDecl **D, size_t ND) +JL_DLLEXPORT void *CreateTemplateParameterList(CxxInstance *Cxx, clang::NamedDecl **D, size_t ND) { #ifdef LLVM38 return (void*)clang::TemplateParameterList::Create(Cxx->CI->getASTContext(), clang::SourceLocation(), @@ -2797,7 +2796,7 @@ JL_DLLEXPORT void *CreateTemplateParameterList(C, clang::NamedDecl **D, size_t N #endif } -JL_DLLEXPORT void *CreateFunctionTemplateDecl(C, clang::DeclContext *DC, clang::TemplateParameterList *Params, clang::FunctionDecl *FD) +JL_DLLEXPORT void *CreateFunctionTemplateDecl(CxxInstance *Cxx, clang::DeclContext *DC, clang::TemplateParameterList *Params, clang::FunctionDecl *FD) { clang::FunctionTemplateDecl *FTD = clang::FunctionTemplateDecl::Create( Cxx->CI->getASTContext(), DC, clang::SourceLocation(), @@ -2825,7 +2824,7 @@ JL_DLLEXPORT void getSpecializations(clang::FunctionTemplateDecl *FTD, std::vect specs->push_back(it); } -JL_DLLEXPORT const char *getMangledFunctionName(C,clang::FunctionDecl *D) +JL_DLLEXPORT const char *getMangledFunctionName(CxxInstance *Cxx,clang::FunctionDecl *D) { return Cxx->CGM->getMangledName(clang::GlobalDecl(D)).data(); } @@ -2840,7 +2839,7 @@ JL_DLLEXPORT void *getLambdaCallOperator(clang::CXXRecordDecl *R) return R->getLambdaCallOperator(); } -JL_DLLEXPORT void *getCallOperator(C, clang::CXXRecordDecl *R) +JL_DLLEXPORT void *getCallOperator(CxxInstance *Cxx, clang::CXXRecordDecl *R) { clang::DeclarationName Name = Cxx->CI->getASTContext().DeclarationNames.getCXXOperatorName(clang::OO_Call); @@ -2898,31 +2897,31 @@ CreateFunctionRefExpr(clang::Sema &S, clang::FunctionDecl *Fn, clang::NamedDecl return E; } -JL_DLLEXPORT void *CreateCStyleCast(C, clang::Expr *E, clang::Type *T) +JL_DLLEXPORT void *CreateCStyleCast(CxxInstance *Cxx, clang::Expr *E, clang::Type *T) { clang::QualType QT(T,0); return (void*)clang::CStyleCastExpr::Create (Cxx->CI->getASTContext(), QT, clang::VK_RValue, clang::CK_BitCast, E, nullptr, Cxx->CI->getASTContext().getTrivialTypeSourceInfo(QT), clang::SourceLocation(), clang::SourceLocation()); } -JL_DLLEXPORT void *CreateReturnStmt(C, clang::Expr *E) +JL_DLLEXPORT void *CreateReturnStmt(CxxInstance *Cxx, clang::Expr *E) { return (void*)new (Cxx->CI->getASTContext()) clang::ReturnStmt(clang::SourceLocation(),E,nullptr); } -JL_DLLEXPORT void *CreateThisExpr(C, void *T) +JL_DLLEXPORT void *CreateThisExpr(CxxInstance *Cxx, void *T) { return (void*)new (Cxx->CI->getASTContext()) clang::CXXThisExpr( clang::SourceLocation(), clang::QualType::getFromOpaquePtr(T), false); } -JL_DLLEXPORT void *CreateFunctionRefExprFD(C, clang::FunctionDecl *FD) +JL_DLLEXPORT void *CreateFunctionRefExprFD(CxxInstance *Cxx, clang::FunctionDecl *FD) { return (void*)CreateFunctionRefExpr(Cxx->CI->getSema(),FD,FD,false).get(); } -JL_DLLEXPORT void *CreateFunctionRefExprFDTemplate(C, clang::FunctionTemplateDecl *FTD) +JL_DLLEXPORT void *CreateFunctionRefExprFDTemplate(CxxInstance *Cxx, clang::FunctionTemplateDecl *FTD) { return (void*)CreateFunctionRefExpr(Cxx->CI->getSema(),FTD->getTemplatedDecl(),FTD,false).get(); } @@ -2933,12 +2932,12 @@ JL_DLLEXPORT void SetFDBody(clang::FunctionDecl *FD, clang::Stmt *body) FD->setBody(body); } -JL_DLLEXPORT void ActOnFinishFunctionBody(C,clang::FunctionDecl *FD, clang::Stmt *Body) +JL_DLLEXPORT void ActOnFinishFunctionBody(CxxInstance *Cxx,clang::FunctionDecl *FD, clang::Stmt *Body) { Cxx->CI->getSema().ActOnFinishFunctionBody(FD,Body,true); } -JL_DLLEXPORT void *CreateLinkageSpec(C, clang::DeclContext *DC, unsigned kind) +JL_DLLEXPORT void *CreateLinkageSpec(CxxInstance *Cxx, clang::DeclContext *DC, unsigned kind) { return (void *)(clang::DeclContext *)clang::LinkageSpecDecl::Create(Cxx->CI->getASTContext(), DC, clang::SourceLocation(), clang::SourceLocation(), (clang::LinkageSpecDecl::LanguageIDs) kind, @@ -2960,7 +2959,7 @@ JL_DLLEXPORT void *getParmVarDecl(clang::FunctionDecl *FD, unsigned i) return (void *)FD->getParamDecl(i); } -JL_DLLEXPORT void SetDeclUsed(C,clang::Decl *D) +JL_DLLEXPORT void SetDeclUsed(CxxInstance *Cxx,clang::Decl *D) { D->markUsed(Cxx->CI->getASTContext()); } @@ -2975,7 +2974,7 @@ JL_DLLEXPORT void *getPointerElementType(llvm::Type *T) return (void*)T->getPointerElementType (); } -JL_DLLEXPORT void emitDestroyCXXObject(C, llvm::Value *x, clang::Type *T) +JL_DLLEXPORT void emitDestroyCXXObject(CxxInstance *Cxx, llvm::Value *x, clang::Type *T) { clang::CXXRecordDecl *RD = T->getAsCXXRecordDecl(); clang::CXXDestructorDecl *Destructor = Cxx->CI->getSema().LookupDestructor(RD); @@ -2991,7 +2990,7 @@ JL_DLLEXPORT void emitDestroyCXXObject(C, llvm::Value *x, clang::Type *T) clang::QualType(T,0)); } -JL_DLLEXPORT bool hasTrivialDestructor(C, clang::CXXRecordDecl *RD) +JL_DLLEXPORT bool hasTrivialDestructor(CxxInstance *Cxx, clang::CXXRecordDecl *RD) { clang::CXXScopeSpec spec; spec.setBeginLoc(getTrivialSourceLocation(Cxx)); @@ -3005,7 +3004,7 @@ JL_DLLEXPORT void setPersonality(llvm::Function *F, llvm::Function *PersonalityF F->setPersonalityFn(PersonalityF); } -JL_DLLEXPORT void *getFunction(C, char *name, size_t length) +JL_DLLEXPORT void *getFunction(CxxInstance *Cxx, char *name, size_t length) { return Cxx->shadow->getFunction(llvm::StringRef(name,length)); } @@ -3020,7 +3019,7 @@ JL_DLLEXPORT void *getUnderlyingTemplateDecl(clang::TemplateSpecializationType * return (void*)TST->getTemplateName().getAsTemplateDecl(); } -JL_DLLEXPORT void *getOrCreateTemplateSpecialization(C, clang::FunctionTemplateDecl *FTD, void **T, size_t nargs) +JL_DLLEXPORT void *getOrCreateTemplateSpecialization(CxxInstance *Cxx, clang::FunctionTemplateDecl *FTD, void **T, size_t nargs) { clang::TemplateArgumentListInfo TALI; clang::sema::TemplateDeductionInfo Info(clang::SourceLocation{}); @@ -3036,7 +3035,7 @@ JL_DLLEXPORT void *getOrCreateTemplateSpecialization(C, clang::FunctionTemplateD return FD; } -JL_DLLEXPORT void *CreateIntegerLiteral(C, uint64_t val, void *T) +JL_DLLEXPORT void *CreateIntegerLiteral(CxxInstance *Cxx, uint64_t val, void *T) { clang::QualType QT = clang::QualType::getFromOpaquePtr(T); return (void*)clang::IntegerLiteral::Create(Cxx->CI->getASTContext(), @@ -3078,7 +3077,7 @@ JL_DLLEXPORT void SetConstexpr(clang::VarDecl *VD) VD->setConstexpr(true); } -JL_DLLEXPORT void InsertIntoShadowModule(C, llvm::Function *F) +JL_DLLEXPORT void InsertIntoShadowModule(CxxInstance *Cxx, llvm::Function *F) { // Copy the declaration characteristics of the Function (not the body) Function *NewF = Function::Create(F->getFunctionType(), @@ -3102,7 +3101,7 @@ JL_DLLEXPORT void InsertIntoShadowModule(C, llvm::Function *F) } extern void *jl_pchar_to_string(const char *str, size_t len); -JL_DLLEXPORT void *getTypeName(C, void *Ty) +JL_DLLEXPORT void *getTypeName(CxxInstance *Cxx, void *Ty) { SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); @@ -3167,7 +3166,7 @@ struct CodeGenTypes_CGRecordLayouts { typedef CGRMap (clang::CodeGen::CodeGenTyp template class stow_private; template class stow_private; -void RegisterType(C, clang::TagDecl *D, llvm::StructType *ST) +void RegisterType(CxxInstance *Cxx, clang::TagDecl *D, llvm::StructType *ST) { clang::RecordDecl *RD; if(isa(D)) From a408afdc05d193ef2ecfc7482ea9b2cbd5613383 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Sat, 6 Jul 2019 13:14:26 +0800 Subject: [PATCH 8/8] Disable signal handling on Windows temporarily It looks like these code are not being used anywhere and I don't know how to port this to Windows. --- src/bootstrap.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index 574e24fa..5e853271 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -3187,6 +3187,9 @@ JL_DLLEXPORT bool isDCComplete(clang::DeclContext *DC) { return (!clang::isa(DC) || DC->isDependentContext() || clang::cast(DC)->isCompleteDefinition() || clang::cast(DC)->isBeingDefined()); } +} // extern "C" + +#ifndef _OS_WINDOWS_ #include static void jl_unblock_signal(int sig) { @@ -3219,6 +3222,5 @@ JL_DLLEXPORT void InstallSIGABRTHandler(void *exception) abort(); // hah } } -} - -} +} // extern "C" +#endif // _OS_WINDOWS_