From patchwork Tue Mar 6 20:56:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 882228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-474349-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RNN3klM4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zwpx04m4tz9shc for ; Wed, 7 Mar 2018 07:56:52 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=hMi7VibKI5Xs+w/1pPGD+PtVYGuJD Nvb3A0GQjytvb6j8UtY8r5cuI9QG6owS+ChV+NrmySFmB4CCtL6qYN0UsnqEtcCn R3Vak+LPdwJSWQlHLlLZfwjKGikGpmDU7ceYhAXVWfDHxa+3VgGnwppoFrUwi29W /VoP1QN6vnOEas= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=7TuJNX1ScTgNUupa53fHSIHVQjw=; b=RNN 3klM4bNporB/D/MkHYB2owaJseilu9J7lAbTzP3kZmlos/6BoE1kehW/WyrcxMKQ hnrp5Sfg/yCXvxyFaorjKAFzhcex71KkyPr9f18SZMVpgmYmRQ5EH6kGQf9+MoA6 PAR+eP+tgk84Z9zuUcYVNRAmfaIlJoerbCkdiLrQ= Received: (qmail 129953 invoked by alias); 6 Mar 2018 20:56:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 129944 invoked by uid 89); 6 Mar 2018 20:56:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=exclusion X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Mar 2018 20:56:44 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15977EAEAB; Tue, 6 Mar 2018 20:56:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-35.brq.redhat.com [10.40.204.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3C99AFD4E; Tue, 6 Mar 2018 20:56:38 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w26KuatO014180; Tue, 6 Mar 2018 21:56:36 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w26KuYRK014179; Tue, 6 Mar 2018 21:56:34 +0100 Date: Tue, 6 Mar 2018 21:56:34 +0100 From: Jakub Jelinek To: Jeff Law , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Reject target_clones attribute in functions that can't be cloned (PR middle-end/84723) Message-ID: <20180306205634.GC5867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! The following testcases show various reasons why a function definition with target_clones attribute can't be cloned; instead of ICEing because node->create_version_clone_with_body returns NULL and we dereference it, this patch just diagnoses those and ignores the attribute. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Martin Sebor said he wants to work on attribute exclusion, in that case the error messages in pr84723-{1,4,5}.c would be adjusted if needed and const char *reason = NULL; if (lookup_attribute ("noclone", DECL_ATTRIBUTES (node->decl))) reason = G_("function %q+F can never be copied " "because it has % attribute"); else reason = copy_forbidden (DECL_STRUCT_FUNCTION (node->decl)); could be replaced just with const char *reason = copy_forbidden (DECL_STRUCT_FUNCTION (node->decl)); but attribute exclusions can't really help for the cases where cloning is refused because of other reasons. 2018-03-06 Jakub Jelinek PR middle-end/84723 * multiple_target.c: Include tree-inline.h and intl.h. (expand_target_clones): Diagnose and fail if node->definition and !tree_versionable_function_p (node->decl). * gcc.target/i386/pr84723-1.c: New test. * gcc.target/i386/pr84723-2.c: New test. * gcc.target/i386/pr84723-3.c: New test. * gcc.target/i386/pr84723-4.c: New test. * gcc.target/i386/pr84723-5.c: New test. Jakub --- gcc/multiple_target.c.jj 2018-01-03 10:19:54.956533925 +0100 +++ gcc/multiple_target.c 2018-03-06 11:46:09.327627941 +0100 @@ -36,6 +36,8 @@ along with GCC; see the file COPYING3. #include "pretty-print.h" #include "gimple-iterator.h" #include "gimple-walk.h" +#include "tree-inline.h" +#include "intl.h" /* Walker callback that replaces all FUNCTION_DECL of a function that's going to be versioned. */ @@ -312,6 +314,22 @@ expand_target_clones (struct cgraph_node return false; } + if (node->definition + && !tree_versionable_function_p (node->decl)) + { + error_at (DECL_SOURCE_LOCATION (node->decl), + "clones for % attribute cannot be created"); + const char *reason = NULL; + if (lookup_attribute ("noclone", DECL_ATTRIBUTES (node->decl))) + reason = G_("function %q+F can never be copied " + "because it has % attribute"); + else + reason = copy_forbidden (DECL_STRUCT_FUNCTION (node->decl)); + if (reason) + inform (DECL_SOURCE_LOCATION (node->decl), reason, node->decl); + return false; + } + char *attr_str = XNEWVEC (char, attr_len); int attrnum = get_attr_str (arglist, attr_str); char **attrs = XNEWVEC (char *, attrnum); --- gcc/testsuite/gcc.target/i386/pr84723-1.c.jj 2018-03-06 12:00:17.533367738 +0100 +++ gcc/testsuite/gcc.target/i386/pr84723-1.c 2018-03-06 11:52:15.831511845 +0100 @@ -0,0 +1,11 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +__attribute__((noclone)) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it has .noclone. attribute" "" { target *-*-* } .-1 } */ +} --- gcc/testsuite/gcc.target/i386/pr84723-2.c.jj 2018-03-06 12:00:21.019367631 +0100 +++ gcc/testsuite/gcc.target/i386/pr84723-2.c 2018-03-06 11:50:30.458545226 +0100 @@ -0,0 +1,13 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it saves address of local label in a static variable" "" { target *-*-* } .-1 } */ + static void *p = &&lab; + asm volatile ("" : "+m" (p) : : "memory"); +lab:; +} --- gcc/testsuite/gcc.target/i386/pr84723-3.c.jj 2018-03-06 12:00:24.397367531 +0100 +++ gcc/testsuite/gcc.target/i386/pr84723-3.c 2018-03-06 11:50:57.274536736 +0100 @@ -0,0 +1,17 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +int +foo (int x) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it receives a non-local goto" "" { target *-*-* } .-1 } */ + __label__ lab; + __attribute__((noinline)) void bar () { goto lab; } + if (x == 5) + bar (); + x++; +lab:; + return x; +} --- gcc/testsuite/gcc.target/i386/pr84723-4.c.jj 2018-03-06 12:00:17.533367738 +0100 +++ gcc/testsuite/gcc.target/i386/pr84723-4.c 2018-03-06 11:52:15.831511845 +0100 @@ -0,0 +1,11 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +__attribute__((naked)) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it has .noclone. attribute" "" { target *-*-* } .-1 } */ +} --- gcc/testsuite/gcc.target/i386/pr84723-5.c.jj 2018-03-06 12:00:17.533367738 +0100 +++ gcc/testsuite/gcc.target/i386/pr84723-5.c 2018-03-06 11:52:15.831511845 +0100 @@ -0,0 +1,11 @@ +/* PR middle-end/84723 */ +/* { dg-do compile } */ +/* { dg-require-ifunc } */ +/* { dg-options "-O2" } */ + +__attribute__((target_clones ("avx", "default"))) +__attribute__((noipa)) +void +foo (void) /* { dg-error "clones for .target_clones. attribute cannot be created" } */ +{ /* { dg-message "function .foo. can never be copied because it has .noclone. attribute" "" { target *-*-* } .-1 } */ +}