59
59
#include " llvm/IR/Argument.h"
60
60
#include " llvm/IR/Attributes.h"
61
61
#include " llvm/IR/BasicBlock.h"
62
- #include " llvm/IR/CallSite.h"
63
62
#include " llvm/IR/Constant.h"
64
63
#include " llvm/IR/Constants.h"
65
64
#include " llvm/IR/DataLayout.h"
@@ -469,7 +468,7 @@ class DFSanVisitor : public InstVisitor<DFSanVisitor> {
469
468
void visitLoadInst (LoadInst &LI);
470
469
void visitStoreInst (StoreInst &SI);
471
470
void visitReturnInst (ReturnInst &RI);
472
- void visitCallSite (CallSite CS );
471
+ void visitCallBase (CallBase &CB );
473
472
void visitPHINode (PHINode &PN);
474
473
void visitExtractElementInst (ExtractElementInst &I);
475
474
void visitInsertElementInst (InsertElementInst &I);
@@ -1592,10 +1591,10 @@ void DFSanVisitor::visitReturnInst(ReturnInst &RI) {
1592
1591
}
1593
1592
}
1594
1593
1595
- void DFSanVisitor::visitCallSite (CallSite CS ) {
1596
- Function *F = CS .getCalledFunction ();
1597
- if ((F && F->isIntrinsic ()) || isa<InlineAsm>(CS .getCalledValue ())) {
1598
- visitOperandShadowInst (*CS. getInstruction () );
1594
+ void DFSanVisitor::visitCallBase (CallBase &CB ) {
1595
+ Function *F = CB .getCalledFunction ();
1596
+ if ((F && F->isIntrinsic ()) || isa<InlineAsm>(CB .getCalledValue ())) {
1597
+ visitOperandShadowInst (CB );
1599
1598
return ;
1600
1599
}
1601
1600
@@ -1604,32 +1603,32 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1604
1603
if (F == DFSF.DFS .DFSanVarargWrapperFn .getCallee ()->stripPointerCasts ())
1605
1604
return ;
1606
1605
1607
- IRBuilder<> IRB (CS. getInstruction () );
1606
+ IRBuilder<> IRB (&CB );
1608
1607
1609
1608
DenseMap<Value *, Function *>::iterator i =
1610
- DFSF.DFS .UnwrappedFnMap .find (CS .getCalledValue ());
1609
+ DFSF.DFS .UnwrappedFnMap .find (CB .getCalledValue ());
1611
1610
if (i != DFSF.DFS .UnwrappedFnMap .end ()) {
1612
1611
Function *F = i->second ;
1613
1612
switch (DFSF.DFS .getWrapperKind (F)) {
1614
1613
case DataFlowSanitizer::WK_Warning:
1615
- CS .setCalledFunction (F);
1614
+ CB .setCalledFunction (F);
1616
1615
IRB.CreateCall (DFSF.DFS .DFSanUnimplementedFn ,
1617
1616
IRB.CreateGlobalStringPtr (F->getName ()));
1618
- DFSF.setShadow (CS. getInstruction () , DFSF.DFS .ZeroShadow );
1617
+ DFSF.setShadow (&CB , DFSF.DFS .ZeroShadow );
1619
1618
return ;
1620
1619
case DataFlowSanitizer::WK_Discard:
1621
- CS .setCalledFunction (F);
1622
- DFSF.setShadow (CS. getInstruction () , DFSF.DFS .ZeroShadow );
1620
+ CB .setCalledFunction (F);
1621
+ DFSF.setShadow (&CB , DFSF.DFS .ZeroShadow );
1623
1622
return ;
1624
1623
case DataFlowSanitizer::WK_Functional:
1625
- CS .setCalledFunction (F);
1626
- visitOperandShadowInst (*CS. getInstruction () );
1624
+ CB .setCalledFunction (F);
1625
+ visitOperandShadowInst (CB );
1627
1626
return ;
1628
1627
case DataFlowSanitizer::WK_Custom:
1629
1628
// Don't try to handle invokes of custom functions, it's too complicated.
1630
1629
// Instead, invoke the dfsw$ wrapper, which will in turn call the __dfsw_
1631
1630
// wrapper.
1632
- if (CallInst *CI = dyn_cast<CallInst>(CS. getInstruction () )) {
1631
+ if (CallInst *CI = dyn_cast<CallInst>(&CB )) {
1633
1632
FunctionType *FT = F->getFunctionType ();
1634
1633
TransformedFunction CustomFn = DFSF.DFS .getCustomFunctionType (FT);
1635
1634
std::string CustomFName = " __dfsw_" ;
@@ -1648,7 +1647,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1648
1647
1649
1648
std::vector<Value *> Args;
1650
1649
1651
- CallSite::arg_iterator i = CS .arg_begin ();
1650
+ auto i = CB .arg_begin ();
1652
1651
for (unsigned n = FT->getNumParams (); n != 0 ; ++i, --n) {
1653
1652
Type *T = (*i)->getType ();
1654
1653
FunctionType *ParamFT;
@@ -1668,19 +1667,19 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1668
1667
}
1669
1668
}
1670
1669
1671
- i = CS .arg_begin ();
1670
+ i = CB .arg_begin ();
1672
1671
const unsigned ShadowArgStart = Args.size ();
1673
1672
for (unsigned n = FT->getNumParams (); n != 0 ; ++i, --n)
1674
1673
Args.push_back (DFSF.getShadow (*i));
1675
1674
1676
1675
if (FT->isVarArg ()) {
1677
1676
auto *LabelVATy = ArrayType::get (DFSF.DFS .ShadowTy ,
1678
- CS .arg_size () - FT->getNumParams ());
1677
+ CB .arg_size () - FT->getNumParams ());
1679
1678
auto *LabelVAAlloca = new AllocaInst (
1680
1679
LabelVATy, getDataLayout ().getAllocaAddrSpace (),
1681
1680
" labelva" , &DFSF.F ->getEntryBlock ().front ());
1682
1681
1683
- for (unsigned n = 0 ; i != CS .arg_end (); ++i, ++n) {
1682
+ for (unsigned n = 0 ; i != CB .arg_end (); ++i, ++n) {
1684
1683
auto LabelVAPtr = IRB.CreateStructGEP (LabelVATy, LabelVAAlloca, n);
1685
1684
IRB.CreateStore (DFSF.getShadow (*i), LabelVAPtr);
1686
1685
}
@@ -1698,7 +1697,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1698
1697
Args.push_back (DFSF.LabelReturnAlloca );
1699
1698
}
1700
1699
1701
- for (i = CS .arg_begin () + FT->getNumParams (); i != CS .arg_end (); ++i)
1700
+ for (i = CB .arg_begin () + FT->getNumParams (); i != CB .arg_end (); ++i)
1702
1701
Args.push_back (*i);
1703
1702
1704
1703
CallInst *CustomCI = IRB.CreateCall (CustomF, Args);
@@ -1730,17 +1729,17 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1730
1729
}
1731
1730
1732
1731
FunctionType *FT = cast<FunctionType>(
1733
- CS .getCalledValue ()->getType ()->getPointerElementType ());
1732
+ CB .getCalledValue ()->getType ()->getPointerElementType ());
1734
1733
if (DFSF.DFS .getInstrumentedABI () == DataFlowSanitizer::IA_TLS) {
1735
1734
for (unsigned i = 0 , n = FT->getNumParams (); i != n; ++i) {
1736
- IRB.CreateStore (DFSF.getShadow (CS. getArgument (i)),
1737
- DFSF.getArgTLS (i, CS. getInstruction () ));
1735
+ IRB.CreateStore (DFSF.getShadow (CB. getArgOperand (i)),
1736
+ DFSF.getArgTLS (i, &CB ));
1738
1737
}
1739
1738
}
1740
1739
1741
1740
Instruction *Next = nullptr ;
1742
- if (!CS .getType ()->isVoidTy ()) {
1743
- if (InvokeInst *II = dyn_cast<InvokeInst>(CS. getInstruction () )) {
1741
+ if (!CB .getType ()->isVoidTy ()) {
1742
+ if (InvokeInst *II = dyn_cast<InvokeInst>(&CB )) {
1744
1743
if (II->getNormalDest ()->getSinglePredecessor ()) {
1745
1744
Next = &II->getNormalDest ()->front ();
1746
1745
} else {
@@ -1749,15 +1748,15 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1749
1748
Next = &NewBB->front ();
1750
1749
}
1751
1750
} else {
1752
- assert (CS-> getIterator () != CS-> getParent ()->end ());
1753
- Next = CS-> getNextNode ();
1751
+ assert (CB. getIterator () != CB. getParent ()->end ());
1752
+ Next = CB. getNextNode ();
1754
1753
}
1755
1754
1756
1755
if (DFSF.DFS .getInstrumentedABI () == DataFlowSanitizer::IA_TLS) {
1757
1756
IRBuilder<> NextIRB (Next);
1758
1757
LoadInst *LI = NextIRB.CreateLoad (DFSF.DFS .ShadowTy , DFSF.getRetvalTLS ());
1759
1758
DFSF.SkipInsts .insert (LI);
1760
- DFSF.setShadow (CS. getInstruction () , LI);
1759
+ DFSF.setShadow (&CB , LI);
1761
1760
DFSF.NonZeroChecks .push_back (LI);
1762
1761
}
1763
1762
}
@@ -1767,58 +1766,56 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
1767
1766
if (DFSF.DFS .getInstrumentedABI () == DataFlowSanitizer::IA_Args) {
1768
1767
FunctionType *NewFT = DFSF.DFS .getArgsFunctionType (FT);
1769
1768
Value *Func =
1770
- IRB.CreateBitCast (CS .getCalledValue (), PointerType::getUnqual (NewFT));
1769
+ IRB.CreateBitCast (CB .getCalledValue (), PointerType::getUnqual (NewFT));
1771
1770
std::vector<Value *> Args;
1772
1771
1773
- CallSite::arg_iterator i = CS .arg_begin (), e = CS .arg_end ();
1772
+ auto i = CB .arg_begin (), E = CB .arg_end ();
1774
1773
for (unsigned n = FT->getNumParams (); n != 0 ; ++i, --n)
1775
1774
Args.push_back (*i);
1776
1775
1777
- i = CS .arg_begin ();
1776
+ i = CB .arg_begin ();
1778
1777
for (unsigned n = FT->getNumParams (); n != 0 ; ++i, --n)
1779
1778
Args.push_back (DFSF.getShadow (*i));
1780
1779
1781
1780
if (FT->isVarArg ()) {
1782
- unsigned VarArgSize = CS .arg_size () - FT->getNumParams ();
1781
+ unsigned VarArgSize = CB .arg_size () - FT->getNumParams ();
1783
1782
ArrayType *VarArgArrayTy = ArrayType::get (DFSF.DFS .ShadowTy , VarArgSize);
1784
1783
AllocaInst *VarArgShadow =
1785
1784
new AllocaInst (VarArgArrayTy, getDataLayout ().getAllocaAddrSpace (),
1786
1785
" " , &DFSF.F ->getEntryBlock ().front ());
1787
1786
Args.push_back (IRB.CreateConstGEP2_32 (VarArgArrayTy, VarArgShadow, 0 , 0 ));
1788
- for (unsigned n = 0 ; i != e ; ++i, ++n) {
1787
+ for (unsigned n = 0 ; i != E ; ++i, ++n) {
1789
1788
IRB.CreateStore (
1790
1789
DFSF.getShadow (*i),
1791
1790
IRB.CreateConstGEP2_32 (VarArgArrayTy, VarArgShadow, 0 , n));
1792
1791
Args.push_back (*i);
1793
1792
}
1794
1793
}
1795
1794
1796
- CallSite NewCS ;
1797
- if (InvokeInst *II = dyn_cast<InvokeInst>(CS. getInstruction () )) {
1798
- NewCS = IRB.CreateInvoke (NewFT, Func, II->getNormalDest (),
1795
+ CallBase *NewCB ;
1796
+ if (InvokeInst *II = dyn_cast<InvokeInst>(&CB )) {
1797
+ NewCB = IRB.CreateInvoke (NewFT, Func, II->getNormalDest (),
1799
1798
II->getUnwindDest (), Args);
1800
1799
} else {
1801
- NewCS = IRB.CreateCall (NewFT, Func, Args);
1800
+ NewCB = IRB.CreateCall (NewFT, Func, Args);
1802
1801
}
1803
- NewCS. setCallingConv (CS .getCallingConv ());
1804
- NewCS. setAttributes (CS .getAttributes ().removeAttributes (
1802
+ NewCB-> setCallingConv (CB .getCallingConv ());
1803
+ NewCB-> setAttributes (CB .getAttributes ().removeAttributes (
1805
1804
*DFSF.DFS .Ctx , AttributeList::ReturnIndex,
1806
- AttributeFuncs::typeIncompatible (NewCS. getInstruction () ->getType ())));
1805
+ AttributeFuncs::typeIncompatible (NewCB ->getType ())));
1807
1806
1808
1807
if (Next) {
1809
- ExtractValueInst *ExVal =
1810
- ExtractValueInst::Create (NewCS.getInstruction (), 0 , " " , Next);
1808
+ ExtractValueInst *ExVal = ExtractValueInst::Create (NewCB, 0 , " " , Next);
1811
1809
DFSF.SkipInsts .insert (ExVal);
1812
- ExtractValueInst *ExShadow =
1813
- ExtractValueInst::Create (NewCS.getInstruction (), 1 , " " , Next);
1810
+ ExtractValueInst *ExShadow = ExtractValueInst::Create (NewCB, 1 , " " , Next);
1814
1811
DFSF.SkipInsts .insert (ExShadow);
1815
1812
DFSF.setShadow (ExVal, ExShadow);
1816
1813
DFSF.NonZeroChecks .push_back (ExShadow);
1817
1814
1818
- CS. getInstruction ()-> replaceAllUsesWith (ExVal);
1815
+ CB. replaceAllUsesWith (ExVal);
1819
1816
}
1820
1817
1821
- CS. getInstruction ()-> eraseFromParent ();
1818
+ CB. eraseFromParent ();
1822
1819
}
1823
1820
}
1824
1821
0 commit comments