From patchwork Tue Jul 2 13:21:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 93224 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB2C0388217E for ; Tue, 2 Jul 2024 13:22:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 17F17388215D for ; Tue, 2 Jul 2024 13:21:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17F17388215D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 17F17388215D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::336 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719926505; cv=none; b=IGZZW4dfRBM/Aa6wN7CuIzgCifY0PNjpjwcG00slawt2I+1QgzDpM1yLqrBs/DHpjerZGOaI9NNEUjyIgMxv4POfcfrCh/Al+x0qW9tc5dKfCloqOIZ80eve56oRd1Z92QOH2nRH+rU513/12cj0/df/H4Lva79YKp6Odl5iW9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719926505; c=relaxed/simple; bh=etnKT2ntk/ME/lFeMk971ahTKcyTOEL7UHKJzF57UeI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CEqn42bkX0O2WTRq0RUdsOoEeDz4oODmYUFekhtqMmyuY96Z+m6jQsBACRwxLkCbuUeG5v55Uiu8UxPvWSUG+lUUY5Vq4JtveIe6zlwwm47YElqo2G/acnG+JNU+4Xirx/QQjcIfSIuiBGsbd7Jvne9u/ErEc7/kB0am3MYQ0fI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42573d3f7e4so27343725e9.0 for ; Tue, 02 Jul 2024 06:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1719926502; x=1720531302; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YgoxcePkGEKlh43izrGTC/U6sW037fAkSILcDdQVJQQ=; b=hMr5CRnGlR/0hj6eqqJvPp+Xp6ckPqdNuFipYH5u/SdKhIHX1+m2kLeX1a/PsGOiek nxGi4DJOdaM2x0d/P6LvqZ/5pBi+djuOKCSQOwJz27cXmXu+Zebqs1Nqr4PyTR98E671 gZaCXXns34SiiNAI1L1dFFFEtv+U46XDji2qb8+BD1q+mZ1XHh3wfr0Wl20EiLEAG0iR syteY++urUP1EJ+E1faX6UYpbJbbKXFb3DFMtiQ89GlpsbHb1hk8I+Tc4CLLEdO0LQrH DTJDCTjpsBWl9/0/8Pq7LsZSk9Vljwf061pYDhzJ6YnMEkVfCSnWR8O+kME83yfWwzl3 +Ezw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719926502; x=1720531302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YgoxcePkGEKlh43izrGTC/U6sW037fAkSILcDdQVJQQ=; b=rZNarfvwEyoMg8CaVIm58fCblzGvDiEuipdPlXg2dSHxP9FTRFLvf7nxV+6GEyqiZe 4aDjziAgCMUuadAdz21mOSehgAR4gaKkvPBxeR9I0jVoS2fXkx51MabD4sLekpVMrLMY 6rSZ7/XkhZWq138pOORJTI6dOQ6hUuYMCqs2FctgStC60Mt5xdlGJNwH9OJidlbq3nhM QTYixC/YbmfYzDMjEsiv04HrxUuflmSnSRwqc1gBk6k8Jm38v5dX4oCn/I26sfk08gD2 VA9ifuG+RZWId8z7aJq2gM0zuEKTb23PLU9RWqxTJOfhRPVNZZ//5FK4mlGmhpCQft5W +VPg== X-Gm-Message-State: AOJu0YyLbaPnFX5LFMPZPD0xpqmOIQwWrPVO0PFfgdte/Qry7fQL58XS 6zdqQXW5fY79c/l6aIdLl5AiwTy0xlY97rdJhZaU57WbCIbdoAHb+64yyWAsFHHqH5OQZ0hIMsM = X-Google-Smtp-Source: AGHT+IExSiCDHV0gbnWfPWqNcmbwInwivFi0x74Hj7oXJMbbpROMaCp272Km8jK/K9e4zd6US+hMng== X-Received: by 2002:a05:600c:3594:b0:424:9f28:22fc with SMTP id 5b1f17b1804b1-4257a02c888mr60055635e9.2.1719926501721; Tue, 02 Jul 2024 06:21:41 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:53cf:a5ff:fb60:5a70]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4256b09abbfsm197319895e9.35.2024.07.02.06.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 06:21:41 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 02/13] ada: Fix crash on box-initialized component with No_Default_Initialization Date: Tue, 2 Jul 2024 15:21:18 +0200 Message-ID: <20240702132130.523603-2-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240702132130.523603-1-poulhies@adacore.com> References: <20240702132130.523603-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Eric Botcazou The problem is that the implementation of the No_Default_Initialization restriction assumes that no type initialization routines are needed and, therefore, builds a dummy version of them, which goes against their use for box-initialized components in aggregates. Therefore this use needs to be flagged as violating the restriction too. gcc/ada/ * doc/gnat_rm/standard_and_implementation_defined_restrictions.rst (No_Default_Initialization): Mention components alongside variables. * exp_aggr.adb (Build_Array_Aggr_Code.Gen_Assign): Check that the restriction No_Default_Initialization is not in effect for default initialized component. (Build_Record_Aggr_Code): Likewise. * gnat_rm.texi: Regenerate. Tested on x86_64-pc-linux-gnu, committed on master. --- ...nd_implementation_defined_restrictions.rst | 4 +- gcc/ada/exp_aggr.adb | 41 +++++++++++-------- gcc/ada/gnat_rm.texi | 6 +-- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/gcc/ada/doc/gnat_rm/standard_and_implementation_defined_restrictions.rst b/gcc/ada/doc/gnat_rm/standard_and_implementation_defined_restrictions.rst index cf4657b7050..0e9162a1906 100644 --- a/gcc/ada/doc/gnat_rm/standard_and_implementation_defined_restrictions.rst +++ b/gcc/ada/doc/gnat_rm/standard_and_implementation_defined_restrictions.rst @@ -163,8 +163,8 @@ No_Default_Initialization .. index:: No_Default_Initialization [GNAT] This restriction prohibits any instance of default initialization -of variables. The binder implements a consistency rule which prevents -any unit compiled without the restriction from with'ing a unit with the +of variables or components. The binder implements a consistency check that +prevents any unit without the restriction from with'ing a unit with the restriction (this allows the generation of initialization procedures to be skipped, since you can be sure that no call is ever generated to an initialization procedure in a unit with the restriction active). If used diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 01ad1dcd437..df228713a28 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -1486,14 +1486,16 @@ package body Exp_Aggr is -- object creation that will invoke it otherwise. else - if Present (Base_Init_Proc (Base_Type (Ctype))) - or else Has_Task (Base_Type (Ctype)) - then - Append_List_To (Stmts, - Build_Initialization_Call (N, - Id_Ref => Indexed_Comp, - Typ => Ctype, - With_Default_Init => True)); + if Present (Base_Init_Proc (Ctype)) then + Check_Restriction (No_Default_Initialization, N); + + if not Restriction_Active (No_Default_Initialization) then + Append_List_To (Stmts, + Build_Initialization_Call (N, + Id_Ref => Indexed_Comp, + Typ => Ctype, + With_Default_Init => True)); + end if; -- If the component type has invariants, add an invariant -- check after the component is default-initialized. It will @@ -3185,6 +3187,8 @@ package body Exp_Aggr is elsif Box_Present (Comp) and then Has_Non_Null_Base_Init_Proc (Etype (Selector)) then + Check_Restriction (No_Default_Initialization, N); + if Ekind (Selector) /= E_Discriminant then Generate_Finalization_Actions; end if; @@ -3216,15 +3220,18 @@ package body Exp_Aggr is end if; end; - Append_List_To (L, - Build_Initialization_Call (N, - Id_Ref => Make_Selected_Component (Loc, - Prefix => New_Copy_Tree (Target), - Selector_Name => - New_Occurrence_Of (Selector, Loc)), - Typ => Etype (Selector), - Enclos_Type => Typ, - With_Default_Init => True)); + if not Restriction_Active (No_Default_Initialization) then + Append_List_To (L, + Build_Initialization_Call (N, + Id_Ref => Make_Selected_Component (Loc, + Prefix => + New_Copy_Tree (Target), + Selector_Name => + New_Occurrence_Of (Selector, Loc)), + Typ => Etype (Selector), + Enclos_Type => Typ, + With_Default_Init => True)); + end if; -- Prepare for component assignment diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index dc5721689cb..4feef7e1f9f 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -19,7 +19,7 @@ @copying @quotation -GNAT Reference Manual , Jun 24, 2024 +GNAT Reference Manual , Jun 27, 2024 AdaCore @@ -12594,8 +12594,8 @@ coextensions. See 3.10.2. @geindex No_Default_Initialization [GNAT] This restriction prohibits any instance of default initialization -of variables. The binder implements a consistency rule which prevents -any unit compiled without the restriction from with’ing a unit with the +of variables or components. The binder implements a consistency check that +prevents any unit without the restriction from with’ing a unit with the restriction (this allows the generation of initialization procedures to be skipped, since you can be sure that no call is ever generated to an initialization procedure in a unit with the restriction active). If used