[basicaa] Fix a latent bug in isGEPBaseAtNegativeOffset
authorPhilip Reames <listmail@philipreames.com>
Wed, 3 Mar 2021 16:43:32 +0000 (08:43 -0800)
committerPhilip Reames <listmail@philipreames.com>
Wed, 3 Mar 2021 16:43:32 +0000 (08:43 -0800)
commite6e5ef40cbc239754003c93c46df644dad8a8272
treea832264246f96ec7497cbcc0df3a6d66e892609b
parentdd9922c487f34896f142778d4caa55a7d54c3cf4
[basicaa] Fix a latent bug in isGEPBaseAtNegativeOffset

This was pointed out in review of D97520 by Nikita, but existed in the original code as well.

The basic issue is that a decomposed GEP expression describes (potentially) more than one getelementptr.  The "inbounds" derived UB which justifies this aliasing rule requires that the entire offset be composed of "inbounds" geps.  Otherwise, as can be seen in the recently added and changes in this patch test, we can end up with a large commulative offset with only a small sub-offset actually being "inbounds".  If that small sub-offset lies within the object, the result was unsound.

We could potentially be fancier here, but for the moment, simply be conservative when any of the GEPs parsed aren't inbounds.
llvm/include/llvm/Analysis/BasicAliasAnalysis.h
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/BasicAA/negoffset.ll