From patchwork Mon Mar 25 00:21:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1063581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498358-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wt7wpUxU"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jV650aTj"; dkim-atps=neutral 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 44SFLt2sRWz9sRy for ; Mon, 25 Mar 2019 11:21:56 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=GXIzGyYnkBT9Dzju1rqeSEWTpxypbtkb1+ZeMGtR7BwobA1AoW aC7I8+45nZzHFzBsv909ZkgVPSt8ZjucyenAqqW59kBaJ/Y5kjKHwNm631OLGWGK LcYeVNDd58ifhp+EVGWWpjCyCfcK/8egEcauaqV6v8CIhLinLz5oddRHU= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=45f8pOdM0k2dP28SD0vqbLPbkGc=; b=wt7wpUxU63JwAX/oKypU PqjnOzYiS2Rwztm6nXjxDqAbrOjcBiHcXYxshF/re+Z3ahm0C3/UgF8rcv1+u7kg jNh2x1kgHWKe14xoyNR2o1NyloZU1lkENfCITB/F/WD50V6wK2kEtvbWVyYC9+55 4wJUtTiL41l4S+ujCv55BWo= Received: (qmail 88053 invoked by alias); 25 Mar 2019 00:21:46 -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 88035 invoked by uid 89); 25 Mar 2019 00:21:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sometime, 32-bits, DECL, HX-Received:a0c X-HELO: mail-qt1-f180.google.com Received: from mail-qt1-f180.google.com (HELO mail-qt1-f180.google.com) (209.85.160.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Mar 2019 00:21:43 +0000 Received: by mail-qt1-f180.google.com with SMTP id z17so8379238qts.13 for ; Sun, 24 Mar 2019 17:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=3FFbqP63iXJO9icWZK3tZbBb4XmMDr6D0eL2GvtLJNA=; b=jV650aTjtJTFxZnWeLOjwq1SV/Q8AcstJkU3t/oy+zMcB2YLWMOw4ZTFrFJRhfiK/l naq65bWmzOORc3MbqNvzDUySRnblUIadfsijAaQ0VlLd/X0jr1O9Z+XnIK4Hmjf1wH5O 3RGRNXNQLvqie9DtnhkPPli5mTAQq9tExf6X9pdcA5QkZIYPEDQivw/hLidB7+X43MtM OBpeGKE9riFuydfPxnD9cN5mm5zZpw8rnKDoh1HbABQVHtbYhuD5qf/7kzkbRDfD7+rB 6iAg1x6tJfjC4ULezz0QXU5R7rdpC8PoR39jTQ01cQiuwya2DJFSKEo3GxpEUY7GxmFQ ys4A== Received: from [192.168.0.41] (75-166-119-163.hlrn.qwest.net. [75.166.119.163]) by smtp.gmail.com with ESMTPSA id u16sm14635085qtc.84.2019.03.24.17.21.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Mar 2019 17:21:40 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" From: Martin Sebor Subject: [PATCH] correct maximum valid alignment in error message (PR 89812) Message-ID: <91b01cb1-b0e5-f39b-a437-16252f421253@gmail.com> Date: Sun, 24 Mar 2019 18:21:38 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes The error issued when the aligned attribute argument is too big to be represented is incorrect: it says the maximum alignment is 1U << 31 when it should actually be 1 << 28. This was a typo introduced when the error message was enhanced earlier in GCC 9. The test I added to verify the fix for the typo exposed another bug introduced in the same commit as the incorrect value in the error message: assuming that the attribute aligned argument fits in SHWI. The attached patch corrects both problems. It has been tested on x86_64-linux. I will commit it as obvious sometime this week unless there are any objections or suggestions for changes. Martin PS I have a couple of questions related to the affected code: 1) Does GCC support building with compilers where int is not 32 bits wide, or where BITS_PER_UNIT is not 3? (I.e., either is less or more?) 2) Is there a supported target that doesn't have __INT64_TYPE__? (And if so, how do I find it in a test? I couldn't find anythhing in target-supports.exp). PR c/89812 - incorrect maximum in error: requested alignment ‘536870912’ exceeds maximum 2147483648 gcc/c-family/ChangeLog: PR c/89812 * c-common.c (check_user_alignment): Rename local. Correct maximum alignment in diagnostic. Avoid assuming argument fits in SHWI, convert it to UHWI when it fits. gcc/testsuite/ChangeLog: PR c/89812 * gcc.dg/attr-aligned-3.c: New test. Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 269902) +++ gcc/c-family/c-common.c (working copy) @@ -5287,9 +5287,10 @@ check_user_alignment (const_tree align, bool objfi return -1; } - int log2bitalign; + /* Log2 of the byte alignment ALIGN. */ + int log2align; if (tree_int_cst_sgn (align) == -1 - || (log2bitalign = tree_log2 (align)) == -1) + || (log2align = tree_log2 (align)) == -1) { error ("requested alignment %qE is not a positive power of 2", align); @@ -5299,7 +5300,7 @@ check_user_alignment (const_tree align, bool objfi if (objfile) { unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT; - if (tree_to_shwi (align) > maxalign) + if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign) { error ("requested alignment %qE exceeds object file maximum %u", align, maxalign); @@ -5307,14 +5308,14 @@ check_user_alignment (const_tree align, bool objfi } } - if (log2bitalign >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT) + if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT) { error ("requested alignment %qE exceeds maximum %u", - align, 1U << (HOST_BITS_PER_INT - 1)); + align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1)); return -1; } - return log2bitalign; + return log2align; } /* Determine the ELF symbol visibility for DECL, which is either a Index: gcc/testsuite/gcc.dg/attr-aligned-3.c =================================================================== --- gcc/testsuite/gcc.dg/attr-aligned-3.c (nonexistent) +++ gcc/testsuite/gcc.dg/attr-aligned-3.c (working copy) @@ -0,0 +1,28 @@ +/* PR c/89812 - incorrect maximum in error: requested alignment '536870912' + exceeds maximum 2147483648 + { dg-do compile } + { dg-require-effective-target size32plus } */ + +#define POWALIGN(N) __attribute__ ((aligned ((__UINT64_TYPE__)1 << (N)))) + +typedef POWALIGN (28) char T28; + +/* The maximum alignment is constrained by the number of bits in int + on host minus 3: HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT. The test + assumes host int is 32-bits wide. */ +typedef POWALIGN (29) char X29; /* { dg-error "requested alignment .536870912. exceeds maximum 268435456" } */ +typedef POWALIGN (30) char X30; /* { dg-error "requested alignment .1073741824. exceeds maximum 268435456" } */ +typedef POWALIGN (31) char X31; /* { dg-error "requested alignment .2147483648. exceeds maximum 268435456" } */ +typedef POWALIGN (32) char X32; /* { dg-error "requested alignment .4294967296. exceeds maximum 268435456" } */ +typedef POWALIGN (60) char X60; /* { dg-error "requested alignment .1152921504606846976. exceeds maximum 268435456" } */ +typedef POWALIGN (63) char X63; /* { dg-error "requested alignment .9223372036854775808. exceeds maximum 268435456" } */ + + +POWALIGN (28) char c28; + +POWALIGN (29) char c29; /* { dg-error "requested alignment .536870912. exceeds object file maximum 268435456" } */ +POWALIGN (30) char x30; /* { dg-error "requested alignment .1073741824. exceeds object file maximum 268435456" } */ +POWALIGN (31) char x31; /* { dg-error "requested alignment .2147483648. exceeds object file maximum 268435456" } */ +POWALIGN (32) char x32; /* { dg-error "requested alignment .4294967296. exceeds object file maximum 268435456" } */ +POWALIGN (60) char x60; /* { dg-error "requested alignment .1152921504606846976. exceeds object file maximum 268435456" } */ +POWALIGN (63) char x63; /* { dg-error "requested alignment .9223372036854775808. exceeds object file maximum 268435456" } */