[cfe-commits] r64504 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ lib/AST/ lib/Analysis/ lib/CodeGen/ lib/Sema/ test/Analysis/ test/CodeGen/ test/Sema/

Douglas Gregor dgregor at apple.com
Mon Feb 16 09:22:50 PST 2009


On Feb 14, 2009, at 10:28 PM, Daniel Dunbar wrote:

> Hi Doug,
>
> A few technical comments:
>
> On Fri, Feb 13, 2009 at 3:20 PM, Douglas Gregor <dgregor at apple.com>  
> wrote:
>> +BUILTIN(alloca, "v*z", "f:stdlib.h")
>> +BUILTIN(calloc, "v*zz", "f:stdlib.h")
>> +BUILTIN(malloc, "v*z", "f:stdlib.h")
>
> + realloc ?

Good catch. Thanks.

>> +DIAG(note_previous_builtin_declaration, NOTE,
>> +     "%0 was implicitly declared here with type %1")
>
> This warning is lying, it wasn't implicitly declared here! What about:
> "%0 is a builtin with type %1"

Yep, that's better.

>> @@ -491,9 +509,12 @@
>>  diag::kind PrevDiag;
>>  if (Old->isThisDeclarationADefinition())
>>    PrevDiag = diag::note_previous_definition;
>> -  else if (Old->isImplicit())
>> -    PrevDiag = diag::note_previous_implicit_declaration;
>> -  else
>> +  else if (Old->isImplicit()) {
>> +    if (Old->getBuiltinID())
>> +      PrevDiag = diag::note_previous_builtin_declaration;
>> +    else
>> +      PrevDiag = diag::note_previous_implicit_declaration;
>> +  } else
>>    PrevDiag = diag::note_previous_declaration;
>
> I think we need to do a bit more than this. This code will allow
> merging of compatible declarations and reuse the new declaration not
> the old one. I think we probably want to merely require the
> declarations to be compatible, but make sure that we always use the
> original builtin declaration.

Yeah, I have an existing Radar about this. The approach I'm taking now  
is to ignore the new declaration if it is an incompatible redeclaration.

> Currently this is causing problems in IRgen with:
> --
> void *malloc();
> void f0() { malloc(10); }
> --
> because the redeclaration of malloc is shadowing the original
> declaration, yet the builtin ID is still set so IRgen expects the
> prototype to match exactly to that of the builtin.


We're actually tripping over http://llvm.org/PR3588 here, because that  
"void *malloc();" is a redeclaration without a prototype, so it's well- 
formed code... but malloc() should really retain its original prototype.

	- Doug



More information about the cfe-commits mailing list