[PATCH] D65417: [SCCP] Update condition to avoid overflow.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 14:46:48 PDT 2019


lebedev.ri marked an inline comment as done.
lebedev.ri added inline comments.


================
Comment at: lib/Analysis/ConstantFolding.cpp:551
   // If we're not accessing anything in this constant, the result is undefined.
-  if (Offset >= InitializerSize)
+  if (Offset + BytesLoaded <= 0)
     return UndefValue::get(IntType);
----------------
asbirlea wrote:
> lebedev.ri wrote:
> > This check looks suspicious to me.
> > I'd expect this to be `if (Offset + BytesLoaded >= InitializerSize)`,
> > this way we are checking that `BytesLoaded` bytes lies within the global.
> If `Offset` can be a negative value, it's possible to get an OOB access when `Offset + BytesLoaded <= 0`.  
> We can also get an OOB access `if (Offset + BytesLoaded >= InitializerSize)`, but the two checks seem orthogonal given this section of code (I'm not familiar with the larger scope of this code).
Okay, sounds plausible.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65417/new/

https://reviews.llvm.org/D65417





More information about the llvm-commits mailing list