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

Richard Smith richard at metafoo.co.uk
Mon Nov 26 20:18:56 PST 2012


On Mon, Nov 26, 2012 at 7:36 PM, Rafael Ávila de Espíndola <
rafael.espindola at gmail.com> wrote:

> GCC accepts
>
> typedef int IA[];
> typedef int A10[10];
> static A10 *f(void);
> static IA  *f(void);
> void g(void) {
>   (void)sizeof(*f());
> }
>
> but clang used to reject it with:
>
>     invalid application of 'sizeof' to an incomplete type 'IA' (aka 'int
> []')
>
> The intention of c99's 6.2.7 seems to be that we should use the composite
> type
> and accept as gcc does.
> ---
>  lib/Sema/SemaDecl.cpp   |  7 +++++++
>  test/Sema/merge-decls.c | 11 +++++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
> index 6a9065e..72b7f26 100644
> --- a/lib/Sema/SemaDecl.cpp
> +++ b/lib/Sema/SemaDecl.cpp
> @@ -2402,6 +2402,13 @@ bool
> Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
>    if (getLangOpts().CPlusPlus)
>      return MergeCXXFunctionDecl(New, Old, S);
>
> +  // Merge the types so the we get the composites for the return and
> argument
> +  // types. Do that only if both decls are not K&R.
>

Why do you not merge functions with no prototype?


> +  if (Old->hasPrototype() && New->hasPrototype()) {
> +    QualType Merged = Context.mergeTypes(Old->getType(), New->getType());
> +    New->setType(Merged);
> +  }
> +
>    return false;
>  }
>
> diff --git a/test/Sema/merge-decls.c b/test/Sema/merge-decls.c
> index da3e245..9789587 100644
> --- a/test/Sema/merge-decls.c
> +++ b/test/Sema/merge-decls.c
> @@ -48,3 +48,14 @@ void test1_g(void)
>    }
>    (void)sizeof(*test1_f());
>  }
> +
> +typedef int test2_IA[];
> +typedef int test2_A10[10];
> +
> +static test2_A10 *test2_f(void);
> +static test2_IA  *test2_f(void);
> +
> +void test2_g(void)
> +{
> +  (void)sizeof(*test2_f());
> +}
> --
> 1.7.11.7
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121126/dedd5377/attachment.html>


More information about the cfe-commits mailing list