@@ -475,106 +475,5 @@ TEST(ConstantsTest, BitcastToGEP) {
475
475
ASSERT_EQ (cast<ConstantExpr>(C)->getOpcode (), Instruction::BitCast);
476
476
}
477
477
478
- bool foldFuncPtrAndConstToNull (LLVMContext &Context, Module *TheModule,
479
- uint64_t AndValue, unsigned FunctionAlign = 0 ) {
480
- Type *VoidType (Type::getVoidTy (Context));
481
- FunctionType *FuncType (FunctionType::get (VoidType, false ));
482
- Function *Func (Function::Create (
483
- FuncType, GlobalValue::ExternalLinkage, " " , TheModule));
484
-
485
- if (FunctionAlign) Func->setAlignment (FunctionAlign);
486
-
487
- IntegerType *ConstantIntType (Type::getInt32Ty (Context));
488
- ConstantInt *TheConstant (ConstantInt::get (ConstantIntType, AndValue));
489
-
490
- Constant *TheConstantExpr (
491
- ConstantExpr::getPtrToInt (Func, ConstantIntType));
492
-
493
- return ConstantExpr::get (Instruction::And, TheConstantExpr,
494
- TheConstant)->isNullValue ();
495
- }
496
-
497
- TEST (ConstantsTest, FoldFunctionPtrAlignUnknownAnd2) {
498
- LLVMContext Context;
499
- Module TheModule (" TestModule" , Context);
500
- // When the DataLayout doesn't specify a function pointer alignment we
501
- // assume in this case that it is 4 byte aligned. This is a bug but we can't
502
- // fix it directly because it causes a code size regression on X86.
503
- // FIXME: This test should be changed once existing targets have
504
- // appropriate defaults. See associated FIXME in ConstantFoldBinaryInstruction
505
- ASSERT_TRUE (foldFuncPtrAndConstToNull (Context, &TheModule, 2 ));
506
- }
507
-
508
- TEST (ConstantsTest, DontFoldFunctionPtrAlignUnknownAnd4) {
509
- LLVMContext Context;
510
- Module TheModule (" TestModule" , Context);
511
- ASSERT_FALSE (foldFuncPtrAndConstToNull (Context, &TheModule, 4 ));
512
- }
513
-
514
- TEST (ConstantsTest, FoldFunctionPtrAlign4) {
515
- LLVMContext Context;
516
- Module TheModule (" TestModule" , Context);
517
- const char * AlignmentStrings[] = { " Fi32" , " Fn32" };
518
-
519
- for (unsigned AndValue = 1 ; AndValue <= 2 ; ++AndValue) {
520
- for (const char *AlignmentString : AlignmentStrings) {
521
- TheModule.setDataLayout (AlignmentString);
522
- ASSERT_TRUE (foldFuncPtrAndConstToNull (Context, &TheModule, AndValue));
523
- }
524
- }
525
- }
526
-
527
- TEST (ConstantsTest, DontFoldFunctionPtrAlign1) {
528
- LLVMContext Context;
529
- Module TheModule (" TestModule" , Context);
530
- const char * AlignmentStrings[] = { " Fi8" , " Fn8" };
531
-
532
- for (const char * AlignmentString : AlignmentStrings) {
533
- TheModule.setDataLayout (AlignmentString);
534
- ASSERT_FALSE (foldFuncPtrAndConstToNull (Context, &TheModule, 2 ));
535
- }
536
- }
537
-
538
- TEST (ConstantsTest, FoldFunctionAlign4PtrAlignMultiple) {
539
- LLVMContext Context;
540
- Module TheModule (" TestModule" , Context);
541
- TheModule.setDataLayout (" Fn8" );
542
- ASSERT_TRUE (foldFuncPtrAndConstToNull (Context, &TheModule, 2 , 4 ));
543
- }
544
-
545
- TEST (ConstantsTest, DontFoldFunctionAlign4PtrAlignIndependent) {
546
- LLVMContext Context;
547
- Module TheModule (" TestModule" , Context);
548
- TheModule.setDataLayout (" Fi8" );
549
- ASSERT_FALSE (foldFuncPtrAndConstToNull (Context, &TheModule, 2 , 4 ));
550
- }
551
-
552
- TEST (ConstantsTest, DontFoldFunctionPtrIfNoModule) {
553
- LLVMContext Context;
554
- // Even though the function is explicitly 4 byte aligned, in the absence of a
555
- // DataLayout we can't assume that the function pointer is aligned.
556
- ASSERT_FALSE (foldFuncPtrAndConstToNull (Context, nullptr , 2 , 4 ));
557
- }
558
-
559
- TEST (ConstantsTest, FoldGlobalVariablePtr) {
560
- LLVMContext Context;
561
-
562
-
563
- IntegerType *IntType (Type::getInt32Ty (Context));
564
-
565
- std::unique_ptr<GlobalVariable> Global (
566
- new GlobalVariable (IntType, true , GlobalValue::ExternalLinkage));
567
-
568
- Global->setAlignment (4 );
569
-
570
- ConstantInt *TheConstant (ConstantInt::get (IntType, 2 ));
571
-
572
- Constant *TheConstantExpr (
573
- ConstantExpr::getPtrToInt (Global.get (), IntType));
574
-
575
- ASSERT_TRUE (ConstantExpr::get ( \
576
- Instruction::And, TheConstantExpr, TheConstant)->isNullValue ());
577
- }
578
-
579
478
} // end anonymous namespace
580
479
} // end namespace llvm
0 commit comments