buildMCJITOptions();
buildMCJITEngine();
buildAndRunPasses();
-
- union {
- void *raw;
- int (*usable)();
- } functionPointer;
- functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
-
- EXPECT_EQ(42, functionPointer.usable());
+
+ auto *functionPointer = reinterpret_cast<int (*)()>(
+ reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(Engine, Function)));
+
+ EXPECT_EQ(42, functionPointer());
}
TEST_F(MCJITCAPITest, gva) {
useRoundTripSectionMemoryManager();
buildMCJITEngine();
buildAndRunPasses();
-
- union {
- void *raw;
- int (*usable)();
- } functionPointer;
- functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
-
- EXPECT_EQ(42, functionPointer.usable());
+
+ auto *functionPointer = reinterpret_cast<int (*)()>(
+ reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(Engine, Function)));
+
+ EXPECT_EQ(42, functionPointer());
EXPECT_TRUE(didCallAllocateCodeSection);
}
useRoundTripSectionMemoryManager();
buildMCJITEngine();
buildAndRunOptPasses();
-
- union {
- void *raw;
- int (*usable)();
- } functionPointer;
- functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
-
- EXPECT_EQ(42, functionPointer.usable());
+
+ auto *functionPointer = reinterpret_cast<int (*)()>(
+ reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(Engine, Function)));
+
+ EXPECT_EQ(42, functionPointer());
EXPECT_TRUE(didCallAllocateCodeSection);
// Up to this point, the test is specific only to X86-64. But this next
Options.MCJMM = wrap(MM);
buildMCJITEngine();
buildAndRunPasses();
-
- union {
- void *raw;
- int (*usable)();
- } GetGlobalFct;
- GetGlobalFct.raw = LLVMGetPointerToGlobal(Engine, Function);
-
- union {
- void *raw;
- void (*usable)(int);
- } SetGlobalFct;
- SetGlobalFct.raw = LLVMGetPointerToGlobal(Engine, Function2);
-
- SetGlobalFct.usable(789);
- EXPECT_EQ(789, GetGlobalFct.usable());
+
+ auto GetGlobalFct = reinterpret_cast<int (*)()>(
+ reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(Engine, Function)));
+
+ auto SetGlobalFct = reinterpret_cast<void (*)(int)>(
+ reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(Engine, Function2)));
+
+ SetGlobalFct(789);
+ EXPECT_EQ(789, GetGlobalFct());
EXPECT_LE(MM->UsedCodeSize, MM->ReservedCodeSize);
EXPECT_LE(MM->UsedDataSizeRO, MM->ReservedDataSizeRO);
EXPECT_LE(MM->UsedDataSizeRW, MM->ReservedDataSizeRW);
LLVMContextSetYieldCallback(C, yield, nullptr);
buildAndRunPasses();
- union {
- void *raw;
- int (*usable)();
- } functionPointer;
- functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
+ auto *functionPointer = reinterpret_cast<int (*)()>(
+ reinterpret_cast<uintptr_t>(LLVMGetPointerToGlobal(Engine, Function)));
- EXPECT_EQ(42, functionPointer.usable());
+ EXPECT_EQ(42, functionPointer());
EXPECT_TRUE(didCallYield);
}
buildMCJITOptions();
buildMCJITEngine();
- union {
- int (*raw)();
- void *usable;
- } functionPointer;
- functionPointer.raw = &localTestFunc;
-
- LLVMAddGlobalMapping(Engine, MappedFn, functionPointer.usable);
+ LLVMAddGlobalMapping(
+ Engine, MappedFn,
+ reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(&localTestFunc)));
buildAndRunPasses();