From patchwork Tue Jul 12 12:25:17 2022 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: 1655386 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=C+f4RfbO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lj0SS0rnKz9sB4 for ; Tue, 12 Jul 2022 22:29:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E727D38CB2A8 for ; Tue, 12 Jul 2022 12:29:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E727D38CB2A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657628981; bh=HJJwlKvYVvhitmWBNH7eQD7zuVEr4HBtHPwXbsf8ps4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=C+f4RfbO4T3hbbjiIDithMmf/bE4Fa3oidaFyF3EF5vsFURTpUcM6XuWM0jtkc7lC hs4/gTFWcRxSDkreQBRqDfAtlcmhpPgeooVII4CoOMjnFaFQTZINwg/DdpdkuGDv+/ HVWyw0mDedeRWRG9NcumdV+P8pBLPU9yLuCLUBPM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id AC2D03857C7D for ; Tue, 12 Jul 2022 12:25:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC2D03857C7D Received: by mail-ej1-x630.google.com with SMTP id l23so13993340ejr.5 for ; Tue, 12 Jul 2022 05:25:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=HJJwlKvYVvhitmWBNH7eQD7zuVEr4HBtHPwXbsf8ps4=; b=IzAlj01/u/NSSi70XD7wvRHL7c1+4IN9byWCr6g3Q7htpu8So/yTAy2mNDjcabXZpo WgD91I+HsuCSGZ3xd3svXh87JeGdiSjFtsgY7YqaJS92PanzaX4eHULfB4vGU65FT/nY /nVVrweaC/P9LRGrlvC9XOpUCMrfra3/hGK7FKn2O0EeLeO638GquLK/5/3JrAy94dWQ oe7BCV/U5wftj+h8H/qJVI8MYGzFg9LlpCIeAeaugUwkFevfGObQhurd3H2X9yVGL+X+ owFhMaWI/vBsRQwKoNNCtpfPXwscRkuNeRo90HszsLze65seSemFCzpmeEWO2ko3QuEu 5VYg== X-Gm-Message-State: AJIora+4MAEcFIpEoIX3JiW7cz6YMmRt7ufvLBabwbb4VJkAfKgJUlnt 1hVCYPHG4iILeodQNZ5zffWG3OyLpSZwQQ== X-Google-Smtp-Source: AGRyM1vUlfy1bbyFKj6E8s6ZzrnrtP6z/9rH5Zxo6/1TOfbaIdV7bXqmjQEIuGhcZjzX/+xxhY0fzA== X-Received: by 2002:a17:906:14d:b0:711:ffc4:3932 with SMTP id 13-20020a170906014d00b00711ffc43932mr23816865ejh.321.1657628718304; Tue, 12 Jul 2022 05:25:18 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id s10-20020a170906354a00b00705cdfec71esm3779173eja.7.2022.07.12.05.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 05:25:17 -0700 (PDT) Date: Tue, 12 Jul 2022 12:25:17 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Warn on unset objects in packages with no bodies Message-ID: <20220712122517.GA3404688@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Fix an inconsistency, where GNAT was warning about references to unset objects inside generic packages with no bodies but not inside ordinary packages with no bodies. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch7.adb (Analyze_Package_Declaration): Check references to unset objects. gcc/testsuite/ * gnat.dg/specs/discr5.ads: Expect new warnings. * gnat.dg/specs/empty_variants.ads: Likewise. * gnat.dg/specs/pack13.ads: Likewise. diff --git a/gcc/ada/sem_ch7.adb b/gcc/ada/sem_ch7.adb --- a/gcc/ada/sem_ch7.adb +++ b/gcc/ada/sem_ch7.adb @@ -1253,6 +1253,13 @@ package body Sem_Ch7 is (Context => N, Is_Main_Unit => Parent (N) = Cunit (Main_Unit)); end if; + + -- Warn about references to unset objects, which is straightforward + -- for packages with no bodies. For packages with bodies this is more + -- complicated, because some of the objects might be set between spec + -- and body elaboration, in nested or child packages, etc. + + Check_References (Id); end if; -- Set Body_Required indication on the compilation unit node diff --git a/gcc/testsuite/gnat.dg/specs/discr5.ads b/gcc/testsuite/gnat.dg/specs/discr5.ads --- a/gcc/testsuite/gnat.dg/specs/discr5.ads +++ b/gcc/testsuite/gnat.dg/specs/discr5.ads @@ -22,7 +22,7 @@ package Discr5 is subtype Rt is R(True); subtype Rf is R(False); - type R1 (D1 : Boolean) is new R (X) with record + type R1 (D1 : Boolean) is new R (X) with record -- { dg-warning "\"X\" may be referenced before it has a value" } FF : Float; case D1 is when True => @@ -38,7 +38,7 @@ package Discr5 is subtype R1t is R1 (True); subtype R1f is R1 (False); - type R2 (D2 : Boolean) is new R1 (Y) with record + type R2 (D2 : Boolean) is new R1 (Y) with record -- { dg-warning "\"Y\" may be referenced before it has a value" } FFF: System.Address; case D2 is when True => @@ -55,3 +55,4 @@ package Discr5 is subtype R2f is R2 (False); end Discr5; + diff --git a/gcc/testsuite/gnat.dg/specs/empty_variants.ads b/gcc/testsuite/gnat.dg/specs/empty_variants.ads --- a/gcc/testsuite/gnat.dg/specs/empty_variants.ads +++ b/gcc/testsuite/gnat.dg/specs/empty_variants.ads @@ -1,5 +1,4 @@ -- { dg-do compile } --- { dg-options "-gnatdF" } package Empty_Variants is @@ -23,10 +22,11 @@ package Empty_Variants is R : Rec; - I : Integer := R.I; + I : Integer := R.I; -- { dg-warning "\"R\.I\" may be referenced before it has a value" } J : Integer := R.J; K : Integer := R.K; L : Integer := R.L; M : Integer := R.L; end Empty_Variants; + diff --git a/gcc/testsuite/gnat.dg/specs/pack13.ads b/gcc/testsuite/gnat.dg/specs/pack13.ads --- a/gcc/testsuite/gnat.dg/specs/pack13.ads +++ b/gcc/testsuite/gnat.dg/specs/pack13.ads @@ -20,6 +20,6 @@ package Pack13 is A : Arr; - package My_G is new G (Boolean, A(True).B); + package My_G is new G (Boolean, A(True).B); -- { dg-warning "\"A\" may be referenced before it has a value" } end Pack13;