[PATCH] D33574: PPC: Verify that branch fixups fit within the range.
Kyle Butt via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 15:59:12 PDT 2017
iteratee updated this revision to Diff 104951.
iteratee set the repository for this revision to rL LLVM.
iteratee added a comment.
Herald added a subscriber: sanjoy.
All the checks use unreachable now.
Repository:
rL LLVM
https://reviews.llvm.org/D33574
Files:
lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
Index: lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
===================================================================
--- lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
+++ lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
@@ -35,10 +35,24 @@
case PPC::fixup_ppc_nofixup:
return Value;
case PPC::fixup_ppc_brcond14:
+ if (static_cast<int64_t>(Value) >= 0 && Value > 0x7fff)
+ llvm_unreachable("Cond branch target overflow.");
+ else if (static_cast<int64_t>(Value) < 0 && -Value > 0x8000)
+ llvm_unreachable("Cond branch target underflow.");
+ return Value & 0xfffc;
case PPC::fixup_ppc_brcond14abs:
+ if(Value > 0xffff)
+ llvm_unreachable("Cond branch absolute target overflow.");
return Value & 0xfffc;
case PPC::fixup_ppc_br24:
+ if (static_cast<int64_t>(Value) >= 0 && Value > 0x1ffffff)
+ llvm_unreachable("Branch target overflow.");
+ else if (static_cast<int64_t>(Value) < 0 && -Value > 0x2000000)
+ llvm_unreachable("Branch target underflow.");
+ return Value & 0x3fffffc;
case PPC::fixup_ppc_br24abs:
+ if(Value > 0x3ffffff)
+ llvm_unreachable("Branch absolute target overflow.");
return Value & 0x3fffffc;
case PPC::fixup_ppc_half16:
return Value & 0xffff;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33574.104951.patch
Type: text/x-patch
Size: 1269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170630/352cc7cb/attachment.bin>
More information about the llvm-commits
mailing list