diff --git a/bindings/go/keystone/keystone_const.go b/bindings/go/keystone/keystone_const.go index 5a3f530ab2b3b639a44f45040ad27b22b95ba3db..d3358fdf802de7d3adfa6be0da68d342491253d7 100644 --- a/bindings/go/keystone/keystone_const.go +++ b/bindings/go/keystone/keystone_const.go @@ -94,6 +94,7 @@ const ( ERR_ASM_TOKEN_INVALID Error = 157 ERR_ASM_INSN_UNSUPPORTED Error = 158 ERR_ASM_FIXUP_INVALID Error = 159 + ERR_ASM_LABEL_INVALID Error = 160 ERR_ASM_INVALIDOPERAND Error = 512 ERR_ASM_MISSINGFEATURE Error = 513 ERR_ASM_MNEMONICFAIL Error = 514 diff --git a/bindings/nodejs/consts/keystone.js b/bindings/nodejs/consts/keystone.js index ee0b5308f73c3d8dea4ce80ed34d4d06cddf1220..5abaffcfce39dfd2973cd726e9906a93f2143fbb 100644 --- a/bindings/nodejs/consts/keystone.js +++ b/bindings/nodejs/consts/keystone.js @@ -70,6 +70,7 @@ module.exports.ERR_ASM_ESC_STR = 156 module.exports.ERR_ASM_TOKEN_INVALID = 157 module.exports.ERR_ASM_INSN_UNSUPPORTED = 158 module.exports.ERR_ASM_FIXUP_INVALID = 159 +module.exports.ERR_ASM_LABEL_INVALID = 160 module.exports.ERR_ASM_INVALIDOPERAND = 512 module.exports.ERR_ASM_MISSINGFEATURE = 513 module.exports.ERR_ASM_MNEMONICFAIL = 514 diff --git a/bindings/python/keystone/keystone_const.py b/bindings/python/keystone/keystone_const.py index 17c70680988b7400ae43747623301b21feabda44..dfc3f34213da4b48b0c6c0d0a1accca0844c6719 100644 --- a/bindings/python/keystone/keystone_const.py +++ b/bindings/python/keystone/keystone_const.py @@ -70,6 +70,7 @@ KS_ERR_ASM_ESC_STR = 156 KS_ERR_ASM_TOKEN_INVALID = 157 KS_ERR_ASM_INSN_UNSUPPORTED = 158 KS_ERR_ASM_FIXUP_INVALID = 159 +KS_ERR_ASM_LABEL_INVALID = 160 KS_ERR_ASM_INVALIDOPERAND = 512 KS_ERR_ASM_MISSINGFEATURE = 513 KS_ERR_ASM_MNEMONICFAIL = 514 diff --git a/bindings/ruby/keystone_gem/lib/keystone/keystone_const.rb b/bindings/ruby/keystone_gem/lib/keystone/keystone_const.rb index 470664544cfde4110c36fb45ca82875d2628fd37..93f22722942b6ed0cb7148d7d86d80fb6dd18f04 100644 --- a/bindings/ruby/keystone_gem/lib/keystone/keystone_const.rb +++ b/bindings/ruby/keystone_gem/lib/keystone/keystone_const.rb @@ -72,6 +72,7 @@ module Keystone KS_ERR_ASM_TOKEN_INVALID = 157 KS_ERR_ASM_INSN_UNSUPPORTED = 158 KS_ERR_ASM_FIXUP_INVALID = 159 + KS_ERR_ASM_LABEL_INVALID = 160 KS_ERR_ASM_INVALIDOPERAND = 512 KS_ERR_ASM_MISSINGFEATURE = 513 KS_ERR_ASM_MNEMONICFAIL = 514 diff --git a/bindings/rust/src/keystone_const.rs b/bindings/rust/src/keystone_const.rs index 0d5c73e0ddb1b0520dd219399e213ea0d6903794..8b34f9398f17bee948206048ab40eeb069334c4b 100644 --- a/bindings/rust/src/keystone_const.rs +++ b/bindings/rust/src/keystone_const.rs @@ -139,6 +139,7 @@ bitflags! { const ERR_ASM_TOKEN_INVALID = 157, const ERR_ASM_INSN_UNSUPPORTED = 158, const ERR_ASM_FIXUP_INVALID = 159, + const ERR_ASM_LABEL_INVALID = 160, const ERR_ASM_INVALIDOPERAND = 512, const ERR_ASM_MISSINGFEATURE = 513, const ERR_ASM_MNEMONICFAIL = 514, diff --git a/include/keystone/keystone.h b/include/keystone/keystone.h index c4ba03fa4c0b922fe9d8ec240242fc4222d7fa2d..a86311a65203511848ed0231615adb423079645d 100644 --- a/include/keystone/keystone.h +++ b/include/keystone/keystone.h @@ -129,6 +129,7 @@ typedef enum ks_err { KS_ERR_ASM_TOKEN_INVALID, // invalid token KS_ERR_ASM_INSN_UNSUPPORTED, // this instruction is unsupported in this mode KS_ERR_ASM_FIXUP_INVALID, // invalid fixup + KS_ERR_ASM_LABEL_INVALID, // invalid label // generic input assembly errors - architecture specific KS_ERR_ASM_INVALIDOPERAND = KS_ERR_ASM_ARCH, diff --git a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h index 96e2a53a1ff6ff11591eb2a21318b820583cef89..09b2f8d6ef7afacd74297bcef6c5824396feb537 100644 --- a/llvm/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/llvm/include/llvm/MC/MCParser/MCAsmLexer.h @@ -190,10 +190,8 @@ public: AsmToken Tok; MutableArrayRef<AsmToken> Buf(Tok); - size_t ReadCount = peekTokens(Buf, ShouldSkipSpace); - - assert(ReadCount == 1); - (void)ReadCount; + if (peekTokens(Buf, ShouldSkipSpace) != 1) + return AsmToken(AsmToken::Error, nullptr); return Tok; } diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h index 93fca923e5a167f85fecf466743e4766196fa2bf..d62bd4ba257115df6e085732e41aa6bceb73ba3a 100644 --- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h +++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h @@ -209,7 +209,7 @@ public: // Return whether this parser uses assignment statements with equals tokens virtual bool equalIsAsmAssignment() { return true; }; // Return whether this start of statement identifier is a label - virtual bool isLabel(AsmToken &Token) { return true; }; + virtual bool isLabel(AsmToken &Token, bool &valid) { valid = true; return true; }; virtual const MCExpr *applyModifierToExpr(const MCExpr *E, MCSymbolRefExpr::VariantKind, diff --git a/llvm/keystone/ks.cpp b/llvm/keystone/ks.cpp index e38c58b8e6493f459a2e3ce5b7ee6ee268870c14..1602c79be8a01d91f8962a4fcefccec98c53e973 100644 --- a/llvm/keystone/ks.cpp +++ b/llvm/keystone/ks.cpp @@ -132,6 +132,8 @@ const char *ks_strerror(ks_err code) return "Unknown directive (KS_ERR_ASM_DIRECTIVE_UNKNOWN)"; case KS_ERR_ASM_FIXUP_INVALID: return "Invalid fixup (KS_ERR_ASM_FIXUP_INVALID)"; + case KS_ERR_ASM_LABEL_INVALID: + return "Invalid label (KS_ERR_ASM_LABEL_INVALID)"; } } diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 265b24cb847c5e91147012170edc794bd9cbffab..3c6141d5724828c44ad8cae7c9eca5b6375c6220 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -1563,8 +1563,13 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, // See what kind of statement we have. switch (Lexer.getKind()) { case AsmToken::Colon: { - if (!getTargetParser().isLabel(ID)) + bool valid; + if (!getTargetParser().isLabel(ID, valid)) break; + if (!valid) { + Info.KsError = KS_ERR_ASM_LABEL_INVALID; + return true; + } checkForValidSection(); // identifier ':' -> Label. diff --git a/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp b/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp index fe0b26a234ed3bea2f0d9e1b18cba205da55fb7b..9f3a670152a32b83fff5f2407bfe7950de83b7a5 100644 --- a/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp +++ b/llvm/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp @@ -73,7 +73,7 @@ class HexagonAsmParser : public MCTargetAsmParser { MCAsmLexer &getLexer() const { return Parser.getLexer(); } bool equalIsAsmAssignment() override { return false; } - bool isLabel(AsmToken &Token) override; + bool isLabel(AsmToken &Token, bool &valid) override; void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); } bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } @@ -1195,10 +1195,15 @@ bool HexagonAsmParser::parseOperand(OperandVector &Operands) { return splitIdentifier(Operands); } -bool HexagonAsmParser::isLabel(AsmToken &Token) { +bool HexagonAsmParser::isLabel(AsmToken &Token, bool &valid) { + valid = true; MCAsmLexer &Lexer = getLexer(); AsmToken const &Second = Lexer.getTok(); AsmToken Third = Lexer.peekTok(); + if (Third.is(AsmToken::Error)) { + valid = false; + return true; + } StringRef String = Token.getString(); if (Token.is(AsmToken::TokenKind::LCurly) || Token.is(AsmToken::TokenKind::RCurly))