[llvm-dev] GEP with a null pointer base
Chris Lattner via llvm-dev
llvm-dev at lists.llvm.org
Thu Jul 6 11:52:42 PDT 2017
> On Jul 6, 2017, at 11:06 AM, Kaylor, Andrew via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> I've got a problem that I would like some input on. The problem basically boils down to a program that I am compiling, whose source I don't control, doing something like this:
> p = (char*)0 + n
> 3) Have the front end recognize this particular idiom and translate it directly as inttoptr.
> We like the first solution best. The second "solution" is basically a punt. It does away with the immediate problem but leaves the code basically working by chance. I think the third solution is incomplete, because it relies on the front end being able to detect the use of a null pointer whereas that might not emerge until a few basic optimizations have been performed.
> I was hoping to get some more input on this matter before proceeding.
Personally, I’d prefer #3 for two reasons:
- This is a very C specific weirdness, so putting it into the frontend makes sense.
- This is really about supporting a specific (horrible :-) idiom. It makes sense to recognize this in the frontend, which is close to the idiom truth, rather than in the optimizer, which is run multiple times and sees code after being transformed.
I see this as pretty similar to the analogous hacks we do to support broken offsetof idioms.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev