<div dir="ltr"><div>ToT clang (correctly) errors-out when the target is armv7 (thumb2) and the program it's compiling has an ARM mode file-level inline assembly statement: </div><div><br></div><p style="margin:0px;font-size:11px;font-family:Menlo">
$ cat test2.c</p><p style="margin:0px;font-size:11px;font-family:Menlo">
</p><p style="margin:0px;font-size:11px;font-family:Menlo">__asm__ ("stmib sp, {r0-r14};");</p><p style="margin:0px;font-size:11px;font-family:Menlo"><br></p><p style="margin:0px;font-size:11px;font-family:Menlo">
$ clang -arch armv7  -S -o - test2.c  <br></p><div>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__text,regular,pure_instructions</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.ios_version_min 5, 0</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__textcoal_nt,coalesced,pure_instructions</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__const_coal,coalesced</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__picsymbolstub4,symbol_stubs,none,16</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__StaticInit,regular,pure_instructions</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.section<span class="" style="white-space:pre">  </span>__TEXT,__cstring,cstring_literals</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><span class="" style="white-space:pre">        </span>.syntax unified</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">                                        @ Start of file scope inline assembly</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"><b><inline asm>:1:1: </b><span style="color:rgb(195,55,32)"><b>error: </b></span><b>instruction requires: arm-mode</b></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">stmib sp, {r0-r14};</p></div><div><br></div><div>However, when the .s file is generated with -no-integrated-as first, and then assembled later, clang completes assembling the .s file without any errors.</div>
<div><br></div><div><p style="margin:0px;font-size:11px;font-family:Menlo">$ clang -arch armv7  -S -o test2.s -no-integrated-as test2.c  </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">$ clang -arch armv7  test2.s -c</p><p style="margin:0px;font-size:11px;font-family:Menlo"><br></p><div>The attached patch fixes this discrepancy in clang's behavior by emitting directive ".code 16" before global inline-asm instructions when the target is thumb. Without this directive, clang assembles the global inline-asm instruction in ARM mode, since the assembler always starts in ARM mode and stays in that mode until it sees directives that instruct it to switch to thumb.</div>
<div><br></div><div><rdar://problem/17757232><br></div><div><br></div></div></div>