[LLVMdev] new warnings

John McCall
Wed, 08 Apr 2009 17:28:49 -0000

On Apr 7, 2009, at 8:31 PM, Nick Lewycky wrote:
> But I'm not sure what it's complaining about. MDNode isa Constant,
> 'n1'
> isa MDNode*, hence &n1 isa MDNode**.  Casting that to Constant**
> breaks strict-aliasing rules? Really?

Yes.  Constant* is not the same type as MDNode*, ergo loading from an
MDNode** as if it were a Constant** is an aliasing violation.  It's
also just a bad idea for several practical reasons:
1.  C++ subtyping is coercive, i.e. it's not necessarily true that
converting an MDNode* to a Constant* is a no-op.  It probably is in
this case, of course, or the code just wouldn't work.
2.  Even if the coercion is a no-op, that cast can easily break the
type system if you, say, assign an arbitrary Constant* to the
Constant**.

John.