[llvm-commits] [PATCH] Merge function types is C.
Rafael Espíndola
rafael.espindola at gmail.com
Mon Nov 26 19:36:23 PST 2012
sorry, wrong list.
On 26 November 2012 22:35, 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.
> + 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
>
More information about the llvm-commits
mailing list