@@ -1547,8 +1547,14 @@ bool MasmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
1547
1547
}
1548
1548
1549
1549
MCSymbol *Sym = getContext ().getInlineAsmLabel (SymbolName);
1550
- if (!Sym)
1550
+ if (!Sym) {
1551
+ // Variables use case-insensitive symbol names; if this is a variable, we
1552
+ // find the symbol using its canonical name.
1553
+ auto VarIt = Variables.find (SymbolName.lower ());
1554
+ if (VarIt != Variables.end ())
1555
+ SymbolName = VarIt->second .Name ;
1551
1556
Sym = getContext ().getOrCreateSymbol (SymbolName);
1557
+ }
1552
1558
1553
1559
// If this is an absolute variable reference, substitute it now to preserve
1554
1560
// semantics in the face of reassignment.
@@ -3268,14 +3274,15 @@ bool MasmParser::parseIdentifier(StringRef &Res) {
3268
3274
// / | name "textequ" text-list
3269
3275
bool MasmParser::parseDirectiveEquate (StringRef IDVal, StringRef Name,
3270
3276
DirectiveKind DirKind) {
3271
- Variable &Var = Variables[Name];
3277
+ Variable &Var = Variables[Name. lower () ];
3272
3278
if (Var.Name .empty ()) {
3273
3279
Var.Name = Name;
3274
3280
} else if (!Var.Redefinable ) {
3275
3281
return TokError (" invalid variable redefinition" );
3276
3282
}
3277
3283
Var.Redefinable = (DirKind != DK_EQU);
3278
3284
3285
+ SMLoc StartLoc = Lexer.getLoc ();
3279
3286
if (DirKind == DK_EQU || DirKind == DK_TEXTEQU) {
3280
3287
// "equ" and "textequ" both allow text expressions.
3281
3288
std::string Value;
@@ -3301,7 +3308,7 @@ bool MasmParser::parseDirectiveEquate(StringRef IDVal, StringRef Name,
3301
3308
3302
3309
// Parse as expression assignment.
3303
3310
const MCExpr *Expr;
3304
- SMLoc EndLoc, StartLoc = Lexer. getLoc () ;
3311
+ SMLoc EndLoc;
3305
3312
if (parseExpression (Expr, EndLoc))
3306
3313
return addErrorSuffix (" in '" + Twine (IDVal) + " ' directive" );
3307
3314
MCSymbol *Sym = getContext ().getOrCreateSymbol (Var.Name );
@@ -3378,21 +3385,30 @@ bool MasmParser::parseTextItem(std::string &Data) {
3378
3385
case AsmToken::LessGreater:
3379
3386
return parseAngleBracketString (Data);
3380
3387
case AsmToken::Identifier: {
3388
+ // This must be a text macro; we need to expand it accordingly.
3381
3389
StringRef ID;
3382
3390
if (parseIdentifier (ID))
3383
3391
return true ;
3384
3392
Data = ID.str ();
3385
3393
3386
- auto it = Variables.find (ID);
3387
- if (it == Variables.end ())
3394
+ auto it = Variables.find (ID.lower ());
3395
+ if (it == Variables.end ()) {
3396
+ // Not a variable; since we haven't used the token, put it back for better
3397
+ // error recovery.
3398
+ getLexer ().UnLex (AsmToken (AsmToken::Identifier, ID));
3388
3399
return true ;
3400
+ }
3389
3401
3390
3402
while (it != Variables.end ()) {
3391
3403
const Variable &Var = it->second ;
3392
- if (!Var.IsText )
3404
+ if (!Var.IsText ) {
3405
+ // Not a text macro; not usable in TextItem context. Since we haven't
3406
+ // used the token, put it back for better error recovery.
3407
+ getLexer ().UnLex (AsmToken (AsmToken::Identifier, ID));
3393
3408
return true ;
3409
+ }
3394
3410
Data = Var.TextValue ;
3395
- it = Variables.find (Data);
3411
+ it = Variables.find (StringRef ( Data). lower () );
3396
3412
}
3397
3413
return false ;
3398
3414
}
@@ -5945,10 +5961,10 @@ bool MasmParser::parseDirectiveIfdef(SMLoc DirectiveLoc, bool expect_defined) {
5945
5961
parseToken (AsmToken::EndOfStatement, " unexpected token in 'ifdef'" ))
5946
5962
return true ;
5947
5963
5948
- if (Variables.find (Name) != Variables.end ()) {
5964
+ if (Variables.find (Name. lower () ) != Variables.end ()) {
5949
5965
is_defined = true ;
5950
5966
} else {
5951
- MCSymbol *Sym = getContext ().lookupSymbol (Name);
5967
+ MCSymbol *Sym = getContext ().lookupSymbol (Name. lower () );
5952
5968
is_defined = (Sym && !Sym->isUndefined (false ));
5953
5969
}
5954
5970
}
@@ -6067,7 +6083,7 @@ bool MasmParser::parseDirectiveElseIfdef(SMLoc DirectiveLoc,
6067
6083
" unexpected token in 'elseifdef'" ))
6068
6084
return true ;
6069
6085
6070
- if (Variables.find (Name) != Variables.end ()) {
6086
+ if (Variables.find (Name. lower () ) != Variables.end ()) {
6071
6087
is_defined = true ;
6072
6088
} else {
6073
6089
MCSymbol *Sym = getContext ().lookupSymbol (Name);
@@ -6237,7 +6253,7 @@ bool MasmParser::parseDirectiveErrorIfdef(SMLoc DirectiveLoc,
6237
6253
if (check (parseIdentifier (Name), " expected identifier after '.errdef'" ))
6238
6254
return true ;
6239
6255
6240
- if (Variables.find (Name) != Variables.end ()) {
6256
+ if (Variables.find (Name. lower () ) != Variables.end ()) {
6241
6257
IsDefined = true ;
6242
6258
} else {
6243
6259
MCSymbol *Sym = getContext ().lookupSymbol (Name);
0 commit comments