<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54395>54395</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            DynamicAllocaLayout of ASan isn't at stack bottom when compile with -O2 flag
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          LeoneChen
      </td>
    </tr>
</table>

<pre>
    There is a `FunctionStackPoisoner::createDynamicAllocasInitStorage` function in AddressSanitizer, and I think DynamicAllocaLayout is allocated at function begin to ensure it's at stack bottom, which is used at `IRB.CreateCall(
        AsanAllocasUnpoisonFunc,
        {IRB.CreateLoad(IntptrTy, DynamicAllocaLayout), DynamicAreaPtr});` to clean up the shadow of stack top to stack bottom.
```cpp
void FunctionStackPoisoner::createDynamicAllocasInitStorage() {
  BasicBlock &FirstBB = *F.begin();
  IRBuilder<> IRB(dyn_cast<Instruction>(FirstBB.begin()));
  DynamicAllocaLayout = IRB.CreateAlloca(IntptrTy, nullptr);
  IRB.CreateStore(Constant::getNullValue(IntptrTy), DynamicAllocaLayout);
  DynamicAllocaLayout->setAlignment(Align(32));
}
```

But when I use ASan and compile tested app on -O2 flag, `DynamicAllocaLayout` will be optimized and not at stack bottom any more. Do I make some mistakes? If not, how to fix it?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVF1vmzAU_TXwYhWBSUh44AGSIUWqtmrd9joZ24AXYyNsmmW_ftcOXZq26ssiK2Bf33PPuR80mp2Lbz2fOBIGERRkcT0raoVWj5bQ44MWRis-BWkJi06cWL4_KzIIWkqpKTEHJeyj1RPpODijdvFGQqGSsYkb80jgivgDIHiHiGLogGwv1BHdAN2Ts56tZ-H3ljNE7BWv4R1AWo24MrOjawO8Me6KcURRo63Vgwtx6gXtHdBsLhjA6_C1inae_Q7gA7wN4n0Ql2j5lYaoRc93NXrNLg2Adnsv2FRXpHtNGCAdlB3t9O3sQr-jKMD5Swt4Ptgp2OzdeVq5lIEmKjlRaB4hMRyZnjB9QrpdlFk9ujsvZUYXWuB9WXQcLydPWjD0HxWExODcyXzWXREjaAX3jijAWS0mY6sKBeketmUd-apcvJyaxQlyNAvJXNBdkH5ye7jDzuonhLNweFDGTrMnCXawLcA3eJd1RX2vXRyRa0Uuplc1UbOUsHnDcPFxyp3unQZORNlLnjpuP4PfDyJnfoOXf1DmD6negVDDbSlFpwYOcfDWv8Mzxa-0uva4LfCy9f8V6D71XMEcQYejEubLjxXVwygkR5YbPzzjiGBu7r5g1ErSOd4A9B516MGTkBJGDOnRigFmlXlEpe3rAYPzMxogZRHaa2AwkCN0rB44GgTcO3ITpDU6tM7Xheyhk6F5W_HbTWxah6xIWZ7mJLTCSl68V1TofC9KGMjO5i0FL_5Z7UnY_p_IcJ5k0Vs7GldGXMPqwD43EXXfhlrKp-fH3TjpX5wCyVoYMwNvXK9Xab4O-2LbJG2brxK6IWyFt3mypUnME5Y1fJukBIeSNFyaIlhDX2PFT8hDwHuw3oeiwDHGcZpk8TbdxHmUZBlt1s26ZTTLmlUbrGI-ECEjxyPSUxdOhafUzJ0Bo4RMmquRGAN9wrkPB_hktr2einsOY72DVIQ-eOHJ_wW_iOEm">