summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAlex Bradbury <asb@lowrisc.org>2019-07-16 04:40:25 +0000
committerAlex Bradbury <asb@lowrisc.org>2019-07-16 04:40:25 +0000
commitbb479ca311958120279cf2c21da3a9d8d06ceb17 (patch)
tree390c9ac810d655d3f6ec773744bef258ddecde08 /llvm/lib
parente9ad0cf6cf79cfa5f8ce99db0f7161e110850011 (diff)
downloadbcm5719-llvm-bb479ca311958120279cf2c21da3a9d8d06ceb17.tar.gz
bcm5719-llvm-bb479ca311958120279cf2c21da3a9d8d06ceb17.zip
[RISCV] Avoid overflow when determining number of nops for code align
RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign() assumed that the align specified would be greater than or equal to the minimum nop length, but that is not always the case - for example if a user specifies ".align 0" in assembly. Differential Revision: https://reviews.llvm.org/D63274 Patch by Edward Jones. llvm-svn: 366176
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 821ac2033c9..ee5f760ebcb 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -313,8 +313,12 @@ bool RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
bool HasStdExtC = STI.getFeatureBits()[RISCV::FeatureStdExtC];
unsigned MinNopLen = HasStdExtC ? 2 : 4;
- Size = AF.getAlignment() - MinNopLen;
- return true;
+ if (AF.getAlignment() <= MinNopLen) {
+ return false;
+ } else {
+ Size = AF.getAlignment() - MinNopLen;
+ return true;
+ }
}
// We need to insert R_RISCV_ALIGN relocation type to indicate the
OpenPOWER on IntegriCloud