<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I also suspect this to be the cause of this build being broken: <a href="http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/" class="">http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/</a> (I am still reproducing to confirm and extracting a testcase).</div><div class=""><br class=""></div><div class="">- Matthias</div><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 15, 2016, at 11:14 AM, Reid Kleckner via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">This is now firing on code in brotli (a compression library): <a href="http://crbug.com/637864" class="">http://crbug.com/637864</a><div class=""><br class=""></div><div class="">How can we avoid this error? Shouldn't LLVM be responsible for relaxing this into some other code sequence?</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Aug 15, 2016 at 12:57 AM, Prakhar Bahuguna via llvm-commits <span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: prakhar<br class="">
Date: Mon Aug 15 02:57:44 2016<br class="">
New Revision: 278659<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278659&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project?rev=278659&view=rev</a><br class="">
Log:<br class="">
[Thumb] Validate branch target for CBZ/CBNZ instructions.<br class="">
<br class="">
Summary:<br class="">
The assembler currently does not check the branch target for CBZ/CBNZ<br class="">
instructions, which only permit branching forwards with a positive offset. This<br class="">
adds validation for the branch target to ensure negative PC-relative offsets are<br class="">
not encoded into the instruction, whether specified as a literal or as an<br class="">
assembler symbol.<br class="">
<br class="">
Reviewers: rengolin, t.p.northover<br class="">
<br class="">
Subscribers: llvm-commits, rengolin<br class="">
<br class="">
Differential Revision: <a href="https://reviews.llvm.org/D23312" rel="noreferrer" target="_blank" class="">https://reviews.llvm.org/<wbr class="">D23312</a><br class="">
<br class="">
Added:<br class="">
llvm/trunk/test/MC/ARM/thumb-<wbr class="">cb-negative-offsets.s<br class="">
Modified:<br class="">
llvm/trunk/lib/Target/ARM/<wbr class="">AsmParser/ARMAsmParser.cpp<br class="">
llvm/trunk/lib/Target/ARM/<wbr class="">MCTargetDesc/ARMAsmBackend.cpp<br class="">
llvm/trunk/test/MC/ARM/thumb-<wbr class="">diagnostics.s<br class="">
<br class="">
Modified: llvm/trunk/lib/Target/ARM/<wbr class="">AsmParser/ARMAsmParser.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=278659&r1=278658&r2=278659&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/lib/Target/<wbr class="">ARM/AsmParser/ARMAsmParser.<wbr class="">cpp?rev=278659&r1=278658&r2=<wbr class="">278659&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/lib/Target/ARM/<wbr class="">AsmParser/ARMAsmParser.cpp (original)<br class="">
+++ llvm/trunk/lib/Target/ARM/<wbr class="">AsmParser/ARMAsmParser.cpp Mon Aug 15 02:57:44 2016<br class="">
@@ -6684,6 +6684,12 @@ bool ARMAsmParser::<wbr class="">validateInstruction(M<br class="">
return Error(Operands[Op]-><wbr class="">getStartLoc(), "branch target out of range");<br class="">
break;<br class="">
}<br class="">
+ case ARM::tCBZ:<br class="">
+ case ARM::tCBNZ: {<br class="">
+ if (!static_cast<ARMOperand &>(*Operands[2]).<wbr class="">isUnsignedOffset<6, 1>())<br class="">
+ return Error(Operands[2]-><wbr class="">getStartLoc(), "branch target out of range");<br class="">
+ break;<br class="">
+ }<br class="">
case ARM::MOVi16:<br class="">
case ARM::t2MOVi16:<br class="">
case ARM::t2MOVTi16:<br class="">
<br class="">
Modified: llvm/trunk/lib/Target/ARM/<wbr class="">MCTargetDesc/ARMAsmBackend.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp?rev=278659&r1=278658&r2=278659&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/lib/Target/<wbr class="">ARM/MCTargetDesc/<wbr class="">ARMAsmBackend.cpp?rev=278659&<wbr class="">r1=278658&r2=278659&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/lib/Target/ARM/<wbr class="">MCTargetDesc/ARMAsmBackend.cpp (original)<br class="">
+++ llvm/trunk/lib/Target/ARM/<wbr class="">MCTargetDesc/ARMAsmBackend.cpp Mon Aug 15 02:57:44 2016<br class="">
@@ -578,6 +578,11 @@ unsigned ARMAsmBackend::<wbr class="">adjustFixupValue<br class="">
// Offset by 4, and don't encode the low two bits.<br class="">
return ((Value - 4) >> 2) & 0xff;<br class="">
case ARM::fixup_arm_thumb_cb: {<br class="">
+ // CB instructions can only branch to offsets in [0, 126] in multiples of 2<br class="">
+ if (Ctx && ((int64_t)Value < 0 || Value > 0x3e || Value & 1)) {<br class="">
+ Ctx->reportError(Fixup.getLoc(<wbr class="">), "out of range pc-relative fixup value");<br class="">
+ return 0;<br class="">
+ }<br class="">
// Offset by 4 and don't encode the lower bit, which is always 0.<br class="">
// FIXME: diagnose if no Thumb2<br class="">
uint32_t Binary = (Value - 4) >> 1;<br class="">
<br class="">
Added: llvm/trunk/test/MC/ARM/thumb-<wbr class="">cb-negative-offsets.s<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/thumb-cb-negative-offsets.s?rev=278659&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/test/MC/<wbr class="">ARM/thumb-cb-negative-offsets.<wbr class="">s?rev=278659&view=auto</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/test/MC/ARM/thumb-<wbr class="">cb-negative-offsets.s (added)<br class="">
+++ llvm/trunk/test/MC/ARM/thumb-<wbr class="">cb-negative-offsets.s Mon Aug 15 02:57:44 2016<br class="">
@@ -0,0 +1,19 @@<br class="">
+@ RUN: not llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o /dev/null %s 2>&1 | FileCheck %s<br class="">
+@ RUN: not llvm-mc -triple thumbv8m.base-none-eabi -filetype=obj -o /dev/null %s 2>&1 | FileCheck %s<br class="">
+<br class="">
+label0:<br class="">
+ .word 4<br class="">
+<br class="">
+@ CHECK: out of range pc-relative fixup value<br class="">
+ cbz r0, label0<br class="">
+@ CHECK: out of range pc-relative fixup value<br class="">
+ cbnz r0, label0<br class="">
+<br class="">
+@ CHECK: out of range pc-relative fixup value<br class="">
+ cbz r0, label1<br class="">
+@ CHECK: out of range pc-relative fixup value<br class="">
+ cbnz r0, label1<br class="">
+<br class="">
+ .space 1000<br class="">
+label1:<br class="">
+ .word 4<br class="">
<br class="">
Modified: llvm/trunk/test/MC/ARM/thumb-<wbr class="">diagnostics.s<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/thumb-diagnostics.s?rev=278659&r1=278658&r2=278659&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/llvm/trunk/test/MC/<wbr class="">ARM/thumb-diagnostics.s?rev=<wbr class="">278659&r1=278658&r2=278659&<wbr class="">view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- llvm/trunk/test/MC/ARM/thumb-<wbr class="">diagnostics.s (original)<br class="">
+++ llvm/trunk/test/MC/ARM/thumb-<wbr class="">diagnostics.s Mon Aug 15 02:57:44 2016<br class="">
@@ -235,6 +235,23 @@ error: invalid operand for instruction<br class="">
@ CHECK-ERRORS: error: branch target out of range<br class="">
<br class="">
@-----------------------------<wbr class="">------------------------------<wbr class="">-------------------<br class="">
+@ CBZ/CBNZ - out of range immediates for branches<br class="">
+@----------------------------<wbr class="">------------------------------<wbr class="">--------------------<br class="">
+<br class="">
+ cbz r0, #-2<br class="">
+ cbz r0, #0<br class="">
+ cbz r0, #17<br class="">
+ cbnz r0, #126<br class="">
+ cbnz r0, #128<br class="">
+<br class="">
+@ CHECK-ERRORS-V7M: error: branch target out of range<br class="">
+@ CHECK-ERRORS-V7M: error: invalid operand for instruction<br class="">
+@ CHECK-ERRORS-V7M: error: branch target out of range<br class="">
+@ CHECK-ERRORS-V8: error: branch target out of range<br class="">
+@ CHECK-ERRORS-V8: error: invalid operand for instruction<br class="">
+@ CHECK-ERRORS-V8: error: branch target out of range<br class="">
+<br class="">
+@----------------------------<wbr class="">------------------------------<wbr class="">--------------------<br class="">
@ SEV/WFE/WFI/YIELD - are not supported pre v6M or v6T2<br class="">
@-----------------------------<wbr class="">------------------------------<wbr class="">-------------------<br class="">
sev<br class="">
<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></body></html>