From patchwork Fri Apr 12 13:09:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 236085 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 912A42C00A7 for ; Fri, 12 Apr 2013 23:09:18 +1000 (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=oAi/Ro/izaiInMg8pYZRmffJuvh3WfRXxNMMZDnK3/K7uE/eFF yaITgSlxTNBFnp3O7+D/7Sa782CsWXX7mf/AfNY8q5c6tG5q4BV0yj1EuspeVeSu 4Z9mW4eNlWYbt0T5naIzXbIMdOyRdzK+coHN1EQdLB2ik/blQg8CpFl58= 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=mK4IyhkLKO5P+tCjUyNwRjhtkA8=; b=nWNRhcu1UI6lCCprSBt7 97xBlk9TW4pahl0R59x2szyHiYx9O+NPvcZgFM6RSOumkAaJOTcBoxV+BgbBmEHT 2FqcOwM9DbrT12WykFNpiOOZ66Z/xPacN5n4xADRs4NZ69hq+tt7TaLwWZHqK1Wd 1HTjg5FKrCDUv0a1C/oxV7A= Received: (qmail 3806 invoked by alias); 12 Apr 2013 13:09:07 -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 3762 invoked by uid 89); 12 Apr 2013 13:09:07 -0000 X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO autolearn=ham version=3.3.1 Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 12 Apr 2013 13:09:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 61AB02E0E8; Fri, 12 Apr 2013 09:09:04 -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 zB5hupmAojHW; Fri, 12 Apr 2013 09:09:04 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 3E56E1C7C17; Fri, 12 Apr 2013 09:09:04 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 3DBA73FF09; Fri, 12 Apr 2013 09:09:04 -0400 (EDT) Date: Fri, 12 Apr 2013 09:09:04 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [Ada] Detect suspicious Contract_Cases instead of Contract_Case Message-ID: <20130412130904.GA22339@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Found: No The Contract_Case pragmas/aspect will be replaced soon by the slightly different Contract_Cases (plural, because all cases are given at once). This changes the detection of suspicious contracts so that it applies to Contract_Cases instead of Contract_Case. Tested on x86_64-pc-linux-gnu, committed on trunk 2013-04-12 Yannick Moy * sem_ch6.adb (Process_Contract_Cases): Update code to apply to Contract_Cases instead of Contract_Case pragma. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 197904) +++ sem_ch6.adb (working copy) @@ -7064,8 +7064,8 @@ -- Last non-trivial postcondition on the subprogram, or else Empty if -- either no non-trivial postcondition or only inherited postconditions. - Last_Contract_Case : Node_Id := Empty; - -- Last non-trivial contract-case on the subprogram, or else Empty + Last_Contract_Cases : Node_Id := Empty; + -- Last non-trivial contract-cases on the subprogram, or else Empty Attribute_Result_Mentioned : Boolean := False; -- Whether attribute 'Result is mentioned in a non-trivial postcondition @@ -7204,8 +7204,10 @@ ---------------------------- procedure Process_Contract_Cases (Spec : Node_Id) is - Prag : Node_Id; - Arg : Node_Id; + Prag : Node_Id; + Aggr : Node_Id; + Conseq : Node_Id; + Post_Case : Node_Id; Ignored : Traverse_Final_Result; pragma Unreferenced (Ignored); @@ -7213,42 +7215,47 @@ begin Prag := Spec_CTC_List (Contract (Spec)); loop - -- Retrieve the Ensures component of the contract-case, if any + if Pragma_Name (Prag) = Name_Contract_Cases then - Arg := Get_Ensures_From_CTC_Pragma (Prag); + Aggr := Expression (First + (Pragma_Argument_Associations (Prag))); - -- Ignore trivial contract-case when Ensures component is "True" - -- or "False". + Post_Case := First (Component_Associations (Aggr)); + while Present (Post_Case) loop + Conseq := Expression (Post_Case); - if Pragma_Name (Prag) = Name_Contract_Case - and then not Is_Trivial_Post_Or_Ensures (Expression (Arg)) - then - -- Since contract-cases are listed in reverse order, the first - -- contract-case in the list is the last in the source. + -- Ignore trivial contract-case when consequence is "True" + -- or "False". - if No (Last_Contract_Case) then - Last_Contract_Case := Prag; - end if; + if not Is_Trivial_Post_Or_Ensures (Conseq) then - -- For functions, look for presence of 'Result in Ensures + Last_Contract_Cases := Prag; - if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then - Ignored := Find_Attribute_Result (Arg); - end if; + -- For functions, look for presence of 'Result in + -- consequence expression. - -- For each individual contract-case, look for presence - -- of an expression that could be evaluated differently - -- in post-state. + if Ekind_In (Spec_Id, E_Function, E_Generic_Function) then + Ignored := Find_Attribute_Result (Conseq); + end if; - Post_State_Mentioned := False; - Ignored := Find_Post_State (Arg); + -- For each individual case, look for presence of an + -- expression that could be evaluated differently in + -- post-state. - if Post_State_Mentioned then - No_Warning_On_Some_Postcondition := True; - else - Error_Msg_N - ("`Ensures` component refers only to pre-state??", Prag); - end if; + Post_State_Mentioned := False; + Ignored := Find_Post_State (Conseq); + + if Post_State_Mentioned then + No_Warning_On_Some_Postcondition := True; + else + Error_Msg_N + ("contract case refers only to pre-state?T?", + Conseq); + end if; + end if; + + Next (Post_Case); + end loop; end if; Prag := Next_Pragma (Prag); @@ -7304,7 +7311,7 @@ No_Warning_On_Some_Postcondition := True; else Error_Msg_N - ("postcondition refers only to pre-state??", Prag); + ("postcondition refers only to pre-state?T?", Prag); end if; end if; end if; @@ -7352,12 +7359,12 @@ if Ekind_In (Spec_Id, E_Function, E_Generic_Function) and then (Present (Last_Postcondition) - or else Present (Last_Contract_Case)) + or else Present (Last_Contract_Cases)) and then not Attribute_Result_Mentioned and then No_Warning_On_Some_Postcondition then if Present (Last_Postcondition) then - if Present (Last_Contract_Case) then + if Present (Last_Contract_Cases) then Error_Msg_N ("neither function postcondition nor " & "contract cases mention result?T?", Last_Postcondition); @@ -7369,7 +7376,7 @@ end if; else Error_Msg_N - ("contract cases do not mention result?T?", Last_Contract_Case); + ("contract cases do not mention result?T?", Last_Contract_Cases); end if; end if; end Check_Subprogram_Contract;