From patchwork Fri Jan 15 13:39:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 568098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 C804F140C04 for ; Sat, 16 Jan 2016 00:40:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=rHHoIhyZ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=WEPftM8C0sb1MNyQI0aJorrP5b1h25lG9vCgi4yIX/H IVNmDTIRH1V4CDthn0aamX+llaiafzn6XiSu/R/jfh2gMsemQB2jrB33X3DJ5c3Q bAZ1uslYZiHZpo7Gp/vEb7AmTU9khxix9ZViJiscdBvjCdKJin6xl5FmLknM8zrE = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=ZvTQtRir3OH2K7iGRdzqb0bbTZk=; b=rHHoIhyZQ0zm5V+m2 qKdtmn5xKOQQp6tI6iRv6belvc6Jsi6rpX2NvGe0yOiI43ssQCfN7+emwgxjnhxM 830CSr84lZ5qJidqC0l73JW3qD6p9eUKX1iYwUIXQBHdVvTvXKZvJlrOTihwxU6U k2d8cIWu5qJRMdxr6DB8+GLAb8= Received: (qmail 50205 invoked by alias); 15 Jan 2016 13:40:00 -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 50195 invoked by uid 89); 15 Jan 2016 13:39:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=oversight, kyrylotkachovarmcom, kyrylo.tkachov@arm.com, Count X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Jan 2016 13:39:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2893449; Fri, 15 Jan 2016 05:39:20 -0800 (PST) Received: from [10.2.206.200] (e100706-lin.cambridge.arm.com [10.2.206.200]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B5C143F21A; Fri, 15 Jan 2016 05:39:55 -0800 (PST) Message-ID: <5698F6AA.3060202@foss.arm.com> Date: Fri, 15 Jan 2016 13:39:54 +0000 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Marcus Shawcroft , Richard Earnshaw , James Greenhalgh Subject: [PATCH][AArch64] Properly reject invalid attribute strings Hi all, A bug in the target attribute parsing logic led to us silently accepting attribute strings that did not appear in the attributes table i.e invalid attributes. This patch fixes that oversight so we now error out on obviously bogus strings. Bootstrapped and tested on aarch64. Ok for trunk? Thanks, Kyrill 2016-01-15 Kyrylo Tkachov * config/aarch64/aarch64.c (aarch64_process_one_target_attr): Return false when argument string is not found in the attributes table at all. 2016-01-15 Kyrylo Tkachov * gcc.target/aarch64/target_attr_17.c: New test. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index e54ce7985f52c6a61b2ef1e3d7f847f22b1a959f..f2e4b45ac0ad1223e8149d1a35782c13f493a740 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -8938,6 +8938,7 @@ aarch64_process_one_target_attr (char *arg_str, const char* pragma_or_attr) arg++; } const struct aarch64_attribute_info *p_attr; + bool found = false; for (p_attr = aarch64_attributes; p_attr->name; p_attr++) { /* If the names don't match up, or the user has given an argument @@ -8946,6 +8947,7 @@ aarch64_process_one_target_attr (char *arg_str, const char* pragma_or_attr) if (strcmp (str_to_check, p_attr->name) != 0) continue; + found = true; bool attr_need_arg_p = p_attr->attr_type == aarch64_attr_custom || p_attr->attr_type == aarch64_attr_enum; @@ -9025,7 +9027,10 @@ aarch64_process_one_target_attr (char *arg_str, const char* pragma_or_attr) } } - return true; + /* If we reached here we either have found an attribute and validated + it or didn't match any. If we matched an attribute but its arguments + were malformed we will have returned false already. */ + return found; } /* Count how many times the character C appears in diff --git a/gcc/testsuite/gcc.target/aarch64/target_attr_17.c b/gcc/testsuite/gcc.target/aarch64/target_attr_17.c new file mode 100644 index 0000000000000000000000000000000000000000..483cc6d4a1d0b78ac404ae903c7e98a6ad288d17 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/target_attr_17.c @@ -0,0 +1,8 @@ +__attribute__((target("invalid-attr-string"))) +int +foo (int a) +{ + return a + 5; +} + +/* { dg-error "target attribute.*is invalid" "" { target *-*-* } 0 } */ \ No newline at end of file