From: Jeff Garzik <jgarzik@pobox.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: linux-sparse@vger.kernel.org, j.neuschaefer@gmx.net,
Christopher Li <sparse@chrisli.org>,
Jeff Garzik <jgarzik@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] sparse, llvm: Fix 'void' return type code generation
Date: Sun, 19 Aug 2012 12:47:12 -0400 [thread overview]
Message-ID: <50311890.2030801@pobox.com> (raw)
In-Reply-To: <1345368480-8431-1-git-send-email-penberg@kernel.org>
On 08/19/2012 05:28 AM, Pekka Enberg wrote:
> Jonathan Neuschäfer reports:
>
> A simple function like this will compile to the following llvm
> bitcode:
>
> /* C */
> void func(void) {
> return;
> }
>
> /* LLVM */
> define i8 @func() {
> L0:
> ret void
> }
>
> The return type of the function and the type in the return instruction
> don't match.
>
> I found this inconsistency by running LLVM's bitcode validation on the
> bitcode produced by sparse-llvm.
>
> Move 'void *' special-casing from sym_basetype_type() to sym_ptr_type()
> to fix the issue.
>
> Reported by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> Cc: Christopher Li <sparse@chrisli.org>
> Cc: Jeff Garzik <jgarzik@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Pekka Enberg <penberg@kernel.org>
> ---
> sparse-llvm.c | 12 ++++++++++--
> validation/backend/void-return-type.c | 13 +++++++++++++
> 2 files changed, 23 insertions(+), 2 deletions(-)
> create mode 100644 validation/backend/void-return-type.c
>
> diff --git a/sparse-llvm.c b/sparse-llvm.c
> index e02e212..213d42d 100644
> --- a/sparse-llvm.c
> +++ b/sparse-llvm.c
> @@ -150,7 +150,13 @@ static LLVMTypeRef sym_union_type(LLVMModuleRef module, struct symbol *sym)
>
> static LLVMTypeRef sym_ptr_type(LLVMModuleRef module, struct symbol *sym)
> {
> - LLVMTypeRef type = symbol_type(module, sym->ctype.base_type);
> + LLVMTypeRef type;
> +
> + /* 'void *' is treated like 'char *' */
> + if (is_void_type(sym->ctype.base_type))
> + type = LLVMInt8Type();
> + else
> + type = symbol_type(module, sym->ctype.base_type);
>
> return LLVMPointerType(type, 0);
> }
> @@ -176,10 +182,12 @@ static LLVMTypeRef sym_basetype_type(struct symbol *sym)
> }
> } else {
> switch (sym->bit_size) {
> + case -1:
> + ret = LLVMVoidType();
> + break;
> case 1:
> ret = LLVMInt1Type();
> break;
> - case -1: /* 'void *' is treated like 'char *' */
> case 8:
> ret = LLVMInt8Type();
> break;
> diff --git a/validation/backend/void-return-type.c b/validation/backend/void-return-type.c
> new file mode 100644
> index 0000000..b282fde
> --- /dev/null
> +++ b/validation/backend/void-return-type.c
> @@ -0,0 +1,13 @@
> +static void foo(void)
> +{
> +}
> +
> +static void *bar(void *p)
> +{
> + return p;
> +}
> +
ACK the code... would prefer that the first testcase included a
"return;" just to be certain we get that right.
Jeff
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2012-08-19 16:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-19 9:28 [PATCH] sparse, llvm: Fix 'void' return type code generation Pekka Enberg
2012-08-19 16:47 ` Jeff Garzik [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50311890.2030801@pobox.com \
--to=jgarzik@pobox.com \
--cc=j.neuschaefer@gmx.net \
--cc=jgarzik@redhat.com \
--cc=linux-sparse@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.