From 3b63d409c9496951977f105309681d3ea34b4d9d Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Tue, 25 Mar 2014 10:57:07 +0000 Subject: [PATCH] [mips] Fix assembler temporary expansion and add associated warnings about the use of $at. Summary: The assembler temporary is normally $at ($1) but can be reassigned using '.set at=$reg'. Regardless of which register is nominated as the assembler temporary, $at remains $1 when written by the user. Adds warnings under the following conditions: * The register nominated as the assembler temporary is used by the user. * '.set noat' is in effect and $at is used by the user. Both of these only work for named registers. I have a follow up commit that makes it work for numeric registers as well. XFAIL set-at-directive.s since it incorrectly tests that $at is redefined by '.set at=$reg'. Testcases will follow in a separate commit. Patch by David Chisnall His work was sponsored by: DARPA, AFRL Differential Revision: http://llvm-reviews.chandlerc.com/D3167 llvm-svn: 204710 --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp | 13 +++++++++++-- test/MC/Mips/set-at-directive.s | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index f54a62b666c..0a6aee4bcee 100644 --- a/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -985,8 +985,13 @@ bool MipsAsmParser::MatchAndEmitInstruction( int MipsAsmParser::matchCPURegisterName(StringRef Name) { int CC; - if (Name == "at") - return getATReg(); + if (Name == "at") { + // If noat is set then the at register is 0, otherwise it's defined as a + // specific register. Warn if the assembler is free to use it. + if (Options.getATRegNum() != 0) + Warning(getLexer().getLoc(), "Used $at without \".set noat\""); + return 1; + } CC = StringSwitch(Name) .Case("zero", 0) @@ -1039,6 +1044,10 @@ int MipsAsmParser::matchCPURegisterName(StringRef Name) { .Case("s8", 30) .Default(-1); + if ((CC != 0) && ((int)Options.getATRegNum() == CC)) + Warning(getLexer().getLoc(), Twine("Used $") + Name + " with \".set at=$" + + Name + "\""); + return CC; } diff --git a/test/MC/Mips/set-at-directive.s b/test/MC/Mips/set-at-directive.s index 828175a223a..be528c977e9 100644 --- a/test/MC/Mips/set-at-directive.s +++ b/test/MC/Mips/set-at-directive.s @@ -2,7 +2,7 @@ # RUN: FileCheck %s # Check that the assembler can handle the documented syntax # for ".set at" and set the correct value. - +# XFAIL: .text foo: # CHECK: jr $1 # encoding: [0x08,0x00,0x20,0x00]