aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Bradbury <asb@lowrisc.org>2019-07-16 04:37:19 +0000
committerAlex Bradbury <asb@lowrisc.org>2019-07-16 04:37:19 +0000
commite9ad0cf6cf79cfa5f8ce99db0f7161e110850011 (patch)
treeda6f65a6da00fdcd6616220dc359bb758709ba71
parentef8577ef98717c1c6a66293de3b2cc0f09e8c3ff (diff)
downloadllvm-e9ad0cf6cf79cfa5f8ce99db0f7161e110850011.zip
llvm-e9ad0cf6cf79cfa5f8ce99db0f7161e110850011.tar.gz
llvm-e9ad0cf6cf79cfa5f8ce99db0f7161e110850011.tar.bz2
[RISCV] Fix a potential issue in shouldInsertFixupForCodeAlign()
The bool result of shouldInsertExtraNopBytesForCodeAlign() is not checked but the returned nop count is unconditionally read even though it could be uninitialized. Differential Revision: https://reviews.llvm.org/D63285 Patch by Edward Jones. llvm-svn: 366175
-rw-r--r--llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index db25efb..821ac20 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -329,11 +329,10 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
if (!STI.getFeatureBits()[RISCV::FeatureRelax])
return false;
- // Calculate total Nops we need to insert.
+ // Calculate total Nops we need to insert. If there are none to insert
+ // then simply return.
unsigned Count;
- shouldInsertExtraNopBytesForCodeAlign(AF, Count);
- // No Nop need to insert, simply return.
- if (Count == 0)
+ if (!shouldInsertExtraNopBytesForCodeAlign(AF, Count) || (Count == 0))
return false;
MCContext &Ctx = Asm.getContext();