From patchwork Thu Aug 18 11:00:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 660400 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 3sFNSD4wV6z9t0M for ; Thu, 18 Aug 2016 21:00:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=eUDYcRf2; 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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=TOReh2Ui/jFcR3/wqI93s3InfjwsAfAgVRK51KJO0liXImiTJylBU INb7SFGR39JRPOCdFk7/aaAg+UdX2NcwJl4Guq1vR8cUPF/hVPOmUPvcCs6hlJI4 9s9cbFzM1SDHbnL0CVky5xpU0FnJIONZUDoL5ESt5fPd9GP33qQfmI= 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:subject:message-id:mime-version:content-type; s= default; bh=OvKtDc1itUi0Yb9a7P2fJIO44U0=; b=eUDYcRf2isMXSfOwHReH k0mNda5AYI7AA3K5KCLi4+ZShj4PcGHT5goZD7osH7s3th+p/yhmfHVHghuFbSR8 4fWpBqhlq8nI55RoN4RlNK2amKlmQycntIyZq+gAV/Fnn4c+c5lxF2L+ntC9oUCu hj19Oj9MUggaB0MHjKbabrY= Received: (qmail 123306 invoked by alias); 18 Aug 2016 11:00:50 -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 123291 invoked by uid 89); 18 Aug 2016 11:00:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1, 23, c-common.c, error_at, cfamily X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Aug 2016 11:00:48 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68A294E33C; Thu, 18 Aug 2016 11:00:47 +0000 (UTC) Received: from redhat.com (ovpn-204-81.brq.redhat.com [10.40.204.81]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7IB0i6w027982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 18 Aug 2016 07:00:46 -0400 Date: Thu, 18 Aug 2016 13:00:43 +0200 From: Marek Polacek To: GCC Patches , Joseph Myers Subject: C PATCH to disallow invalid arguments to __atomic_* (PR c/71514) Message-ID: <20160818110043.GP7007@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.2 (2016-07-01) As discussed in the PR, for __atomic_* functions we shouldn't accept pointer-to-function and pointer-to-VLA as arguments. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-08-18 Marek Polacek PR c/71514 * c-common.c (get_atomic_generic_size): Disallow pointer-to-function and pointer-to-VLA. * gcc.dg/pr71514.c: New test. Marek diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index d413146..22e3844 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -11081,6 +11081,20 @@ get_atomic_generic_size (location_t loc, tree function, function); return 0; } + else if (TYPE_SIZE_UNIT (TREE_TYPE (type)) + && TREE_CODE ((TYPE_SIZE_UNIT (TREE_TYPE (type)))) + != INTEGER_CST) + { + error_at (loc, "argument %d of %qE must be a pointer to a constant " + "size type", x + 1, function); + return 0; + } + else if (FUNCTION_POINTER_TYPE_P (type)) + { + error_at (loc, "argument %d of %qE must not be a pointer to a " + "function", x + 1, function); + return 0; + } tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type)); size = type_size ? tree_to_uhwi (type_size) : 0; if (size != size_0) diff --git gcc/testsuite/gcc.dg/pr71514.c gcc/testsuite/gcc.dg/pr71514.c index e69de29..8bfa805 100644 --- gcc/testsuite/gcc.dg/pr71514.c +++ gcc/testsuite/gcc.dg/pr71514.c @@ -0,0 +1,23 @@ +/* PR c/71514 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void +foo () +{ +} + +int a, b; + +void +fn1 (void) +{ + __atomic_exchange (&a, &foo, &b, __ATOMIC_RELAXED); /* { dg-error "must not be a pointer to a function" } */ +} + +void +fn2 (int n) +{ + int arr[n]; + __atomic_exchange (&a, &arr, &b, __ATOMIC_RELAXED); /* { dg-error "must be a pointer to a constant size type" } */ +}