From patchwork Wed Sep 13 10:35:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 813324 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-462018-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mx84t7V9"; 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 3xsdN96gpcz9sNV for ; Wed, 13 Sep 2017 20:35:21 +1000 (AEST) 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=dJDhjOTPjz5/c6AdUmPh0NBb1BkkgDwjfB5jJgbvSsVwwby0lU NlN3d7bPmbbeBKMP3j8RgY3UrK/a+G9MTgC2WFyKFrvAIgvFsGYKDOXXsCsKjpDg mSusbmwhWAhqiPDHliGydGrDJtm4EeQI1W64KSkMVSkEmqR9Sy3pPiGAI= 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=CSFq54crSmYLtQAfjrk9fB/kI6k=; b=mx84t7V9iGFaoRskKv5y /nQoik+xljW4amzjm48+g9s9VWXP5LVfrvw7S738B0X3z9ebmsvKWlwjccjvJt7/ O3aYY6cQrj/+r3mYlUs+CTmyMJm0acVt6+1R15nWA4S9/ReYhVakwfXO5TUrfZPI Y9SOrMa3Ut2PzL5OWWUxk2w= Received: (qmail 82732 invoked by alias); 13 Sep 2017 10:35:12 -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 82428 invoked by uid 89); 13 Sep 2017 10:35:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=13.3, accra, UD:A X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Sep 2017 10:35:10 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 33B855624E; Wed, 13 Sep 2017 06:35:09 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id NbOo0CtCKyll; Wed, 13 Sep 2017 06:35:09 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 21EDB5624C; Wed, 13 Sep 2017 06:35:09 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 1E1014B3; Wed, 13 Sep 2017 06:35:09 -0400 (EDT) Date: Wed, 13 Sep 2017 06:35:09 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou , Arnaud Charlet Subject: [Ada] Ineffective pragma Suppress (Alignment_Check) on warning Message-ID: <20170913103509.GA129511@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On platforms that require strict alignment of memory accesses, the per-object form of pragma Suppress (Alignment_Check) also disables the alignment warning associated with the check. That's not the case for the global form and this change fixes the inconsistency. Here's an example on a small package compiled with -gnatl: Compiling: p.ads Source file time stamp: 2017-08-07 10:41:19 Compiled at: 2017-08-07 15:19:52 1. package P is 2. 3. type Arr is array (1 .. 16) of Short_Integer; 4. 5. A : Arr; 6. 7. pragma Suppress (Alignment_Check); 8. 9. F1 : Float; 10. for F1 use at A'Address; -- no warning 11. 12. F2 : Float; 13. for F2 use at A'Address; -- warning | >>> warning: specified address for "F2" may be inconsistent with alignment >>> warning: program execution may be erroneous (RM 13.3(27)) >>> warning: alignment of "F2" is 4 >>> warning: alignment of "A" is 2 14. pragma Unsuppress (Alignment_Check, F2); 15. 16. pragma Unsuppress (Alignment_Check); 17. 18. F3 : Float; 19. for F3 use at A'Address; -- warning | >>> warning: specified address for "F3" may be inconsistent with alignment >>> warning: program execution may be erroneous (RM 13.3(27)) >>> warning: alignment of "F3" is 4 >>> warning: alignment of "A" is 2 20. 21. F4 : Float; 22. for F4 use at A'Address; -- no warning 23. pragma Suppress (Alignment_Check, F4); 24. 25. end P; 25 lines: No errors, 8 warnings Tested on x86_64-pc-linux-gnu, committed on trunk 2017-09-13 Eric Botcazou * sem_ch13.adb (Register_Address_Clause_Check): New procedure to save the suppression status of Alignment_Check on the current scope. (Alignment_Checks_Suppressed): New function to use the saved instead of the current suppression status of Alignment_Check. (Address_Clause_Check_Record): Add Alignment_Checks_Suppressed field. (Analyze_Attribute_Definition_Clause): Instead of manually appending to the table, call Register_Address_Clause_Check. (Validate_Address_Clauses): Call Alignment_Checks_Suppressed on the recorded address clause instead of its entity. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 252075) +++ sem_ch13.adb (working copy) @@ -203,6 +203,15 @@ -- renaming_as_body. For tagged types, the specification is one of the -- primitive specs. + procedure Register_Address_Clause_Check + (N : Node_Id; + X : Entity_Id; + A : Uint; + Y : Entity_Id; + Off : Boolean); + -- Register a check for the address clause N. The rest of the parameters + -- are in keeping with the components of Address_Clause_Check_Record below. + procedure Resolve_Iterable_Operation (N : Node_Id; Cursor : Entity_Id; @@ -318,6 +327,11 @@ Off : Boolean; -- Whether the address is offset within Y in the second case + + Alignment_Checks_Suppressed : Boolean; + -- Whether alignment checks are suppressed by an active scope suppress + -- setting. We need to save the value in order to be able to reuse it + -- after the back end has been run. end record; package Address_Clause_Checks is new Table.Table ( @@ -328,6 +342,26 @@ Table_Increment => 200, Table_Name => "Address_Clause_Checks"); + function Alignment_Checks_Suppressed + (ACCR : Address_Clause_Check_Record) return Boolean; + -- Return whether the alignment check generated for the address clause + -- is suppressed. + + --------------------------------- + -- Alignment_Checks_Suppressed -- + --------------------------------- + + function Alignment_Checks_Suppressed + (ACCR : Address_Clause_Check_Record) return Boolean + is + begin + if Checks_May_Be_Suppressed (ACCR.X) then + return Is_Check_Suppressed (ACCR.X, Alignment_Check); + else + return ACCR.Alignment_Checks_Suppressed; + end if; + end Alignment_Checks_Suppressed; + ----------------------------------------- -- Adjust_Record_For_Reverse_Bit_Order -- ----------------------------------------- @@ -5047,8 +5081,8 @@ and then not Is_Generic_Type (Etype (U_Ent)) and then Address_Clause_Overlay_Warnings then - Address_Clause_Checks.Append - ((N, U_Ent, No_Uint, O_Ent, Off)); + Register_Address_Clause_Check + (N, U_Ent, No_Uint, O_Ent, Off); end if; else -- If this is not an overlay, mark a variable as being @@ -5073,8 +5107,8 @@ if Compile_Time_Known_Value (Addr) and then Address_Clause_Overlay_Warnings then - Address_Clause_Checks.Append - ((N, U_Ent, Expr_Value (Addr), Empty, False)); + Register_Address_Clause_Check + (N, U_Ent, Expr_Value (Addr), Empty, False); end if; end; end if; @@ -12254,6 +12288,22 @@ end if; end Push_Scope_And_Install_Discriminants; + ----------------------------------- + -- Register_Address_Clause_Check -- + ----------------------------------- + + procedure Register_Address_Clause_Check + (N : Node_Id; + X : Entity_Id; + A : Uint; + Y : Entity_Id; + Off : Boolean) + is + ACS : constant Boolean := Scope_Suppress.Suppress (Alignment_Check); + begin + Address_Clause_Checks.Append ((N, X, A, Y, Off, ACS)); + end Register_Address_Clause_Check; + ------------------------ -- Rep_Item_Too_Early -- ------------------------ @@ -13465,7 +13515,7 @@ -- Check for known value not multiple of alignment if No (ACCR.Y) then - if not Alignment_Checks_Suppressed (ACCR.X) + if not Alignment_Checks_Suppressed (ACCR) and then X_Alignment /= 0 and then ACCR.A mod X_Alignment /= 0 then @@ -13510,7 +13560,7 @@ -- Note: we do not check the alignment if we gave a size -- warning, since it would likely be redundant. - elsif not Alignment_Checks_Suppressed (ACCR.X) + elsif not Alignment_Checks_Suppressed (ACCR) and then Y_Alignment /= Uint_0 and then (Y_Alignment < X_Alignment