[llvm-branch-commits] [llvm-branch] r244654 - Merging r243891 and r244644:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 11 13:07:52 PDT 2015
Author: hans
Date: Tue Aug 11 15:07:52 2015
New Revision: 244654
URL: http://llvm.org/viewvc/llvm-project?rev=244654&view=rev
Log:
Merging r243891 and r244644:
------------------------------------------------------------------------
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
------------------------------------------------------------------------
Modified:
llvm/branches/release_37/ (props changed)
llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
Propchange: llvm/branches/release_37/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 11 15:07:52 2015
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,242236,242239,242281,242288,242296,242331,242341,242410,242412,242433-242434,242442,242543,242673,242680,242706,242721-242722,242733-242735,242742,242869,242919,242993,243001,243057,243116,243263,243294,243361,243469,243485,243500,243519,243531,243589,243609,243636,243638-243640,243745,243898,243927,243932,243934,243984,243986,244058,244123,244418,244554
+/llvm/trunk:155241,242236,242239,242281,242288,242296,242331,242341,242410,242412,242433-242434,242442,242543,242673,242680,242706,242721-242722,242733-242735,242742,242869,242919,242993,243001,243057,243116,243263,243294,243361,243469,243485,243500,243519,243531,243589,243609,243636,243638-243640,243745,243891,243898,243927,243932,243934,243984,243986,244058,244123,244418,244554,244644
Modified: llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp?rev=244654&r1=244653&r2=244654&view=diff
==============================================================================
--- llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp (original)
+++ llvm/branches/release_37/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp Tue Aug 11 15:07:52 2015
@@ -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) {
@@ -389,14 +386,11 @@ TEST_F(MCJITCAPITest, custom_memory_mana
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);
}
@@ -412,14 +406,11 @@ TEST_F(MCJITCAPITest, stackmap_creates_c
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
@@ -446,21 +437,15 @@ TEST_F(MCJITCAPITest, reserve_allocation
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);
@@ -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);
}
@@ -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();
More information about the llvm-branch-commits
mailing list