From patchwork Wed Apr 3 13:48:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Senthil Kumar Selvaraj X-Patchwork-Id: 233465 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id F11142C012F for ; Thu, 4 Apr 2013 00:49:01 +1100 (EST) 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:mime-version:content-type; q=dns; s=default; b=D+Wu+KWNqDDkIAmBQryaPJr6FQKZukbcfJdlC/HJp6TP+H4WLa yu63SOnndqRQvXp+wKJn+YAF+2vQJ1bX0EUmtWiH/eqIMx6FNsMCPugnJPC7uFGv aYbE7e/+n6C4p9Y7UxGOTwSpsHXkx6Ym68rPH81lKy2TThIZoiLaJGpoo= 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:mime-version:content-type; s= default; bh=35DBk3jykuLlTal/hMx+cyd/53s=; b=xxz4I//BpLQRlBIoD60J rOkUFIHFqzP7OVG6iP2y2H/B66cFkrhIkZuuAB/Mr15Ey73FqKyIR2PJ/HCs0KuO eP17V/Jc1cw/eucCMpiUuB2tkaAE9qOj8yRO0VnA4vJ1SUfXT+t5THEOYBchpysd 2facMfMEqvStyzxxvHY7qds= Received: (qmail 5115 invoked by alias); 3 Apr 2013 13:48:32 -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 5099 invoked by uid 89); 3 Apr 2013 13:48:31 -0000 X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from eusmtp01.atmel.com (HELO eusmtp01.atmel.com) (212.144.249.243) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 03 Apr 2013 13:48:28 +0000 Received: from apsmtp01.atmel.com (10.168.254.30) by eusmtp01.atmel.com (10.161.101.31) with Microsoft SMTP Server id 14.2.318.4; Wed, 3 Apr 2013 15:48:25 +0200 Received: from PENCHT02.corp.atmel.com (10.168.5.162) by apsmtp01.corp.atmel.com (10.168.254.30) with Microsoft SMTP Server (TLS) id 14.2.318.1; Wed, 3 Apr 2013 21:48:23 +0800 Received: from atmel.com (10.168.5.13) by cas-ap.atmel.com (10.168.5.162) with Microsoft SMTP Server (TLS) id 14.2.318.1; Wed, 3 Apr 2013 21:48:22 +0800 Date: Wed, 3 Apr 2013 19:18:20 +0530 From: Senthil Kumar Selvaraj To: CC: , Subject: [Patch] Emit error for negative _Alignas alignment values Message-ID: <20130403134820.GA796@atmel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This patch detects and emits an error if the value provided in _Alignas is negative. The fix was approved pending full regression testing in a previous discussion (http://gcc.gnu.org/ml/gcc/2013-03/msg00282.html). To add to that patch, I have added a testcase that explicitly checks for the error for a negative power of 2. Bootstrapped and regression tested with x86_64-unknown-linux-gnu with no new failures. If ok, could someone commit please? I don't have commit access. Regards Senthil ChangeLog 2013-04-03 Senthil Kumar Selvaraj * c-common.c (check_user_alignment): Emit error for negative values * gcc.dg/c1x-align-3.c: Add test for negative power of 2 diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index c7cdd0f..dfdfbb6 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -7308,9 +7308,10 @@ check_user_alignment (const_tree align, bool allow_zero) } else if (allow_zero && integer_zerop (align)) return -1; - else if ((i = tree_log2 (align)) == -1) + else if (tree_int_cst_sgn (align) == -1 + || (i = tree_log2 (align)) == -1) { - error ("requested alignment is not a power of 2"); + error ("requested alignment is not a positive power of 2"); return -1; } else if (i >= HOST_BITS_PER_INT - BITS_PER_UNIT_LOG) diff --git gcc/testsuite/gcc.dg/c1x-align-3.c gcc/testsuite/gcc.dg/c1x-align-3.c index 0b2a77f..b97351c 100644 --- gcc/testsuite/gcc.dg/c1x-align-3.c +++ gcc/testsuite/gcc.dg/c1x-align-3.c @@ -23,6 +23,7 @@ _Alignas (-(__LONG_LONG_MAX__-1)/4) char i3; /* { dg-error "too large|power of 2 _Alignas (-(__LONG_LONG_MAX__-1)/8) char i4; /* { dg-error "too large|power of 2" } */ _Alignas (-(__LONG_LONG_MAX__-1)/16) char i5; /* { dg-error "too large|power of 2" } */ _Alignas (-1) char j; /* { dg-error "power of 2" } */ +_Alignas (-2) char j; /* { dg-error "positive power of 2" } */ _Alignas (3) char k; /* { dg-error "power of 2" } */ _Alignas ((void *) 1) char k; /* { dg-error "integer constant" } */