[PATCH] D76965: [FunctionAttrs][Mem2Reg] Handle Alloca passed as function call operand with function attributes

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 28 00:30:31 PDT 2020


jdoerfert added a comment.

> Allow mem2reg to replace an Alloca used as a nocapture and inaccessiblememonly/readnone function call operand with undef

This is not sound. Take the following example

  int foo(int *a) {
    return a & 31;  // or "worse": if(a&32) return 1; else return 0;
  }
  int is_stack_aligned() {
     int stack;
     return foo(&stack);
  }

Replacing stack with undef will introduce poison or UB where there was none before.
It also breaks if you have something like:

  int is_same(int *a, short *b) {
    return a == b;
  }
  int return_true() {
    int Stack;
    return is_same(&Stack, (short*)&Stack);
  }



---

That said, I think what we can do is "privatize" the pointer under more strict requirements than you have here. I was hoping to do that in `AAPrivatizablePtrImpl` at some point but I now think the requirements we have there are still a little too weak. I'll have to think about this one a bit. (Btw. you should really consider implementing some of these in the Attributor instead. It should be way more powerful there.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76965/new/

https://reviews.llvm.org/D76965





More information about the llvm-commits mailing list