From patchwork Wed Dec 28 08:16:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 37128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1776145wrt; Wed, 28 Dec 2022 00:17:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsCBPp5xYY45TuBx7U8APS9tUGrywC3/e/Iya51GZ6mdVSfT7maAAMfsJyw3KHmJa970DKT X-Received: by 2002:a17:907:7e84:b0:7a4:bbce:ddae with SMTP id qb4-20020a1709077e8400b007a4bbceddaemr26635240ejc.59.1672215445446; Wed, 28 Dec 2022 00:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672215445; cv=none; d=google.com; s=arc-20160816; b=olgI2ms+9q3KObJOfVkSas9TP+dLcal8byp2jurYxi3Oze1D5LHrgZmWHCxpozzN3m V5EOY5BS7ikyrq/NmKvNosbmIku3u9sq1dPupvkeCT7eCnpuUlPzlmF+d21onU2et21E DD+HAFf6T7Xz0oyBcpe1p3yDeJam5fCy+1bHW7iNw1gfgp/SUIJpsoU3MYcOcUGqZjJW wtkWpsNpa5woumgfM4nYNVo8CM57ud/4eUJJMhWRqZXxGCjDCAxUnj7PvPpMz711LPql CMlY18LVyEJTthqWM52cJ1g5DfRFaXI1887mel+69HZ39s0m27lJjusRf+GWg8hPEx8Z UtmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=8+OzzOIWVoT1uJaW1T73VW/v9FdmipNGYdKHrn0aDTQ=; b=PxxtueiLoao8KaXjhGohDGAhCzeQfFwaP5seLsV5mvucdi7+urR7MQAznGmUmU1koQ 5DExhDR0xj7fZbvC1EgS7BnofkwtQOq064EBM+8gWLW4qjKLXW0OxSQZqWhk+SBrIfhH geYwAfg7oFlQF6pVig+7QWsZBi03wY8Ct2lp/qB7lXpFvwK43Pb2x1iKCMwh87ROX/kw l2w3OkSMWn7d5Prb4NDRRKFsV9pBtHsknnZq1LULLsUTm6SvbojicHgGUgTdT6PTD4u9 IoYS/E6Q6sBLG4ELZhLIhIDhjUD1BAWRumSoYXmWc5YbjWwBeyDCpPlrfqEPHGjWmKd1 Q47Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=jAiVBAYa; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id la26-20020a170907781a00b007adeb7f8e5bsi10007492ejc.913.2022.12.28.00.17.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 00:17:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=jAiVBAYa; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6779F3858C27 for ; Wed, 28 Dec 2022 08:17:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 4CCAD3858D37 for ; Wed, 28 Dec 2022 08:16:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4CCAD3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 114AB21A60 for ; Wed, 28 Dec 2022 08:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1672215415; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8+OzzOIWVoT1uJaW1T73VW/v9FdmipNGYdKHrn0aDTQ=; b=jAiVBAYa2GfGfJF5rKP2iCnA6oXhKBHpsrpLuQ4J2MaRhrHGFGO9ExrFxZgsb7cmic6YDV GU5NEgpW/QGbuSJ8d99BnTgev0CzV7Mp+TKSeWQy2qi1uY+/aJBD1HmKTiyIdkr1sh8Fpn Pxf8dOR5PIzbkuPlXr29u9mRhO1ieec= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1672215415; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8+OzzOIWVoT1uJaW1T73VW/v9FdmipNGYdKHrn0aDTQ=; b=ENzkFGGJmzgZT3WZgNbLhDlkh+EjKhmzejFr4XCU+lnM2fqgK6HboSPdgNoGb9x3ettW7T fLS+/7hg85owZFAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0271D138F9 for ; Wed, 28 Dec 2022 08:16:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iXASO3b7q2OwPAAAMHmgww (envelope-from ) for ; Wed, 28 Dec 2022 08:16:54 +0000 Message-ID: <10349745-e297-3e62-81ff-85ed0bf4460c@suse.cz> Date: Wed, 28 Dec 2022 09:16:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] c: check if target_clone attrs are all string To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753444982762248663?= X-GMAIL-MSGID: =?utf-8?q?1753444982762248663?= Hi. The patch checks all attribute arguments if they are string. If not, an error message is emitted. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR c/107993 gcc/c-family/ChangeLog: * c-attribs.cc (handle_target_clones_attribute): Check for string constant for all target_clone attribute values. gcc/testsuite/ChangeLog: * gcc.target/i386/pr107993.c: New test. --- gcc/c-family/c-attribs.cc | 14 ++++++++++---- gcc/testsuite/gcc.target/i386/pr107993.c | 9 +++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr107993.c diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index b36dd97802b..33d84cb6e07 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -5574,12 +5574,18 @@ handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args), /* Ensure we have a function type. */ if (TREE_CODE (*node) == FUNCTION_DECL) { - if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) + for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t)) { - error ("%qE attribute argument not a string constant", name); - *no_add_attrs = true; + tree value = TREE_VALUE (t); + if (TREE_CODE (value) != STRING_CST) + { + error ("%qE attribute argument not a string constant", name); + *no_add_attrs = true; + return NULL_TREE; + } } - else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node))) + + if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node))) { warning (OPT_Wattributes, "%qE attribute ignored due to conflict " "with %qs attribute", name, "always_inline"); diff --git a/gcc/testsuite/gcc.target/i386/pr107993.c b/gcc/testsuite/gcc.target/i386/pr107993.c new file mode 100644 index 00000000000..b0b84a677d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr107993.c @@ -0,0 +1,9 @@ +/* PR c/107993 */ +/* { dg-do compile } */ + +typedef union { int x; } u; +__attribute__((target_clones("arch=alderlake",!"default"))) +int f (u *x) +{ /* { dg-error ".target_clones. attribute argument not a string constant" } */ + return 0; +}