llvm.org GIT mirror llvm / d9bcf42
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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@244654 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 5 years ago
1 changed file(s) with 31 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
338338 buildMCJITOptions();
339339 buildMCJITEngine();
340340 buildAndRunPasses();
341
342 union {
343 void *raw;
344 int (*usable)();
345 } functionPointer;
346 functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
347
348 EXPECT_EQ(42, functionPointer.usable());
341
342 auto *functionPointer = reinterpret_cast(
343 reinterpret_cast(LLVMGetPointerToGlobal(Engine, Function)));
344
345 EXPECT_EQ(42, functionPointer());
349346 }
350347
351348 TEST_F(MCJITCAPITest, gva) {
388385 useRoundTripSectionMemoryManager();
389386 buildMCJITEngine();
390387 buildAndRunPasses();
391
392 union {
393 void *raw;
394 int (*usable)();
395 } functionPointer;
396 functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
397
398 EXPECT_EQ(42, functionPointer.usable());
388
389 auto *functionPointer = reinterpret_cast(
390 reinterpret_cast(LLVMGetPointerToGlobal(Engine, Function)));
391
392 EXPECT_EQ(42, functionPointer());
399393 EXPECT_TRUE(didCallAllocateCodeSection);
400394 }
401395
411405 useRoundTripSectionMemoryManager();
412406 buildMCJITEngine();
413407 buildAndRunOptPasses();
414
415 union {
416 void *raw;
417 int (*usable)();
418 } functionPointer;
419 functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
420
421 EXPECT_EQ(42, functionPointer.usable());
408
409 auto *functionPointer = reinterpret_cast(
410 reinterpret_cast(LLVMGetPointerToGlobal(Engine, Function)));
411
412 EXPECT_EQ(42, functionPointer());
422413 EXPECT_TRUE(didCallAllocateCodeSection);
423414
424415 // Up to this point, the test is specific only to X86-64. But this next
445436 Options.MCJMM = wrap(MM);
446437 buildMCJITEngine();
447438 buildAndRunPasses();
448
449 union {
450 void *raw;
451 int (*usable)();
452 } GetGlobalFct;
453 GetGlobalFct.raw = LLVMGetPointerToGlobal(Engine, Function);
454
455 union {
456 void *raw;
457 void (*usable)(int);
458 } SetGlobalFct;
459 SetGlobalFct.raw = LLVMGetPointerToGlobal(Engine, Function2);
460
461 SetGlobalFct.usable(789);
462 EXPECT_EQ(789, GetGlobalFct.usable());
439
440 auto GetGlobalFct = reinterpret_cast(
441 reinterpret_cast(LLVMGetPointerToGlobal(Engine, Function)));
442
443 auto SetGlobalFct = reinterpret_cast(
444 reinterpret_cast(LLVMGetPointerToGlobal(Engine, Function2)));
445
446 SetGlobalFct(789);
447 EXPECT_EQ(789, GetGlobalFct());
463448 EXPECT_LE(MM->UsedCodeSize, MM->ReservedCodeSize);
464449 EXPECT_LE(MM->UsedDataSizeRO, MM->ReservedDataSizeRO);
465450 EXPECT_LE(MM->UsedDataSizeRW, MM->ReservedDataSizeRW);
477462 LLVMContextSetYieldCallback(C, yield, nullptr);
478463 buildAndRunPasses();
479464
480 union {
481 void *raw;
482 int (*usable)();
483 } functionPointer;
484 functionPointer.raw = LLVMGetPointerToGlobal(Engine, Function);
485
486 EXPECT_EQ(42, functionPointer.usable());
465 auto *functionPointer = reinterpret_cast(
466 reinterpret_cast(LLVMGetPointerToGlobal(Engine, Function)));
467
468 EXPECT_EQ(42, functionPointer());
487469 EXPECT_TRUE(didCallYield);
488470 }
489471
513495 buildMCJITOptions();
514496 buildMCJITEngine();
515497
516 LLVMAddGlobalMapping(Engine, MappedFn, reinterpret_cast(&localTestFunc));
498 LLVMAddGlobalMapping(
499 Engine, MappedFn,
500 reinterpret_cast(reinterpret_cast(&localTestFunc)));
517501
518502 buildAndRunPasses();
519503