Index: include/llvm-c/ExecutionEngine.h =================================================================== --- include/llvm-c/ExecutionEngine.h +++ include/llvm-c/ExecutionEngine.h @@ -64,7 +64,7 @@ unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, LLVMBool IsSigned); -void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); +const void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal); @@ -144,7 +144,8 @@ void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, void* Addr); -void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); +const void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, + LLVMValueRef Global); uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name); Index: include/llvm-c/Support.h =================================================================== --- include/llvm-c/Support.h +++ include/llvm-c/Support.h @@ -47,7 +47,7 @@ * * @see sys::DynamicLibrary::SearchForAddressOfSymbol() */ -void *LLVMSearchForAddressOfSymbol(const char *symbolName); +const void *LLVMSearchForAddressOfSymbol(const char *symbolName); /** * This functions permanently adds the symbol \p symbolName with the Index: include/llvm/ExecutionEngine/ExecutionEngine.h =================================================================== --- include/llvm/ExecutionEngine/ExecutionEngine.h +++ include/llvm/ExecutionEngine/ExecutionEngine.h @@ -89,7 +89,7 @@ uint64_t RemoveMapping(StringRef Name); }; -using FunctionCreator = std::function; +using FunctionCreator = std::function; /// \brief Abstract interface for implementation execution of LLVM modules, /// designed to support both interpreter and just-in-time (JIT) compiler @@ -237,8 +237,8 @@ /// it prints a message to stderr and aborts. /// /// This function is deprecated for the MCJIT execution engine. - virtual void *getPointerToNamedFunction(StringRef Name, - bool AbortOnFailure = true) = 0; + virtual const void *getPointerToNamedFunction(StringRef Name, + bool AbortOnFailure = true) = 0; /// mapSectionAddress - map a section to its target address space value. /// Map the address of a JIT section as returned from the memory manager @@ -303,7 +303,7 @@ /// existing data in memory. Values to be mapped should be named, and have /// external or weak linkage. Mappings are automatically removed when their /// GlobalValue is destroyed. - void addGlobalMapping(const GlobalValue *GV, void *Addr); + void addGlobalMapping(const GlobalValue *GV, const void *Addr); void addGlobalMapping(StringRef Name, uint64_t Addr); /// clearAllGlobalMappings - Clear all global mappings and start over again, @@ -318,7 +318,7 @@ /// address. This updates both maps as required. If "Addr" is null, the /// entry for the global is removed from the mappings. This returns the old /// value of the pointer, or null if it was not in the map. - uint64_t updateGlobalMapping(const GlobalValue *GV, void *Addr); + uint64_t updateGlobalMapping(const GlobalValue *GV, const void *Addr); uint64_t updateGlobalMapping(StringRef Name, uint64_t Addr); /// getAddressToGlobalIfAvailable - This returns the address of the specified @@ -328,15 +328,15 @@ /// getPointerToGlobalIfAvailable - This returns the address of the specified /// global value if it is has already been codegen'd, otherwise it returns /// null. - void *getPointerToGlobalIfAvailable(StringRef S); - void *getPointerToGlobalIfAvailable(const GlobalValue *GV); + const void *getPointerToGlobalIfAvailable(StringRef S); + const void *getPointerToGlobalIfAvailable(const GlobalValue *GV); /// getPointerToGlobal - This returns the address of the specified global /// value. This may involve code generation if it's a function. /// /// This function is deprecated for the MCJIT execution engine. Use /// getGlobalValueAddress instead. - void *getPointerToGlobal(const GlobalValue *GV); + const void *getPointerToGlobal(const GlobalValue *GV); /// getPointerToFunction - The different EE's represent function bodies in /// different ways. They should each implement this to say what a function @@ -346,7 +346,7 @@ /// /// This function is deprecated for the MCJIT execution engine. Use /// getFunctionAddress instead. - virtual void *getPointerToFunction(Function *F) = 0; + virtual const void *getPointerToFunction(Function *F) = 0; /// getPointerToFunctionOrStub - If the specified function has been /// code-gen'd, return a pointer to the function. If not, compile it, or use @@ -355,7 +355,7 @@ /// /// This function is deprecated for the MCJIT execution engine. Use /// getFunctionAddress instead. - virtual void *getPointerToFunctionOrStub(Function *F) { + virtual const void *getPointerToFunctionOrStub(Function *F) { // Default implementation, just codegen the function. return getPointerToFunction(F); } @@ -398,7 +398,7 @@ /// /// This function is deprecated for the MCJIT execution engine. Use /// getGlobalValueAddress instead. - virtual void *getOrEmitGlobalVariable(const GlobalVariable *GV) { + virtual const void *getOrEmitGlobalVariable(const GlobalVariable *GV) { return getPointerToGlobal((const GlobalValue *)GV); } Index: include/llvm/ExecutionEngine/GenericValue.h =================================================================== --- include/llvm/ExecutionEngine/GenericValue.h +++ include/llvm/ExecutionEngine/GenericValue.h @@ -21,7 +21,7 @@ namespace llvm { -typedef void* PointerTy; +typedef const void* PointerTy; class APInt; struct GenericValue { @@ -44,11 +44,11 @@ // potentially can cause problems, since GenericValue to store garbage // instead of zero. GenericValue() : IntVal(1,0) {UIntPairVal.first = 0; UIntPairVal.second = 0;} - explicit GenericValue(void *V) : PointerVal(V), IntVal(1,0) { } + explicit GenericValue(const void *V) : PointerVal(V), IntVal(1,0) { } }; -inline GenericValue PTOGV(void *P) { return GenericValue(P); } -inline void* GVTOP(const GenericValue &GV) { return GV.PointerVal; } +inline GenericValue PTOGV(const void *P) { return GenericValue(P); } +inline const void* GVTOP(const GenericValue &GV) { return GV.PointerVal; } } // End llvm namespace. #endif Index: include/llvm/Support/DynamicLibrary.h =================================================================== --- include/llvm/Support/DynamicLibrary.h +++ include/llvm/Support/DynamicLibrary.h @@ -85,10 +85,10 @@ /// as explicitly registered symbols (AddSymbol()). /// @throws std::string on error. /// @brief Search through libraries for address of a symbol - static void *SearchForAddressOfSymbol(const char *symbolName); + static const void *SearchForAddressOfSymbol(const char *symbolName); /// @brief Convenience function for C++ophiles. - static void *SearchForAddressOfSymbol(const std::string &symbolName) { + static const void *SearchForAddressOfSymbol(const std::string &symbolName) { return SearchForAddressOfSymbol(symbolName.c_str()); } Index: lib/ExecutionEngine/ExecutionEngine.cpp =================================================================== --- lib/ExecutionEngine/ExecutionEngine.cpp +++ lib/ExecutionEngine/ExecutionEngine.cpp @@ -205,7 +205,8 @@ return FullName.str(); } -void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) { +void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, + const void *Addr) { MutexGuard locked(lock); addGlobalMapping(getMangledName(GV), (uint64_t) Addr); } @@ -244,7 +245,7 @@ } uint64_t ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, - void *Addr) { + const void *Addr) { MutexGuard locked(lock); return updateGlobalMapping(getMangledName(GV), (uint64_t) Addr); } @@ -287,14 +288,15 @@ } -void *ExecutionEngine::getPointerToGlobalIfAvailable(StringRef S) { +const void *ExecutionEngine::getPointerToGlobalIfAvailable(StringRef S) { MutexGuard locked(lock); if (void* Address = (void *) getAddressToGlobalIfAvailable(S)) return Address; return nullptr; } -void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) { +const void * +ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) { MutexGuard locked(lock); return getPointerToGlobalIfAvailable(getMangledName(GV)); } @@ -415,7 +417,7 @@ #ifndef NDEBUG /// isTargetNullPtr - Return whether the target pointer stored at Loc is null. -static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) { +static bool isTargetNullPtr(ExecutionEngine *EE, const void *Loc) { unsigned PtrSize = EE->getDataLayout().getPointerSize(); for (unsigned i = 0; i < PtrSize; ++i) if (*(i + (uint8_t*)Loc)) @@ -573,12 +575,12 @@ return nullptr; } -void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) { +const void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) { if (Function *F = const_cast(dyn_cast(GV))) return getPointerToFunction(F); MutexGuard locked(lock); - if (void* P = getPointerToGlobalIfAvailable(GV)) + if (const void* P = getPointerToGlobalIfAvailable(GV)) return P; // Global variable might have been added since interpreter started. @@ -1295,7 +1297,7 @@ } else { // External variable reference. Try to use the dynamic loader to // get a pointer to it. - if (void *SymAddr = + if (const void *SymAddr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV.getName())) addGlobalMapping(&GV, SymAddr); else { @@ -1312,7 +1314,7 @@ const GlobalValue *GV = NonCanonicalGlobals[i]; const GlobalValue *CGV = LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())]; - void *Ptr = getPointerToGlobalIfAvailable(CGV); + const void *Ptr = getPointerToGlobalIfAvailable(CGV); assert(Ptr && "Canonical global wasn't codegen'd!"); addGlobalMapping(GV, Ptr); } @@ -1338,7 +1340,7 @@ // address specified in GlobalAddresses, or allocates new memory if it's not // already in the map. void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) { - void *GA = getPointerToGlobalIfAvailable(GV); + const void *GA = getPointerToGlobalIfAvailable(GV); if (!GA) { // If it's not already specified, allocate memory for the global. @@ -1352,7 +1354,7 @@ // Don't initialize if it's thread local, let the client do it. if (!GV->isThreadLocal()) - InitializeMemory(GV->getInitializer(), GA); + InitializeMemory(GV->getInitializer(), const_cast(GA)); Type *ElTy = GV->getValueType(); size_t GVSize = (size_t)getDataLayout().getTypeAllocSize(ElTy); Index: lib/ExecutionEngine/ExecutionEngineBindings.cpp =================================================================== --- lib/ExecutionEngine/ExecutionEngineBindings.cpp +++ lib/ExecutionEngine/ExecutionEngineBindings.cpp @@ -79,7 +79,7 @@ return GenVal->IntVal.getZExtValue(); } -void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal) { +const void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal) { return unwrap(GenVal)->PointerVal; } @@ -292,7 +292,8 @@ unwrap(EE)->addGlobalMapping(unwrap(Global), Addr); } -void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global) { +const void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, + LLVMValueRef Global) { unwrap(EE)->finalizeObject(); return unwrap(EE)->getPointerToGlobal(unwrap(Global)); @@ -408,4 +409,3 @@ void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM) { delete unwrap(MM); } - Index: lib/ExecutionEngine/Interpreter/Execution.cpp =================================================================== --- lib/ExecutionEngine/Interpreter/Execution.cpp +++ lib/ExecutionEngine/Interpreter/Execution.cpp @@ -912,7 +912,7 @@ void Interpreter::visitIndirectBrInst(IndirectBrInst &I) { ExecutionContext &SF = ECStack.back(); - void *Dest = GVTOP(getOperandValue(I.getAddress(), SF)); + const void *Dest = GVTOP(getOperandValue(I.getAddress(), SF)); SwitchToNewBasicBlock((BasicBlock*)Dest, SF); } Index: lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp =================================================================== --- lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -482,7 +482,7 @@ static GenericValue lle_X_memcpy(FunctionType *FT, ArrayRef Args) { - memcpy(GVTOP(Args[0]), GVTOP(Args[1]), + memcpy(const_cast(GVTOP(Args[0])), GVTOP(Args[1]), (size_t)(Args[2].IntVal.getLimitedValue())); // llvm.memcpy* returns void, lle_X_* returns GenericValue, Index: lib/ExecutionEngine/MCJIT/MCJIT.h =================================================================== --- lib/ExecutionEngine/MCJIT/MCJIT.h +++ lib/ExecutionEngine/MCJIT/MCJIT.h @@ -257,7 +257,7 @@ /// \param isDtors - Run the destructors instead of constructors. void runStaticConstructorsDestructors(bool isDtors) override; - void *getPointerToFunction(Function *F) override; + const void *getPointerToFunction(Function *F) override; GenericValue runFunction(Function *F, ArrayRef ArgValues) override; @@ -270,8 +270,8 @@ /// found, this function silently returns a null pointer. Otherwise, /// it prints a message to stderr and aborts. /// - void *getPointerToNamedFunction(StringRef Name, - bool AbortOnFailure = true) override; + const void *getPointerToNamedFunction(StringRef Name, + bool AbortOnFailure = true) override; /// mapSectionAddress - map a section to its target address space value. /// Map the address of a JIT section as returned from the memory manager Index: lib/ExecutionEngine/MCJIT/MCJIT.cpp =================================================================== --- lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -275,7 +275,7 @@ } JITSymbol MCJIT::findExistingSymbol(const std::string &Name) { - if (void *Addr = getPointerToGlobalIfAvailable(Name)) + if (const void *Addr = getPointerToGlobalIfAvailable(Name)) return JITSymbol(static_cast( reinterpret_cast(Addr)), JITSymbolFlags::Exported); @@ -394,7 +394,7 @@ } // Deprecated. Use getFunctionAddress instead. -void *MCJIT::getPointerToFunction(Function *F) { +const void *MCJIT::getPointerToFunction(Function *F) { MutexGuard locked(lock); Mangler Mang; @@ -403,7 +403,7 @@ if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) { bool AbortOnFailure = !F->hasExternalWeakLinkage(); - void *Addr = getPointerToNamedFunction(Name, AbortOnFailure); + const void *Addr = getPointerToNamedFunction(Name, AbortOnFailure); updateGlobalMapping(F, Addr); return Addr; } @@ -497,7 +497,7 @@ GenericValue MCJIT::runFunction(Function *F, ArrayRef ArgValues) { assert(F && "Function *F was null at entry to run()"); - void *FPtr = getPointerToFunction(F); + const void *FPtr = getPointerToFunction(F); finalizeModule(F->getParent()); assert(FPtr && "Pointer to fn's code was null after getPointerToFunction"); FunctionType *FTy = F->getFunctionType(); @@ -597,7 +597,8 @@ "to the desired function pointer type."); } -void *MCJIT::getPointerToNamedFunction(StringRef Name, bool AbortOnFailure) { +const void *MCJIT::getPointerToNamedFunction(StringRef Name, + bool AbortOnFailure) { if (!isSymbolSearchingDisabled()) { void *ptr = reinterpret_cast( @@ -608,7 +609,7 @@ /// If a LazyFunctionCreator is installed, use it to get/create the function. if (LazyFunctionCreator) - if (void *RP = LazyFunctionCreator(Name)) + if (const void *RP = LazyFunctionCreator(Name)) return RP; if (AbortOnFailure) { Index: lib/Support/DynamicLibrary.cpp =================================================================== --- lib/Support/DynamicLibrary.cpp +++ lib/Support/DynamicLibrary.cpp @@ -108,7 +108,7 @@ void *SearchForAddressOfSpecialSymbol(const char* symbolName); } -void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) { +const void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) { SmartScopedLock Lock(*SymbolsMutex); // First check symbols added via AddSymbol(). @@ -179,11 +179,10 @@ return llvm::sys::DynamicLibrary::LoadLibraryPermanently(Filename); } -void *LLVMSearchForAddressOfSymbol(const char *symbolName) { +const void *LLVMSearchForAddressOfSymbol(const char *symbolName) { return llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(symbolName); } void LLVMAddSymbol(const char *symbolName, void *symbolValue) { return llvm::sys::DynamicLibrary::AddSymbol(symbolName, symbolValue); } - Index: unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp =================================================================== --- unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp @@ -95,7 +95,7 @@ // We may be using a null cache, so ensure compilation is valid. TheJIT->finalizeObject(); - void *vPtr = TheJIT->getPointerToFunction(Main); + const void *vPtr = TheJIT->getPointerToFunction(Main); EXPECT_TRUE(nullptr != vPtr) << "Unable to get pointer to main() from JIT"; Index: unittests/ExecutionEngine/MCJIT/MCJITTest.cpp =================================================================== --- unittests/ExecutionEngine/MCJIT/MCJITTest.cpp +++ unittests/ExecutionEngine/MCJIT/MCJITTest.cpp @@ -51,7 +51,7 @@ int initialValue = 5; GlobalValue *Global = insertGlobalInt32(M.get(), "test_global", initialValue); createJIT(std::move(M)); - void *globalPtr = TheJIT->getPointerToGlobal(Global); + const void *globalPtr = TheJIT->getPointerToGlobal(Global); EXPECT_TRUE(nullptr != globalPtr) << "Unable to get pointer to global value from JIT"; @@ -193,14 +193,14 @@ Function *Foo = insertExternalReferenceToFunction(M.get(), "_exit"); createJIT(std::move(M)); - void *A = TheJIT->getPointerToFunction(Foo); - void *B = TheJIT->getPointerToFunction(Foo); + const void *A = TheJIT->getPointerToFunction(Foo); + const void *B = TheJIT->getPointerToFunction(Foo); EXPECT_TRUE(A != nullptr) << "Failed lookup - test not correctly configured."; EXPECT_EQ(A, B) << "Repeat calls to getPointerToFunction fail."; } -typedef void * (*FunctionHandlerPtr)(const std::string &str); +typedef const void * (*FunctionHandlerPtr)(const std::string &str); TEST_F(MCJITTest, lazy_function_creator_pointer) { SKIP_UNSUPPORTED_PLATFORM; @@ -221,14 +221,14 @@ // Try to resolve the function in the current process before marking it as // unresolved. This solves an issue on ARM where '__aeabi_*' function names // are passed to this handler. - void *symbol = + const void *symbol = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(str.c_str()); if (symbol) { return symbol; } UnresolvedExternal = str; - return (void *)(uintptr_t)-1; + return (const void *)(uintptr_t)-1; }; TheJIT->InstallLazyFunctionCreator(UnresolvedHandler); @@ -261,13 +261,13 @@ // Try to resolve the function in the current process before marking it as // unresolved. This solves an issue on ARM where '__aeabi_*' function names // are passed to this handler. - void *symbol = + const void *symbol = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(str.c_str()); if (symbol) { return symbol; } UnresolvedExternals.push_back(str); - return (void *)(uintptr_t)-1; + return (const void *)(uintptr_t)-1; }; TheJIT->InstallLazyFunctionCreator(UnresolvedHandler);