Skip to content

Commit 7b517cf

Browse files
committed
MCParser: Add SMLoc to expressions
The information helps debugging, and will be used and tested when we change MCFixup::getLoc to use the MCExpr location and remove MCFixup::Loc.
1 parent 06922c4 commit 7b517cf

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,15 +1356,17 @@ const MCExpr *MCAsmParser::applySpecifier(const MCExpr *E, uint32_t Spec) {
13561356
return E;
13571357
}
13581358

1359-
return MCSymbolRefExpr::create(&SRE->getSymbol(), Spec, getContext());
1359+
return MCSymbolRefExpr::create(&SRE->getSymbol(), Spec, getContext(),
1360+
SRE->getLoc());
13601361
}
13611362

13621363
case MCExpr::Unary: {
13631364
const MCUnaryExpr *UE = cast<MCUnaryExpr>(E);
13641365
const MCExpr *Sub = applySpecifier(UE->getSubExpr(), Spec);
13651366
if (!Sub)
13661367
return nullptr;
1367-
return MCUnaryExpr::create(UE->getOpcode(), Sub, getContext());
1368+
return MCUnaryExpr::create(UE->getOpcode(), Sub, getContext(),
1369+
UE->getLoc());
13681370
}
13691371

13701372
case MCExpr::Binary: {
@@ -1380,7 +1382,8 @@ const MCExpr *MCAsmParser::applySpecifier(const MCExpr *E, uint32_t Spec) {
13801382
if (!RHS)
13811383
RHS = BE->getRHS();
13821384

1383-
return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, getContext());
1385+
return MCBinaryExpr::create(BE->getOpcode(), LHS, RHS, getContext(),
1386+
BE->getLoc());
13841387
}
13851388
}
13861389

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8266,7 +8266,7 @@ bool AArch64AsmParser::parseAuthExpr(const MCExpr *&Res, SMLoc &EndLoc) {
82668266
return true;
82678267

82688268
Res = AArch64AuthMCExpr::create(Res, Discriminator, *KeyIDOrNone,
8269-
UseAddressDiversity, Ctx);
8269+
UseAddressDiversity, Ctx, Res->getLoc());
82708270
return false;
82718271
}
82728272

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCAsmInfo.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,17 @@ class AArch64AuthMCExpr final : public MCSpecifierExpr {
199199
AArch64PACKey::ID Key;
200200

201201
explicit AArch64AuthMCExpr(const MCExpr *Expr, uint16_t Discriminator,
202-
AArch64PACKey::ID Key, bool HasAddressDiversity)
203-
: MCSpecifierExpr(Expr, HasAddressDiversity ? AArch64::S_AUTHADDR
204-
: AArch64::S_AUTH),
202+
AArch64PACKey::ID Key, bool HasAddressDiversity,
203+
SMLoc Loc)
204+
: MCSpecifierExpr(
205+
Expr, HasAddressDiversity ? AArch64::S_AUTHADDR : AArch64::S_AUTH,
206+
Loc),
205207
Discriminator(Discriminator), Key(Key) {}
206208

207209
public:
208210
static const AArch64AuthMCExpr *
209211
create(const MCExpr *Expr, uint16_t Discriminator, AArch64PACKey::ID Key,
210-
bool HasAddressDiversity, MCContext &Ctx);
212+
bool HasAddressDiversity, MCContext &Ctx, SMLoc Loc = SMLoc());
211213

212214
AArch64PACKey::ID getKey() const { return Key; }
213215
uint16_t getDiscriminator() const { return Discriminator; }

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const AArch64AuthMCExpr *AArch64AuthMCExpr::create(const MCExpr *Expr,
1818
uint16_t Discriminator,
1919
AArch64PACKey::ID Key,
2020
bool HasAddressDiversity,
21-
MCContext &Ctx) {
21+
MCContext &Ctx, SMLoc Loc) {
2222
return new (Ctx)
23-
AArch64AuthMCExpr(Expr, Discriminator, Key, HasAddressDiversity);
23+
AArch64AuthMCExpr(Expr, Discriminator, Key, HasAddressDiversity, Loc);
2424
}

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,12 +2092,13 @@ ParseStatus RISCVAsmParser::parseOperandWithSpecifier(OperandVector &Operands) {
20922092
}
20932093

20942094
bool RISCVAsmParser::parseExprWithSpecifier(const MCExpr *&Res, SMLoc &E) {
2095+
SMLoc Loc = getLoc();
20952096
if (getLexer().getKind() != AsmToken::Identifier)
2096-
return Error(getLoc(), "expected '%' relocation specifier");
2097+
return TokError("expected '%' relocation specifier");
20972098
StringRef Identifier = getParser().getTok().getIdentifier();
20982099
auto Spec = RISCV::parseSpecifierName(Identifier);
20992100
if (!Spec)
2100-
return Error(getLoc(), "invalid relocation specifier");
2101+
return TokError("invalid relocation specifier");
21012102

21022103
getParser().Lex(); // Eat the identifier
21032104
if (parseToken(AsmToken::LParen, "expected '('"))
@@ -2107,7 +2108,7 @@ bool RISCVAsmParser::parseExprWithSpecifier(const MCExpr *&Res, SMLoc &E) {
21072108
if (getParser().parseParenExpression(SubExpr, E))
21082109
return true;
21092110

2110-
Res = MCSpecifierExpr::create(SubExpr, Spec, getContext(), SubExpr->getLoc());
2111+
Res = MCSpecifierExpr::create(SubExpr, Spec, getContext(), Loc);
21112112
return false;
21122113
}
21132114

0 commit comments

Comments
 (0)