From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 List-Id: 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; +} -- 2.39.0