[all-commits] [llvm/llvm-project] f4c546: [instcombine] Infer alignment for aligned_alloc wi...

Philip Reames via All-commits all-commits at lists.llvm.org
Mon Jan 10 08:49:05 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f4c54683d684100fffd307ddf773078429b83442
      https://github.com/llvm/llvm-project/commit/f4c54683d684100fffd307ddf773078429b83442
  Author: Philip Reames <listmail at philipreames.com>
  Date:   2022-01-10 (Mon, 10 Jan 2022)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    M llvm/test/Transforms/InstCombine/deref-alloc-fns.ll

  Log Message:
  -----------
  [instcombine] Infer alignment for aligned_alloc with potentially zero size

This change removes a previous restriction where we had to prove the allocation performed by aligned_alloc was non-zero in size before using the align parameter to annotate the result.  I believe this was conservatism around the C11 specification of this routine which allowed UB when size was not a multiple of alignment, but if so, it was a partial one at best.  (ex: align 32, size 16  was equally UB, but not restricted)  The spec has since been clarified to require nullptr return, not UB.

A nullptr - the documented return for this function on failure for all cases after UB mentioned above was removed - is trivially aligned for any power of two.  This isn't totally new behavior even for this transform, we'd previously annotate potentially failing allocs (e.g. huge sizes) meaning we were putting align on potentially null pointers anyways.  This change simpy does the same for all failure modes.


  Commit: 332642e693509947d33ec5dbcbdc3fcf149f4a87
      https://github.com/llvm/llvm-project/commit/332642e693509947d33ec5dbcbdc3fcf149f4a87
  Author: Philip Reames <listmail at philipreames.com>
  Date:   2022-01-10 (Mon, 10 Jan 2022)

  Changed paths:
    M llvm/test/Transforms/InstCombine/deref-alloc-fns.ll

  Log Message:
  -----------
  Add test coverage for D116851


Compare: https://github.com/llvm/llvm-project/compare/4b5d59ffd073...332642e69350


More information about the All-commits mailing list