Skip to content

Commit e9ad0cf

Browse files
committed
[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
1 parent ef8577e commit e9ad0cf

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,10 @@ bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
329329
if (!STI.getFeatureBits()[RISCV::FeatureRelax])
330330
return false;
331331

332-
// Calculate total Nops we need to insert.
332+
// Calculate total Nops we need to insert. If there are none to insert
333+
// then simply return.
333334
unsigned Count;
334-
shouldInsertExtraNopBytesForCodeAlign(AF, Count);
335-
// No Nop need to insert, simply return.
336-
if (Count == 0)
335+
if (!shouldInsertExtraNopBytesForCodeAlign(AF, Count) || (Count == 0))
337336
return false;
338337

339338
MCContext &Ctx = Asm.getContext();

0 commit comments

Comments
 (0)