Skip to content

[AsmParser] Correctly handle .ifeqs nested in other conditional directives #132713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5224,37 +5224,43 @@ bool AsmParser::parseDirectiveIfc(SMLoc DirectiveLoc, bool ExpectEqual) {
/// parseDirectiveIfeqs
/// ::= .ifeqs string1, string2
bool AsmParser::parseDirectiveIfeqs(SMLoc DirectiveLoc, bool ExpectEqual) {
if (Lexer.isNot(AsmToken::String)) {
if (ExpectEqual)
return TokError("expected string parameter for '.ifeqs' directive");
return TokError("expected string parameter for '.ifnes' directive");
}
TheCondStack.push_back(TheCondState);
TheCondState.TheCond = AsmCond::IfCond;

StringRef String1 = getTok().getStringContents();
Lex();
if (TheCondState.Ignore) {
eatToEndOfStatement();
} else {
if (Lexer.isNot(AsmToken::String)) {
if (ExpectEqual)
return TokError("expected string parameter for '.ifeqs' directive");
return TokError("expected string parameter for '.ifnes' directive");
}

if (Lexer.isNot(AsmToken::Comma)) {
if (ExpectEqual)
StringRef String1 = getTok().getStringContents();
Lex();

if (Lexer.isNot(AsmToken::Comma)) {
if (ExpectEqual)
return TokError(
"expected comma after first string for '.ifeqs' directive");
return TokError(
"expected comma after first string for '.ifeqs' directive");
return TokError("expected comma after first string for '.ifnes' directive");
}
"expected comma after first string for '.ifnes' directive");
}

Lex();
Lex();

if (Lexer.isNot(AsmToken::String)) {
if (ExpectEqual)
return TokError("expected string parameter for '.ifeqs' directive");
return TokError("expected string parameter for '.ifnes' directive");
}
if (Lexer.isNot(AsmToken::String)) {
if (ExpectEqual)
return TokError("expected string parameter for '.ifeqs' directive");
return TokError("expected string parameter for '.ifnes' directive");
}

StringRef String2 = getTok().getStringContents();
Lex();
StringRef String2 = getTok().getStringContents();
Lex();

TheCondStack.push_back(TheCondState);
TheCondState.TheCond = AsmCond::IfCond;
TheCondState.CondMet = ExpectEqual == (String1 == String2);
TheCondState.Ignore = !TheCondState.CondMet;
TheCondState.CondMet = ExpectEqual == (String1 == String2);
TheCondState.Ignore = !TheCondState.CondMet;
}

return false;
}
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/MC/AsmParser/ifeqs.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@
// CHECK-NOT: .byte 0
// CHECK: .byte 1


.if 0
.ifeqs "alpha", "alpha"
.byte 2
.else
.byte 3
.endif
.endif

// CHECK-NOT: .byte 2
// CHECK-NOT: .byte 3
10 changes: 10 additions & 0 deletions llvm/test/MC/AsmParser/ifnes.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@
# CHECK: .byte 1
.ifnes "equal", "equal" ; .byte 0 ; .else ; .byte 1 ; .endif

.if 0
.ifnes "alpha", "alpha"
.byte 2
.else
.byte 3
.endif
.endif

// CHECK-NOT: .byte 2
// CHECK-NOT: .byte 3