[llvm] r366175 - [RISCV] Fix a potential issue in shouldInsertFixupForCodeAlign()

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 15 21:37:19 PDT 2019


Author: asb
Date: Mon Jul 15 21:37:19 2019
New Revision: 366175

URL: http://llvm.org/viewvc/llvm-project?rev=366175&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Modified: llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp?rev=366175&r1=366174&r2=366175&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp Mon Jul 15 21:37:19 2019
@@ -329,11 +329,10 @@ bool RISCVAsmBackend::shouldInsertFixupF
   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();




More information about the llvm-commits mailing list