From patchwork Mon Mar 27 21:24:03 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: 9647531 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 6E8F560349 for ; Mon, 27 Mar 2017 21:27:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 602621FF28 for ; Mon, 27 Mar 2017 21:27:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54FE3205FD; Mon, 27 Mar 2017 21:27:07 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 0712D1FF28 for ; Mon, 27 Mar 2017 21:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752610AbdC0V1H (ORCPT ); Mon, 27 Mar 2017 17:27:07 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:33978 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752356AbdC0V1E (ORCPT ); Mon, 27 Mar 2017 17:27:04 -0400 Received: by mail-wr0-f196.google.com with SMTP id w43so14205385wrb.1 for ; Mon, 27 Mar 2017 14:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Artch8fMN30/onnGsZBX6oL1QeozcX2LOoGNMDn0rRQ=; b=Oclcy/x86PKaPvufNMqNSnY9YtzRh9WX26PtlWnFwNDP6EZ0udtDY0gGfvvnfMpxIt C77qTYI0bCxs/HZ9VJTA0EKR1oo6f5bwuaYCxgbiV5i/sK3xArXBHEgd+QrQ6rnPKykp TycthwdPfEOquc6kSEU2w76Sv5/g/EO54XaYCMIoAPmxp3Z3p4JVo4xwesBLtcRxGe+N dTcZ6NYda7uRVla21Oqpjz/dJG4fgihDS2SHsahJPlnoljqDqiFgveR50YcsIkcnwjKq 6zfA104tBaEioCF8g7WZoLtRpV0ctSvs3+EsZvJydxzJZxw2iMFNpiF/EBPzVOkGWm4Q 7VhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Artch8fMN30/onnGsZBX6oL1QeozcX2LOoGNMDn0rRQ=; b=Zwa3yHVJNrm7QNHBX4cqYMWGc+y2sOCy8RRD9NoRxwjzGui9qqDZDyaKJ0jddUzugN ZdUCGRcStbTOvg9ZFT1C0HUM4E47LFyerdbpixHFUwDfHEPfswjM4UVUfjxvCs62NpPv vprfL/gLt6I7uX785xMZM6tvSk4VxVQ1TpDU35FA14OoYg0wJmFOG/8xmWep6AgJTk1m Rj4USbpYrLglmFRDas3apJwQ72kEalOFDKaEx268R/ICTt+CBA8sjQLC9NMthiU3se0r 4DcinhKvVVhSgGyyNB86rkZjBuwvBbDJJCPY6xMzC3G/w4JdbR3b0zLRtU/TQRwsboqS B88w== X-Gm-Message-State: AFeK/H28/jYWUHstSicWmOAyZkvVZeK3ARYxUywqfKk49lzS2GC4WD1PXa3phgIbatMnfQ== X-Received: by 10.223.139.83 with SMTP id v19mr21101031wra.142.1490650022684; Mon, 27 Mar 2017 14:27:02 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:802:b00:496:ae63:aebb:a034]) by smtp.gmail.com with ESMTPSA id k203sm973767wmk.4.2017.03.27.14.27.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 14:27:02 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v6 39/52] llvm: fix mutating function pointer Date: Mon, 27 Mar 2017 23:24:03 +0200 Message-Id: <20170327212416.18536-40-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170327212416.18536-1-luc.vanoostenryck@gmail.com> References: <20170327212416.18536-1-luc.vanoostenryck@gmail.com> 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 Signed-off-by: Luc Van Oostenryck --- sparse-llvm.c | 5 ++++- validation/backend/function-ptr-xtype.c | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 validation/backend/function-ptr-xtype.c diff --git a/sparse-llvm.c b/sparse-llvm.c index 0c92eab23..af540033d 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -829,7 +829,10 @@ static void output_op_call(struct function *fn, struct instruction *insn) args[i++] = pseudo_to_rvalue(fn, arg, arg->src); } END_FOR_EACH_PTR(arg); - func = pseudo_to_value(fn, NULL, insn->func); + if (insn->func->type == PSEUDO_REG || insn->func->type == PSEUDO_PHI) + func = get_operand(fn, insn->fntype, insn->func); + else + func = pseudo_to_value(fn, insn->fntype, insn->func); pseudo_name(insn->target, name); target = LLVMBuildCall(fn->builder, func, args, n_arg, name); diff --git a/validation/backend/function-ptr-xtype.c b/validation/backend/function-ptr-xtype.c new file mode 100644 index 000000000..9cdfab051 --- /dev/null +++ b/validation/backend/function-ptr-xtype.c @@ -0,0 +1,37 @@ +typedef int (*binop_t)(int, int); +typedef int (*unop_t)(int); +typedef int (*idef_t)(void); +typedef long (*ldef_t)(void); +typedef void (*use_t)(int); + +// We want to 'fn' have several different types. +// The goal is for the ->priv member to be used +// with a type different from what it was first stored. + +int foo(void *fn, int arg1, int arg2); +int foo(void *fn, int arg1, int arg2) +{ + int res = 0; + + res += ((binop_t)fn)(arg1, arg2); + res += ((unop_t)fn)(arg1); + res += ((ldef_t)fn)(); + res += ((idef_t)fn)(); + ((use_t)fn)(res); + return res; +} + +int bar(int (*fn)(int), int arg1, int arg2); +int bar(int (*fn)(int), int arg1, int arg2) +{ + int res = 0; + + res += ((binop_t)fn)(arg1, arg2); + res += fn(arg1); + return res; +} + +/* + * check-name: mutate function pointer's type + * check-command: ./sparsec -c $file -o tmp.o + */