Skip to content

Commit 37fb3b3

Browse files
author
David Spickett
committed
[AsmParser] Make generic directives and aliases case insensitive.
GCC will accept any case for assembler directives. For example ".abort" and ".ABORT" (even ".aBoRt") are equivalent. https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops "The names are case insensitive for most targets, and usually written in lower case." Change llvm-mc to accept any case for generic directives or aliases of those directives. This for Bugzilla llvm#39527. Differential Revision: https://reviews.llvm.org/D72686
1 parent fe3bb8e commit 37fb3b3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class AsmParser : public MCAsmParser {
199199
}
200200

201201
void addAliasForDirective(StringRef Directive, StringRef Alias) override {
202-
DirectiveKindMap[Directive] = DirectiveKindMap[Alias];
202+
DirectiveKindMap[Directive.lower()] = DirectiveKindMap[Alias.lower()];
203203
}
204204

205205
/// @name MCAsmParser Interface
@@ -1750,7 +1750,7 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
17501750
// have to do this so that .endif isn't skipped in a ".if 0" block for
17511751
// example.
17521752
StringMap<DirectiveKind>::const_iterator DirKindIt =
1753-
DirectiveKindMap.find(IDVal);
1753+
DirectiveKindMap.find(IDVal.lower());
17541754
DirectiveKind DirKind = (DirKindIt == DirectiveKindMap.end())
17551755

17561756
? DK_NO_DIRECTIVE
@@ -5320,6 +5320,12 @@ bool AsmParser::parseDirectiveEndIf(SMLoc DirectiveLoc) {
53205320
}
53215321

53225322
void AsmParser::initializeDirectiveKindMap() {
5323+
/* Lookup will be done with the directive
5324+
* converted to lower case, so all these
5325+
* keys should be lower case.
5326+
* (target specific directives are handled
5327+
* elsewhere)
5328+
*/
53235329
DirectiveKindMap[".set"] = DK_SET;
53245330
DirectiveKindMap[".equ"] = DK_EQU;
53255331
DirectiveKindMap[".equiv"] = DK_EQUIV;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
2+
3+
# CHECK: .byte 65
4+
.ascii "A"
5+
# CHECK: .byte 66
6+
.ASCII "B"
7+
# CHECK: .byte 67
8+
.aScIi "C"
9+
10+
# Note: using 2byte because it is an alias
11+
# CHECK: .short 4660
12+
.2byte 0x1234
13+
# CHECK: .short 4661
14+
.2BYTE 0x1235
15+
# CHECK: .short 4662
16+
.2bYtE 0x1236

0 commit comments

Comments
 (0)