[cfe-commits] [PATCH] Merge function types is C.

Rafael Espíndola rafael.espindola at gmail.com
Thu Nov 29 08:12:36 PST 2012


r168895.

Thanks Eli and Richard for  all the help with the dark corners of C!

On 29 November 2012 00:54, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Wed, Nov 28, 2012 at 8:04 PM, Rafael Espíndola
> <rafael.espindola at gmail.com> wrote:
>>> void f(int (*)[10]);
>>> void f(int (*)[]);
>>> void g() {
>>>   int x[5];
>>>   f(&x);
>>> }
>>>
>>> gcc gives "warning: passing argument 1 of ‘f’ from incompatible
>>> pointer type"; clang should print a similar warning.
>>
>> Added. This required changing/fixing initialization sequences to use
>> the type from the function prototype instead of the one from the
>> argument.
>>
>>>> What is the behavior you would expect from CodeGen? Given
>>>>
>>>> void f(int);
>>>> void f(a)
>>>>   char a;
>>>> {
>>>>   int v[sizeof(a) == 1 ? 1 : -1];
>>>> }
>>>>
>>>> Should it produce a f(i32) that truncates its argument?
>>>
>>> Yes, this should continue to work the same way it works on trunk.
>>
>> A new patch is attached. The codegen is not identical in all cases,
>> for example, given
>>
>> int svc_register (void (*dispatch) (int));
>> int svc_register (dispatch)
>>      void (*dispatch) ();
>> {}
>>
>> without this patch we produce "@svc_register(void (...)* %dispatch)"
>> and with it we produce "@svc_register(void (i32)*)", which I think is
>> the desired result.
>
> Yes, fine.
>
> @@ -1230,7 +1230,11 @@ void CodeGenFunction::EmitFunctionProlog(const
> CGFunctionInfo &FI,
>
>          if (isPromoted)
>            V = emitArgumentDemotion(*this, Arg, V);
> -
> +
> +        llvm::Type *LTy = ConvertType(Arg->getType());
> +        if (V->getType() != LTy)
> +          V = Builder.CreateBitCast(V, LTy);
> +
>
> This deserves a comment describing why the bitcast is safe.
>
> Otherwise looks fine.
>
> -Eli




More information about the cfe-commits mailing list