[PATCH] D28494: Make `@llvm.objectsize` more conservative with null pointers.

George Burgess IV via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 15:17:43 PST 2017


george.burgess.iv created this revision.
george.burgess.iv added reviewers: echristo, sanjoy, mehdi_amini.
george.burgess.iv added a subscriber: llvm-commits.
Herald added a reviewer: tstellarAMD.
Herald added subscribers: nhaehnle, arsenm.

In pursuit of fixing https://llvm.org/bugs/show_bug.cgi?id=23277, we'd like `@llvm.objectsize` to treat null pointers as opaque/unknown pointers, rather than treating them as pointers to 0 bytes of memory. This patch adds an argument to `@llvm.objectsize` that lets us control how `@llvm.objectsize` treats `null`.

As Sanjoy noted in http://lists.llvm.org/pipermail/llvm-dev/2017-January/108623.html, we can also make a backwards-incompatible change that just makes `@llvm.objectsize` adopt this null-is-unknown-size behavior in all cases. I dunno what the better option is here, but we could easily do that by throwing basically half of this patch out (all except for the changes to MemoryBuiltins).

If we want the absolutely-minimal patch, we could cut the changes to MemoryBuiltins.cpp down to a few lines (just returning `unknown()` in `ObjectSizeOffsetVisitor::visitConstantPointerNull`). Doing so would cause us to delay lowering the calls to `@llvm.objectsize` as much as possible, which may inhibit some optimizations.

There's a handful of tests with @llvm.objectsize in them that this patch doesn't update, since they don't CHECK for objectsize with a specific set of arguments. If we want, I'm happy to update them to use the three-arg version, as well.

I wasn't entirely sure who to poke with this, since I can't find a code owner for intrinsics. :)


https://reviews.llvm.org/D28494

Files:
  docs/LangRef.rst
  include/llvm/Analysis/MemoryBuiltins.h
  include/llvm/IR/Intrinsics.td
  lib/Analysis/MemoryBuiltins.cpp
  lib/IR/AutoUpgrade.cpp
  lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
  lib/Transforms/Instrumentation/AddressSanitizer.cpp
  test/Assembler/auto_upgrade_intrinsics.ll
  test/CodeGen/AMDGPU/promote-alloca-mem-intrinsics.ll
  test/Transforms/InstCombine/memset_chk-1.ll
  test/Transforms/InstCombine/objsize.ll
  test/Transforms/InstCombine/stpcpy_chk-1.ll
  test/Transforms/InstCombine/strcpy_chk-1.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28494.83710.patch
Type: text/x-patch
Size: 31521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170109/58689216/attachment.bin>


More information about the llvm-commits mailing list