[LLVMdev] new warnings

Nick Lewycky nicholas at mxc.ca
Wed Apr 8 20:19:14 PDT 2009

Jeffrey Yasskin wrote:
> On Tue, Apr 7, 2009 at 8:31 PM, Nick Lewycky <nicholas at mxc.ca> wrote:
>> Mike Stump wrote:
>>> On Apr 7, 2009, at 6:02 PM, Tanya M. Lattner wrote:
>>>> Can you please just respond to the specific patch on llvm-commits
>>>> instead
>>>> of emailing llvm-dev?
>>> Don't happen to know which checkin caused it...
>> Given that there's only ever been one checkin to this file, it can't be
>> that hard. :)
>> 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, because MDNode* is a different type from Constant*. In the C++0X
> draft, it's in section 3.10:
> If a program attempts to access the stored value of an object through
> an lvalue of other than one of the
> following types the behavior is undeļ¬ned

Thanks. I knew about the 'Derived** is incompatible with Base**' rule 
for containers and why you can't just downcast to pass to a callee (it 
might try to insert a Derived2*) but for no good reason thought that 
different rules applied to type aliasing.

> I'm not sure about LLVM's conventions, but I think it's a good idea to
> avoid C-style cases in favor of the more specific (but longer) C++
> ones. Then the compiler will tell you about dangerous casts by making
> you use reinterpret_cast or const_cast to do them. And
> reinterpret_cast is only safe when going to (or sometimes from) char*
> or intptr_t.

Yes, and in this case neither dynamic_cast nor static_cast would compile.

Sadly, I actually did think about it and wrongly conclude that what I 
was doing was okay. Apparently I daydream new paragraphs in the C++ 
standard now. ;-)


More information about the llvm-dev mailing list