[PATCH] D85522: [Loads] Globals are dereferenceable, if offset + size <= sizeof(global).
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 7 06:41:53 PDT 2020
fhahn created this revision.
fhahn added reviewers: nlopes, efriedma, hfinkel, aqjune.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
fhahn requested review of this revision.
Currently we fail to determine whether pointers to globals are
dereferenceable. Unless I am missing something, we can treat constant
expression GEPs as dereferenceable, if all the dereferenced bits fall
within the global's size.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85522
Files:
llvm/lib/Analysis/Loads.cpp
Index: llvm/lib/Analysis/Loads.cpp
===================================================================
--- llvm/lib/Analysis/Loads.cpp
+++ llvm/lib/Analysis/Loads.cpp
@@ -85,6 +85,15 @@
.isMinValue())
return false;
+ // A pointer to a global value is dereferenceable if all dereferenced bits
+ // are within the global's size.
+ if (auto *GV = dyn_cast<GlobalValue>(Base)) {
+ if (((Offset + Size.sextOrTrunc(Offset.getBitWidth())) * 8)
+ .ule(
+ DL.getTypeSizeInBits(GV->getType()->getPointerElementType())))
+ return true;
+ }
+
// If the base pointer is dereferenceable for Offset+Size bytes, then the
// GEP (== Base + Offset) is dereferenceable for Size bytes. If the base
// pointer is aligned to Align bytes, and the Offset is divisible by Align
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85522.283896.patch
Type: text/x-patch
Size: 847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200807/332215be/attachment.bin>
More information about the llvm-commits
mailing list