Index: include/llvm/MC/MCParser/MCTargetAsmParser.h =================================================================== --- include/llvm/MC/MCParser/MCTargetAsmParser.h +++ include/llvm/MC/MCParser/MCTargetAsmParser.h @@ -476,6 +476,9 @@ return nullptr; } + // For actions that have to be performed before a label is emitted + virtual void doBeforeLabelEmit(MCSymbol *Symbol) {} + virtual void onLabelParsed(MCSymbol *Symbol) {} /// Ensure that all previously parsed instructions have been emitted to the Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -1808,6 +1808,8 @@ Lex(); } + getTargetParser().doBeforeLabelEmit(Sym); + // Emit the label. if (!getTargetParser().isParsingInlineAsm()) Out.EmitLabel(Sym, IDLoc); Index: lib/Target/ARM/AsmParser/ARMAsmParser.cpp =================================================================== --- lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -631,6 +631,8 @@ void ReportNearMisses(SmallVectorImpl &NearMisses, SMLoc IDLoc, OperandVector &Operands); + void doBeforeLabelEmit(MCSymbol *Symbol) override; + void onLabelParsed(MCSymbol *Symbol) override; }; @@ -9443,6 +9445,12 @@ return false; } +void ARMAsmParser::doBeforeLabelEmit(MCSymbol *Symbol) { + // We need to flush the current implicit IT block on a label, because it is + // not legal to branch into an IT block. + flushPendingInstructions(getStreamer()); +} + void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) { // We need to flush the current implicit IT block on a label, because it is // not legal to branch into an IT block. Index: test/MC/ARM/implicit-it-generation.s =================================================================== --- test/MC/ARM/implicit-it-generation.s +++ test/MC/ARM/implicit-it-generation.s @@ -82,6 +82,19 @@ @ CHECK: it eq @ CHECK: addeq +@ Ensure label encountered within range of an IT block is emitted after the IT block is flushed + .section test6a +@ CHECK-LABEL: test6a + beq .chk_done + adchs r0, r0, #0 +.chk_done: + adds r0, r0, r4 +@ CHECK: beq +@ CHECK: it hs +@ CHECK: adchs +@ CHECK: .chk_done +@ CHECK: adds + @ Flush on a section-change directive .section test7a @ CHECK-LABEL: test7a