Skip to content

Commit

Permalink
Merging r243891 and r244644:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r243891 | lhames | 2015-08-03 11:03:40 -0700 (Mon, 03 Aug 2015) | 4 lines

[MCJIT] Fix a cast warning in the unit-test introduced in r243589.

Thanks to Aaron Ballman for spotting this.
------------------------------------------------------------------------

------------------------------------------------------------------------
r244644 | dblaikie | 2015-08-11 11:17:45 -0700 (Tue, 11 Aug 2015) | 5 lines

Fix UB in MCJIT test cases that relied on union type punning

Reviewers: lhames, aaron.ballman

Differential Revision: http://reviews.llvm.org/D11779
------------------------------------------------------------------------

llvm-svn: 244654
  • Loading branch information
zmodem committed Aug 11, 2015
1 parent cef0bc1 commit 0a48915
Showing 1 changed file with 30 additions and 46 deletions.
76 changes: 30 additions & 46 deletions llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
Expand Up @@ -339,14 +339,11 @@ TEST_F(MCJITCAPITest, simple_function) {
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) {
Expand Down Expand Up @@ -389,14 +386,11 @@ TEST_F(MCJITCAPITest, custom_memory_manager) {
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);
}

Expand All @@ -412,14 +406,11 @@ TEST_F(MCJITCAPITest, stackmap_creates_compact_unwind_on_darwin) {
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
Expand All @@ -446,21 +437,15 @@ TEST_F(MCJITCAPITest, reserve_allocation_space) {
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);
Expand All @@ -478,13 +463,10 @@ TEST_F(MCJITCAPITest, yield) {
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);
}

Expand Down Expand Up @@ -514,7 +496,9 @@ TEST_F(MCJITCAPITest, addGlobalMapping) {
buildMCJITOptions();
buildMCJITEngine();

LLVMAddGlobalMapping(Engine, MappedFn, reinterpret_cast<void*>(&localTestFunc));
LLVMAddGlobalMapping(
Engine, MappedFn,
reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(&localTestFunc)));

buildAndRunPasses();

Expand Down

0 comments on commit 0a48915

Please sign in to comment.