From patchwork Tue Feb 28 17:35:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9596401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9353D600CB for ; Tue, 28 Feb 2017 17:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8921F2853D for ; Tue, 28 Feb 2017 17:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E02128552; Tue, 28 Feb 2017 17:36:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26C5228547 for ; Tue, 28 Feb 2017 17:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598AbdB1Rf6 (ORCPT ); Tue, 28 Feb 2017 12:35:58 -0500 Received: from mail-wr0-f174.google.com ([209.85.128.174]:34727 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751387AbdB1Rfv (ORCPT ); Tue, 28 Feb 2017 12:35:51 -0500 Received: by mail-wr0-f174.google.com with SMTP id l37so13709477wrc.1 for ; Tue, 28 Feb 2017 09:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Tbn5GFwyNLohFKxhzwEvVYrGeQ2ZB5z2UxERcqdu14A=; b=jhrdvbb5vkzHM9jCmiUEjI+QGnv6JBWxFQi8ItUEI4rzG/8Rxw/P7TFspJSvwTImVx 7DdcLSp91VS0DA/wpj9zNLhC7z4gHIuvgyOBFAM89F8fPO/flG29Rr1LkJlmxDninTUL xJiFbf44dFzSgRBkjyzO6enVBYwr3q9CFf0Qc5q4yrDTb3gWGn+1zakNIzlGQfOr3Ti9 UPZb239D3y4RZqPEEnsfLrrhOhYelzF3Fc8Jym56JcqNuG9Eus+gxTfumHAAHQ7HutwH cFronhXHpD0FSSWjJab6E5aRI/9228ZnkVn7TlRwjR81RD55N9+nc3vxmK63vIZsP9NR dbqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Tbn5GFwyNLohFKxhzwEvVYrGeQ2ZB5z2UxERcqdu14A=; b=Gh+R0z9JD1e1w1nbhyFduZ1I5D+4wdyWeXgsfQk79m48OYwY197nJleY4XE2VilYaF AvbLiHX789n42BrCTT4ngRHpNvYNeRpJF26ON1vE+SZcWNgl5wbRl3Xxaul6PGdTPX9P X8KV00tQ/A53vM+yMypKWd5jD1BPE6r80y3vC0TCVZsuiutUIW6YG/SqJAJpCvDSCLg3 Dk0ZsYYKrU96mI2ArODtDR0cevZhtKLCdonwxPFB0FR62JZXbX2wb8w8N3fcH0uAquTk QB7FDE9cHMNEIUFmoBZk9/kLS3M5TjFlu1Ifv0OIw6ZYCfVSO2CESpFBHC5CV3A6mmIP oPnA== X-Gm-Message-State: AMke39kIGj/ca+1H3wJaVFUUs+BNbLTJIip4tfIz24hdoDNCgt94eEMeDq2t1pOvBIGgkg== X-Received: by 10.223.169.140 with SMTP id b12mr3441159wrd.138.1488303322364; Tue, 28 Feb 2017 09:35:22 -0800 (PST) Received: from macpro.local ([2a02:a03f:85e:d600:80dd:dea5:aa0f:9d7c]) by smtp.gmail.com with ESMTPSA id j18sm3197484wrb.33.2017.02.28.09.35.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 09:35:21 -0800 (PST) Date: Tue, 28 Feb 2017 18:35:19 +0100 From: Luc Van Oostenryck To: Dibyendu Majumdar Cc: Linux-Sparse Subject: Re: Sparse-LLVM issue compiling NULL pointers Message-ID: <20170228173519.hyq3aihtg3zouoih@macpro.local> References: <20170228150956.moyfiyd5zf7tbeze@macbook.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170206 (1.7.2) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Feb 28, 2017 at 06:03:05PM +0100, Luc Van Oostenryck wrote: > On Tue, Feb 28, 2017 at 4:09 PM, Luc Van Oostenryck > wrote: > > There is indeed some problems regarding this, we looked a bit at this > > some weeks ago. However I firmly believe that the information about > > the type belong to the operations and not the values. > > I've taken a very quick look at this "mt->foo = (void *)0" > The type info is perfectly present. > If in sparse-llvm.c:output_op_store() you add somewhere something like: > fprintf(stderr, "-> %s\n", show_typename(insn->type)); > You will see that it display the expected type: "int *". > This is all the type info needed: it's the type of insn->target (the > value to be stored) > and the type of the dereferencing of insn->src (the (base) address). > > The problem is that output_op_store() doesn't use this info, it tries to deduce > this type via pseudo_to_value() but pseudo_to_value() wrongly assumes that all > PSEUDO_VALUE-pseudo are integer. Not very pretty and incomplete but the following patch allow sparse-llvm to compile this: struct mytype { int *foo; }; extern void init_mytype(struct mytype *mt); void init_mytype(struct mytype *mt) { mt->foo = (int *)mt; mt->foo = (void *)mt; mt->foo = (int *)0; mt->foo = (void *)0; mt->foo = (void *)(long)0; } It fail at " ... = (... *)1;" though. target_in = pseudo_to_value(fn, insn, insn->target); /* perform store */ --- 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 diff --git a/sparse-llvm.c b/sparse-llvm.c index 9f362b3ed..9e0450ae7 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -306,6 +306,7 @@ static void pseudo_name(pseudo_t pseudo, char *buf) static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *insn, pseudo_t pseudo) { LLVMValueRef result = NULL; + LLVMTypeRef type; switch (pseudo->type) { case PSEUDO_REG: @@ -360,7 +361,21 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins break; } case PSEUDO_VAL: - result = LLVMConstInt(insn_symbol_type(fn->module, insn), pseudo->value, 1); + type = insn_symbol_type(fn->module, insn); + switch (LLVMGetTypeKind(type)) { + case LLVMPointerTypeKind: + assert(!pseudo->value); + result = LLVMConstPointerNull(type); + break; + case LLVMIntegerTypeKind: + result = LLVMConstInt(type, pseudo->value, 1); + break; + default: + assert(0); + } break; case PSEUDO_ARG: { result = LLVMGetParam(fn->fn, pseudo->nr - 1); @@ -626,6 +641,7 @@ static void output_op_store(struct function *fn, struct instruction *insn) addr = calc_memop_addr(fn, insn);