[llvm-commits] [llvm] r140679 - in /llvm/trunk/lib/Target/PTX: PTXISelLowering.cpp PTXParamManager.h
Benjamin Kramer
benny.kra at googlemail.com
Tue Sep 27 21:08:02 PDT 2011
Author: d0k
Date: Tue Sep 27 23:08:02 2011
New Revision: 140679
URL: http://llvm.org/viewvc/llvm-project?rev=140679&view=rev
Log:
PTX: Pass param name strings per const reference.
The copies caused use-after-free bugs on std::string implementations without COW (i.e. anything but libstdc++)
Modified:
llvm/trunk/lib/Target/PTX/PTXISelLowering.cpp
llvm/trunk/lib/Target/PTX/PTXParamManager.h
Modified: llvm/trunk/lib/Target/PTX/PTXISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXISelLowering.cpp?rev=140679&r1=140678&r2=140679&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PTX/PTXISelLowering.cpp Tue Sep 27 23:08:02 2011
@@ -225,7 +225,7 @@
unsigned ParamSize = Ins[i].VT.getStoreSizeInBits();
unsigned Param = PM.addArgumentParam(ParamSize);
- std::string ParamName = PM.getParamName(Param);
+ const std::string &ParamName = PM.getParamName(Param);
SDValue ParamValue = DAG.getTargetExternalSymbol(ParamName.c_str(),
MVT::Other);
SDValue ArgValue = DAG.getNode(PTXISD::LOAD_PARAM, dl, Ins[i].VT, Chain,
@@ -322,7 +322,7 @@
if (Outs.size() == 1) {
unsigned ParamSize = OutVals[0].getValueType().getSizeInBits();
unsigned Param = PM.addReturnParam(ParamSize);
- std::string ParamName = PM.getParamName(Param);
+ const std::string &ParamName = PM.getParamName(Param);
SDValue ParamValue = DAG.getTargetExternalSymbol(ParamName.c_str(),
MVT::Other);
Chain = DAG.getNode(PTXISD::STORE_PARAM, dl, MVT::Other, Chain,
@@ -419,7 +419,7 @@
for (unsigned i = 0; i != OutVals.size(); ++i) {
unsigned Size = OutVals[i].getValueType().getSizeInBits();
unsigned Param = PM.addLocalParam(Size);
- std::string ParamName = PM.getParamName(Param);
+ const std::string &ParamName = PM.getParamName(Param);
SDValue ParamValue = DAG.getTargetExternalSymbol(ParamName.c_str(),
MVT::Other);
Chain = DAG.getNode(PTXISD::STORE_PARAM, dl, MVT::Other, Chain,
@@ -433,7 +433,7 @@
for (unsigned i = 0; i < Ins.size(); ++i) {
unsigned Size = Ins[i].VT.getStoreSizeInBits();
unsigned Param = PM.addLocalParam(Size);
- std::string ParamName = PM.getParamName(Param);
+ const std::string &ParamName = PM.getParamName(Param);
SDValue ParamValue = DAG.getTargetExternalSymbol(ParamName.c_str(),
MVT::Other);
Ops[i+1] = ParamValue;
Modified: llvm/trunk/lib/Target/PTX/PTXParamManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXParamManager.h?rev=140679&r1=140678&r2=140679&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXParamManager.h (original)
+++ llvm/trunk/lib/Target/PTX/PTXParamManager.h Tue Sep 27 23:08:02 2011
@@ -67,15 +67,15 @@
unsigned addLocalParam(unsigned Size);
/// getParamName - Returns the name of the parameter as a string.
- std::string getParamName(unsigned Param) const {
+ const std::string &getParamName(unsigned Param) const {
assert(AllParams.count(Param) == 1 && "Param has not been defined!");
- return AllParams.lookup(Param).Name;
+ return AllParams.find(Param)->second.Name;
}
/// getParamSize - Returns the size of the parameter in bits.
unsigned getParamSize(unsigned Param) const {
assert(AllParams.count(Param) == 1 && "Param has not been defined!");
- return AllParams.lookup(Param).Size;
+ return AllParams.find(Param)->second.Size;
}
};
More information about the llvm-commits
mailing list