[PATCH] D52258: Fix for bug 34002

Maya Madhavan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 18 21:39:48 PDT 2018


maya.madhavan created this revision.
maya.madhavan added a reviewer: craig.topper.
Herald added a reviewer: javed.absar.
Herald added a subscriber: llvm-commits.
maya.madhavan added a comment.

**Verification**

1. Rebuilt with changes (LogAfterChange.log)
2. make check (in progress)


When a label is encountered while an open 'it' block is under construction (under construction because more conditional instructions can be added to it), the gathered block should be emitted before the label is emitted.
Due to the location from where the onLabelParsed function was being called, the label is emitted first and the 'it' block flushed after, resulting in incorrect code.


Repository:
  rL LLVM

https://reviews.llvm.org/D52258

Files:
  include/llvm/MC/MCParser/MCTargetAsmParser.h
  lib/MC/MCParser/AsmParser.cpp
  lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  test/MC/ARM/implicit-it-generation.s


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
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<NearMissInfo> &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: 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: 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52258.166067.patch
Type: text/x-patch
Size: 2447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180919/6db59dab/attachment.bin>


More information about the llvm-commits mailing list