[llvm-commits] [PATCH] Bug 889: clean up dodgy casts between Value** and Constant**

Jay Foad jay.foad at gmail.com
Wed Jan 12 07:54:47 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=889

This bug is about removing virtual methods from Value and its subclasses.

While playing with fixes for this bug, I found a few C-style casts
from Value** to Constant** or vice versa. This works at the moment,
because a static_cast from Constant* to Value* doesn't have to adjust
the "this" pointer, but it's not safe in general. In particular, it
won't work if Constant has virtual methods but Value doesn't.

The reason for the casts' existence is that there are various methods
to do with creating getElementPtrs which take either an array of
Values or an array of Constants, but there isn't much consistency --
some methods can only take an array of Values, and some can only take
an array of Constants.

This patch ensures that there are two overloads for each such method:
one taking an array of Values, and one taking an array of Constants.
By calling the appropriate version in each case, we can avoid the
casts.

Tested with "make check". OK to commit?

Thanks,
Jay.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-dodgy-casts
Type: application/octet-stream
Size: 13171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110112/97490b28/attachment.obj>


More information about the llvm-commits mailing list