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

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 14:43:35 PDT 2019


asbirlea marked an inline comment as done.
asbirlea 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);
----------------
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).


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