From patchwork Sun Aug 19 09:28:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 1344201 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id ABAD8DF215 for ; Sun, 19 Aug 2012 09:28:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750829Ab2HSJ2M (ORCPT ); Sun, 19 Aug 2012 05:28:12 -0400 Received: from mail-lpp01m010-f46.google.com ([209.85.215.46]:36622 "EHLO mail-lpp01m010-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751358Ab2HSJ2K (ORCPT ); Sun, 19 Aug 2012 05:28:10 -0400 Received: by lagy9 with SMTP id y9so2844657lag.19 for ; Sun, 19 Aug 2012 02:28:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; bh=DFZYOAbL/NKZgWAB2YM8+3FQtE+/J2FIIgLTV2065+8=; b=IjL3csVlUgByEYDs+Z1xGZDcaB04WfigFL44RoWJJVCMkYFU6mPYOTU94Q/21bU2LX MWYY9HDPu/wh9MRdWbWCMO2vsnJGiLBtO23meCliX7Bn/5pYUOoRo6Wc9uwtVAU9S7bo ZquXQWOxM/jF1aEJWzLC/VVCQIuQ/6lCx+Lzl3VZX6TfkUKlFMgPy1ITvStCSWjkOZ1L qfJmlkt5853Msd4GbPNXcFVvE4COAW+MjeNL0R0MkKM2tUXROlSjxMFdRiB6vsWwCp/O 5e3bg7zrau8dG3BJ4zUkO9v9rK+DJSYsc4lmVdbHIN0Ty5IS5vfPTrXRmHaa+9iXoE8G ySlg== Received: by 10.152.114.3 with SMTP id jc3mr10403822lab.11.1345368488500; Sun, 19 Aug 2012 02:28:08 -0700 (PDT) Received: from tux.localdomain (cs181213079.pp.htv.fi. [82.181.213.79]) by mx.google.com with ESMTPS id ba4sm2817320lbb.14.2012.08.19.02.28.07 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Aug 2012 02:28:08 -0700 (PDT) From: Pekka Enberg To: linux-sparse@vger.kernel.org Cc: j.neuschaefer@gmx.net, Pekka Enberg , Christopher Li , Jeff Garzik , Linus Torvalds Subject: [PATCH] sparse, llvm: Fix 'void' return type code generation Date: Sun, 19 Aug 2012 12:28:00 +0300 Message-Id: <1345368480-8431-1-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.7.6 MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org 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 Cc: Christopher Li Cc: Jeff Garzik Cc: Linus Torvalds Signed-off-by: Pekka Enberg --- 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; +} + +/* + * check-name: void return type code generation + * check-command: ./sparsec -c $file -o tmp.o + */