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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
The reasoning looks good, though the case when offset + size overflows doesn't seem to be considered.
It may be a silly question, but can lifetime.end intrinsics be applied to global variables, too?
LangRef isn't clear about this, but it makes sense to say that lifetime.end only works for alloca/mallocs IMO.
I'm not sure I understand why you need a special case here. I think getPointerDereferenceableBytes() and isAligned() should handle global variables without any additional help.
If this does make a difference, it should be possible to write a testcase using LICM or something like that.
IIRC, not all globals are dereferenceable and we have to look at the linkage. Could be wrong though.
This needs a test for sure.
Why * 8 isn't size in bytes too?
Shouldn't we handle gep+global in Value::getPointerDereferenceableBytes instead, that should make this unnecessary, right?
You are right, this is already handled, I was just using isDereferenceablePointer with the wrong type, which was why it didn't work initially. Sorry for the noise, this seems not needed after all!
clang-tidy: warning: 'auto *GV' can be declared as 'const auto *GV' [llvm-qualified-auto]
not useful