Fix textual emission of label instructions in ARM assembler.

The integrated ARM assembler was incorrectly assuming that an
(instruction) label defines a corresponding assembler instruction.
Therefore, placement into the buffer was incorrect.

This CL fixes this mistake. This fixes assembler translator problems
with ARM branch, movw, and movt instructions.

BUG= https://bugs.chromium.org/p/nativeclient/issues/detail?id=4334
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/1430973003 .
diff --git a/src/IceInstARM32.cpp b/src/IceInstARM32.cpp
index 94ea762..dd92097 100644
--- a/src/IceInstARM32.cpp
+++ b/src/IceInstARM32.cpp
@@ -842,8 +842,6 @@
 }
 
 void InstARM32Br::emitIAS(const Cfg *Func) const {
-  if (!Func->getContext()->getFlags().getAllowUnsafeIas())
-    return emitUsingTextFixup(Func);
   auto *Asm = Func->getAssembler<ARM32::AssemblerARM32>();
   if (Label) {
     Asm->b(Asm->getOrCreateLocalLabel(Label->getNumber()), getPredicate());
@@ -923,6 +921,10 @@
 void InstARM32Label::emit(const Cfg *Func) const {
   if (!BuildDefs::dump())
     return;
+  // A label is not really an instruction. Hence, we need to fix the
+  // emitted text size.
+  if (auto *Asm = Func->getAssembler<ARM32::AssemblerARM32>())
+    Asm->decEmitTextSize(InstSize);
   Ostream &Str = Func->getContext()->getStrEmit();
   Str << getName(Func) << ":";
 }
@@ -1025,8 +1027,6 @@
 }
 
 template <> void InstARM32Movw::emitIAS(const Cfg *Func) const {
-  if (!Func->getContext()->getFlags().getAllowUnsafeIas())
-    return emitUsingTextFixup(Func);
   assert(getSrcSize() == 1);
   auto *Asm = Func->getAssembler<ARM32::AssemblerARM32>();
   Asm->movw(getDest(), getSrc(0), getPredicate());
@@ -1053,8 +1053,6 @@
 }
 
 template <> void InstARM32Movt::emitIAS(const Cfg *Func) const {
-  if (!Func->getContext()->getFlags().getAllowUnsafeIas())
-    return emitUsingTextFixup(Func);
   assert(getSrcSize() == 2);
   auto *Asm = Func->getAssembler<ARM32::AssemblerARM32>();
   Asm->movt(getDest(), getSrc(1), getPredicate());
diff --git a/tests_lit/assembler/arm32/branch-simple.ll b/tests_lit/assembler/arm32/branch-simple.ll
index 4f67cca..fb4a645 100644
--- a/tests_lit/assembler/arm32/branch-simple.ll
+++ b/tests_lit/assembler/arm32/branch-simple.ll
@@ -12,12 +12,12 @@
 ; RUN:   --args -Om1 | FileCheck %s --check-prefix=DIS
 
 ; Compile using integrated assembler.
-; RUN: %p2i --filetype=iasm -i %s --target=arm32 --args -Om1 -unsafe-ias \
+; RUN: %p2i --filetype=iasm -i %s --target=arm32 --args -Om1 \
 ; RUN:   | FileCheck %s --check-prefix=IASM
 
 ; Show bytes in assembled integrated code.
 ; RUN: %p2i --filetype=iasm -i %s --target=arm32 --assemble --disassemble \
-; RUN:   --args -Om1 -unsafe-ias | FileCheck %s --check-prefix=DIS
+; RUN:   --args -Om1 | FileCheck %s --check-prefix=DIS
 
 define internal void @simple_uncond_branch() {
 ; DIS-LABEL: 00000000 <simple_uncond_branch>:
diff --git a/tests_lit/assembler/arm32/global-load-store.ll b/tests_lit/assembler/arm32/global-load-store.ll
index cb972d9..3f7f6a7 100644
--- a/tests_lit/assembler/arm32/global-load-store.ll
+++ b/tests_lit/assembler/arm32/global-load-store.ll
@@ -11,12 +11,12 @@
 ; RUN:   --args -O2 | FileCheck %s --check-prefix=DIS
 
 ; Compile using integrated assembler.
-; RUN: %p2i --filetype=iasm -i %s --target=arm32 --args -O2 -unsafe-ias \
+; RUN: %p2i --filetype=iasm -i %s --target=arm32 --args -O2 \
 ; RUN:   | FileCheck %s --check-prefix=IASM
 
 ; Show bytes in assembled integrated code.
 ; RUN: %p2i --filetype=iasm -i %s --target=arm32 --assemble --disassemble \
-; RUN:   --args -O2 -unsafe-ias | FileCheck %s --check-prefix=DIS
+; RUN:   --args -O2 | FileCheck %s --check-prefix=DIS
 
 @filler = internal global [128 x i8] zeroinitializer, align 4
 
diff --git a/tests_lit/assembler/arm32/sdiv.ll b/tests_lit/assembler/arm32/sdiv.ll
index e7261a9..2aab7dd7 100644
--- a/tests_lit/assembler/arm32/sdiv.ll
+++ b/tests_lit/assembler/arm32/sdiv.ll
@@ -14,11 +14,11 @@
 
 ; Compile using integrated assembler.
 ; RUN: %p2i --filetype=iasm -i %s --target=arm32 --args -O2 -mattr=hwdiv-arm \
-; RUN:   -unsafe-ias | FileCheck %s --check-prefix=IASM
+; RUN:   | FileCheck %s --check-prefix=IASM
 
 ; Show bytes in assembled integrated code.
 ; RUN: %p2i --filetype=iasm -i %s --target=arm32 --assemble --disassemble \
-; RUN:   --args -O2 -mattr=hwdiv-arm -unsafe-ias \
+; RUN:   --args -O2 -mattr=hwdiv-arm \
 ; RUN:   | FileCheck %s --check-prefix=DIS
 
 define internal i32 @SdivTwoRegs(i32 %a, i32 %b) {
diff --git a/tests_lit/assembler/arm32/udiv.ll b/tests_lit/assembler/arm32/udiv.ll
index 2dd0310..9fb2b43 100644
--- a/tests_lit/assembler/arm32/udiv.ll
+++ b/tests_lit/assembler/arm32/udiv.ll
@@ -14,11 +14,11 @@
 
 ; Compile using integrated assembler.
 ; RUN: %p2i --filetype=iasm -i %s --target=arm32 --args -O2 -mattr=hwdiv-arm \
-; RUN:   -unsafe-ias | FileCheck %s --check-prefix=IASM
+; RUN:   | FileCheck %s --check-prefix=IASM
 
 ; Show bytes in assembled integrated code.
 ; RUN: %p2i --filetype=iasm -i %s --target=arm32 --assemble --disassemble \
-; RUN:   --args -O2 -mattr=hwdiv-arm -unsafe-ias \
+; RUN:   --args -O2 -mattr=hwdiv-arm \
 ; RUN:   | FileCheck %s --check-prefix=DIS
 
 define internal i32 @UdivTwoRegs(i32 %a, i32 %b) {