[llvm] r181192 - [PowerPC] Fix memory corruption in AsmParser
Ulrich Weigand
ulrich.weigand at de.ibm.com
Mon May 6 04:16:57 PDT 2013
Author: uweigand
Date: Mon May 6 06:16:57 2013
New Revision: 181192
URL: http://llvm.org/viewvc/llvm-project?rev=181192&view=rev
Log:
[PowerPC] Fix memory corruption in AsmParser
As pointed out by Evgeniy Stepanov, assigning a std::string temporary
to a StringRef is not a good idea. Rework MatchRegisterName to avoid
using the .lower routine.
Modified:
llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
Modified: llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp?rev=181192&r1=181191&r2=181192&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp Mon May 6 06:16:57 2013
@@ -508,29 +508,29 @@ MatchAndEmitInstruction(SMLoc IDLoc, uns
bool PPCAsmParser::
MatchRegisterName(const AsmToken &Tok, unsigned &RegNo, int64_t &IntVal) {
if (Tok.is(AsmToken::Identifier)) {
- StringRef Name = Tok.getString().lower();
+ StringRef Name = Tok.getString();
- if (Name == "lr") {
+ if (Name.equals_lower("lr")) {
RegNo = isPPC64()? PPC::LR8 : PPC::LR;
IntVal = 8;
return false;
- } else if (Name == "ctr") {
+ } else if (Name.equals_lower("ctr")) {
RegNo = isPPC64()? PPC::CTR8 : PPC::CTR;
IntVal = 9;
return false;
- } else if (Name.startswith("r") &&
+ } else if (Name.substr(0, 1).equals_lower("r") &&
!Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) {
RegNo = isPPC64()? XRegs[IntVal] : RRegs[IntVal];
return false;
- } else if (Name.startswith("f") &&
+ } else if (Name.substr(0, 1).equals_lower("f") &&
!Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) {
RegNo = FRegs[IntVal];
return false;
- } else if (Name.startswith("v") &&
+ } else if (Name.substr(0, 1).equals_lower("v") &&
!Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) {
RegNo = VRegs[IntVal];
return false;
- } else if (Name.startswith("cr") &&
+ } else if (Name.substr(0, 2).equals_lower("cr") &&
!Name.substr(2).getAsInteger(10, IntVal) && IntVal < 8) {
RegNo = CRRegs[IntVal];
return false;
More information about the llvm-commits
mailing list