From patchwork Fri Nov 7 13:48:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 408141 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 9E5BA1400A8 for ; Sat, 8 Nov 2014 00:49:12 +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:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Kj8ZZ9aG1Tf+z3qyQHP7QgAJ6Tu3jSfZ10lKrry40cO3TLJnMD Am9gssxU9mIs3woZiy2qF757vxBzOa1AA83ZyVi7H6Q/Xs4B1Oo2cAhMuN5pUE1U 6dec2tcGmjwx1th//QLltA8D1wkGCnzzdqAkIN6qoJPHZcDIk54rHybn8= 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=p1wewVxxG3lpobS1s6EkCUUEDw0=; b=lhYSZDPo+atBOpi6LBaL L/Xw1BbVXsBRndJc0rV4fiHKoFa8qBrFAR2hSu1olD/8ju9Bo/SC9i7wmXtH7Zbf HCZtQpopxA7S0wTrOhCLCC53VXPeuUua4KTOo2TXR3BYaWLSF8fv6sTgvea+36nO mWdv0dFshdY/Bf8Yc/GARxk= Received: (qmail 10525 invoked by alias); 7 Nov 2014 13:48:56 -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 10429 invoked by uid 89); 7 Nov 2014 13:48:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 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 (AES256-SHA encrypted) ESMTPS; Fri, 07 Nov 2014 13:48:54 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9ECA61165C1; Fri, 7 Nov 2014 08:48:52 -0500 (EST) 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 TMKJ6PfLX8jF; Fri, 7 Nov 2014 08:48:52 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 8EF78116505; Fri, 7 Nov 2014 08:48:52 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 8DCAD91A7E; Fri, 7 Nov 2014 08:48:52 -0500 (EST) Date: Fri, 7 Nov 2014 08:48:52 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Rejecting properly illegal iterator Message-ID: <20141107134852.GA7127@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This patch removes an infinite loop in the compiler, when an Ada 2012 iterator is attempted over an object without proper iterable aspects, and the code is compiled in SPARK mode. Compiling iter.adb must yield: iter.adb:12:21: cannot iterate over "R" iter.adb:12:21: to iterate directly over the elements of a container, write "of Obj" --- procedure Iter is pragma SPARK_Mode (On); type R is record X, Y, Z : Integer; end record; Obj : R; function Sum (X : R) return Integer is Result : Integer := 0; begin return Result : Integer := 0 Do for Val in Obj loop Result := Result + Val; end loop; end return; end; begin if Sum (Obj) /= 0 then null; end if; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-11-07 Ed Schonberg * sem_ch5.adb (Analyze_Iterator_Specification): return if name in iterator does not have any usable aspect for iteration. Index: sem_ch5.adb =================================================================== --- sem_ch5.adb (revision 217215) +++ sem_ch5.adb (working copy) @@ -2063,6 +2063,10 @@ Error_Msg_NE ("\to iterate directly over the elements of a container, " & "write `of &`", Name (N), Original_Node (Name (N))); + + -- No point in continuing analysis of iterator spec. + + return; end if; end if;