From patchwork Thu May 24 13:05:14 2018 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: 919826 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-478374-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GwBWBsZT"; 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 40s8kc2GKVz9ryk for ; Thu, 24 May 2018 23:05:27 +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=sxtnrbA2x2r6iOIVbIPXywl3lwWu1xctdGiNevjRRky4ipRwk6 o5ga1AnpbtqkjD1j7FV1zSvqSuHh+qSrs/zNbPSvAMnepgevMrEaIPM9yOeuOpmE 3Tk2Nxmn3totlQxKqWULwjCFp138rC80BoFCtAYyzN5tGLM2iW8szZsaQ= 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=lViFjAjQ6dXHI21t+J2P/H386sQ=; b=GwBWBsZTT2ZOrYgBxSiQ RLPPPNTFjOsTFaUwLHcF/8qk3dplrzHPepsEyHjhTejsIZoSkfodBLk9mAsvz4dI f66THRYD6Ce5/zF2k5Lc5ia1NgrsSQi+pPWisRBG+xI65PfKVSQ5W9KFu/OPNR+b XbMGdTEtMi/LEx8GJBCL5es= Received: (qmail 42597 invoked by alias); 24 May 2018 13:05:20 -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 42339 invoked by uid 89); 24 May 2018 13:05:18 -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=Performance, elsif, Sem_Elab, Prevent 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; Thu, 24 May 2018 13:05:16 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0DA88117EDE; Thu, 24 May 2018 09:05:15 -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 s-bUWx7hp-Yg; Thu, 24 May 2018 09:05:14 -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 F0FC7117EDD; Thu, 24 May 2018 09:05:14 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id EFE434C2; Thu, 24 May 2018 09:05:14 -0400 (EDT) Date: Thu, 24 May 2018 09:05:14 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Crash on compilation unit instance Message-ID: <20180524130514.GA61968@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Do not generate a variable marker for a reference which appears within the formal part of an instantiation which acts as a compilation unit because there is no suitable insertion context. ------------ -- Source -- ------------ -- gnat.adc pragma SPARK_Mode (On); -- gen.ads generic Val_1 : Integer; Val_2 : Integer; package Gen is end Gen; -- pack.ads package Pack is Val : Integer := 123; function Get_Val return Integer; end Pack; -- inst.ads with Gen; with Pack; use Pack; package Inst is new Gen (Val, Get_Val); -- proc.adb with Pack; use Pack; procedure Proc (Val_1 : Integer := Val; Val_2 : Integer := Get_Val) is begin null; end Proc; ----------------- -- Compilation -- ----------------- $ gcc -c inst.ads $ gcc -c inst.ads -gnatd.F $ gcc -c proc.adb $ gcc -c proc.adb -gnatd.F Tested on x86_64-pc-linux-gnu, committed on trunk 2018-05-24 Hristian Kirtchev gcc/ada/ * sem_elab.adb (Build_Variable_Reference_Marker): Do not create a variable marker when the reference appears in the formal part of a compilation unit instance because there is no place to insert it. (In_Compilation_Instance_Formal_Part): New routine. --- gcc/ada/sem_elab.adb +++ gcc/ada/sem_elab.adb @@ -2274,9 +2274,44 @@ package body Sem_Elab is Read : Boolean; Write : Boolean) is + function In_Compilation_Instance_Formal_Part + (Nod : Node_Id) return Boolean; + -- Determine whether arbitrary node Nod appears within the formal part + -- of an instantiation which acts as a compilation unit. + function In_Pragma (Nod : Node_Id) return Boolean; -- Determine whether arbitrary node Nod appears within a pragma + ----------------------------------------- + -- In_Compilation_Instance_Formal_Part -- + ----------------------------------------- + + function In_Compilation_Instance_Formal_Part + (Nod : Node_Id) return Boolean + is + Par : Node_Id; + + begin + Par := Nod; + while Present (Par) loop + if Nkind (Par) = N_Generic_Association + and then Nkind (Parent (Par)) in N_Generic_Instantiation + and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit + then + return True; + + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (Par) then + exit; + end if; + + Par := Parent (Par); + end loop; + + return False; + end In_Compilation_Instance_Formal_Part; + --------------- -- In_Pragma -- --------------- @@ -2349,6 +2384,15 @@ package body Sem_Elab is and then Entity (N) /= Any_Id) then return; + + -- Nothing to do when the reference appears within the formal part of + -- an instantiation which acts as compilation unit because there is no + -- proper context for the insertion of the marker. + + -- Performance note: parent traversal + + elsif In_Compilation_Instance_Formal_Part (N) then + return; end if; Extract_Variable_Reference_Attributes