[cfe-dev] Fixing selector types on the GNU runtime

David Chisnall csdavec at swansea.ac.uk
Sun Jan 18 15:01:08 PST 2009


On 18 Jan 2009, at 20:06, Chris Lattner wrote:

> On Jan 18, 2009, at 8:14 AM, David Chisnall wrote:
>> I've also included some fixes in this patch which turn NULL into  
>> (void*)0 when it is used as a sentinel in variadic functions.  This  
>> gets rid of a load of warnings when compiling and stops it breaking  
>> on 64-bit architectures.
>
> Why are you getting this?  There are tons of other places that pass  
> NULL as a sentinel.  Is NULL getting defined incorrectly for that  
> file?  NULL needs to be a pointer type, so it should be fine on 64- 
> bit systems.  Passing a raw "0" would not be.

NULL is #defined as 0 for C++ ((void*)0 for C) on FreeBSD.  I get  
missing sentinels in a huge numbers of missing sentinel errors when  
building LLVM.  When I first came across this, I assumed it was a bug  
in the implementation, but checking the spec apparently it can't be a  
void* because C++ doesn't allow the type escaping here.  In other  
places I've worked around this by defining NULLP in C++ as a C NULL  
and using this in sentinels.

On some 64-bit systems it will work fine, since the sentinel will be  
passed in a register and will be sign extended.  This is somewhat  
dependent on the number of other arguments though - I have a couple of  
variadic calls here with enough arguments that the sentinel will go on  
the stack on at least some architectures (SPARC64, for example), at  
which point it will cause some stack corruption if the stack doesn't  
happen to have 32 0 bits immediately before the sentinel.

David



More information about the cfe-dev mailing list