diff options
author | Simon Atanasyan <simon@atanasyan.com> | 2019-03-19 15:15:35 +0000 |
---|---|---|
committer | Simon Atanasyan <simon@atanasyan.com> | 2019-03-19 15:15:35 +0000 |
commit | af40d4371d89d9c4a9be2e4bef3266577bd9ff3f (patch) | |
tree | 9fac052d4737d43aa4e2b85d8dcc6630906e0754 | |
parent | 00160e226f68c87f70b7e9cae464c51339a28026 (diff) | |
download | bcm5719-llvm-af40d4371d89d9c4a9be2e4bef3266577bd9ff3f.tar.gz bcm5719-llvm-af40d4371d89d9c4a9be2e4bef3266577bd9ff3f.zip |
[mips] Fix crash on recursive using of .set
Switch to the `MCParserUtils::parseAssignmentExpression` for parsing
assignment expressions in the `.set` directive reduces code and allows
to print an error message instead of crashing in case of incorrect
recursive using of the `.set`.
Fix for the bug https://bugs.llvm.org/show_bug.cgi?id=41053.
Differential Revision: http://reviews.llvm.org/D59452
llvm-svn: 356461
-rw-r--r-- | llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 19 | ||||
-rw-r--r-- | llvm/test/MC/Mips/set-sym-recursive.s | 5 |
2 files changed, 14 insertions, 10 deletions
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 59df173eee9..927b15e916f 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -28,6 +28,7 @@ #include "llvm/MC/MCParser/MCAsmLexer.h" #include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCAsmParserExtension.h" +#include "llvm/MC/MCParser/MCAsmParserUtils.h" #include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/MC/MCParser/MCTargetAsmParser.h" #include "llvm/MC/MCSectionELF.h" @@ -6803,7 +6804,6 @@ bool MipsAsmParser::parseSetHardFloatDirective() { bool MipsAsmParser::parseSetAssignment() { StringRef Name; - const MCExpr *Value; MCAsmParser &Parser = getParser(); if (Parser.parseIdentifier(Name)) @@ -6821,17 +6821,16 @@ bool MipsAsmParser::parseSetAssignment() { RegisterSets[Name] = Parser.getTok(); Parser.Lex(); // Eat identifier. getContext().getOrCreateSymbol(Name); - } else if (!Parser.parseExpression(Value)) { - // Parse assignment of an expression including - // symbolic registers: - // .set $tmp, $BB0-$BB1 - // .set r2, $f2 - MCSymbol *Sym = getContext().getOrCreateSymbol(Name); - Sym->setVariableValue(Value); - } else { - return reportParseError("expected valid expression after comma"); + return false; } + MCSymbol *Sym; + const MCExpr *Value; + if (MCParserUtils::parseAssignmentExpression(Name, /* allow_redef */ true, + Parser, Sym, Value)) + return true; + Sym->setVariableValue(Value); + return false; } diff --git a/llvm/test/MC/Mips/set-sym-recursive.s b/llvm/test/MC/Mips/set-sym-recursive.s new file mode 100644 index 00000000000..4e6b589813a --- /dev/null +++ b/llvm/test/MC/Mips/set-sym-recursive.s @@ -0,0 +1,5 @@ +# RUN: not llvm-mc -triple mips-unknown-linux %s 2>&1 | FileCheck %s + +.set A, A + 1 +# CHECK: :[[@LINE-1]]:9: error: Recursive use of 'A' +.word A |