From patchwork Thu Jun 20 08:53:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1950025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=X0/6jQRU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W4Zjq6HHzz20KL for ; Thu, 20 Jun 2024 19:21:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2CDC3888C7C for ; Thu, 20 Jun 2024 09:21:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id DE769388A022 for ; Thu, 20 Jun 2024 08:53:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE769388A022 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 DE769388A022 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873639; cv=none; b=scumCdYtzd5NB1N02oZ4SPzJjDT9oxi/0/pqSie4hYupPIdvrSnXqrRFdB04w04nwVeASfcc6tmp98ZPuP2kxlrsYTKEmCYVWHCIbeK3fYkcmBNt5X53ss939WJbVBJQc2pgBkrqUY/bM4j+8dlYzA9ScqFxxFR2LFr6xP13Z2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873639; c=relaxed/simple; bh=krAJ1s6/nYtvYFPjdDz36toAKqiAapbLQBppVJ/9FIs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fObq3MWnm4QY8p/48y0PMajOoVP0WsOA1Dsdy+Q8ORNL/gpBGa3loxfwLQ11BoiCbQ+XlQWrLjYHRdyHZ+I6MGz7Kng0GgAZsWg2i6W+KP7GKwah9VG87Six9W6fCDALWTJJaXzFp7lcoujCCO9NVCFuMiNBBhdeLBqj+fhtUxw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-364ff42999eso333421f8f.3 for ; Thu, 20 Jun 2024 01:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718873629; x=1719478429; 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=EHYu/FUzekLHsMlvzI7sGgIwGN8qdhvjACSE4mWK8kE=; b=X0/6jQRUPYllUk5OMqL/E3ONsbVijv0bgUACzmkLs3Kc0sfQ7pqVXoWq5STxlAYVxf VrUZ14mbz6LwEtRrg1lCMTt+Tb5qFPHfMBvrbXe1Cwi1rxPJgp/5oDD/Q+F7X0Vek92d thTkxF5pcNsUTFjSX4h/r/kMZSEVJ3Z81BHj5QUu9jRN91K0TXBFOvKapjj3a9maWjyW AkDtbJVu3Jw1H7M9MjSxNnXjwEoA71G4DUfiviiyMurgYDW3Z1WqkfGszOKIHRzSApoq R8ydByfdG7y8i0ql/JwYeZcOfVx0pJMdFkGaFkvxvGiGkcFpfTvkgov81PABf6S47XMB R9pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718873629; x=1719478429; 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=EHYu/FUzekLHsMlvzI7sGgIwGN8qdhvjACSE4mWK8kE=; b=ShZd6fsmmzovSM8mmRSLcac7Rx1DrfMyoWxFIqOlurt9uApYNRAbTrO4Y6mUSlsEEM 5aYk2P3Ku9ckyeU/sMd/H08a7sy9XurQMTNCQYBVVrRfX6cDN4SUuvm9ppOD1gJnPXix jCxAQ2K0P1teaJ6E397ym2ZrMFQ0nYwa75cn7A0/V1tzMRbfz8fd0gsNYehHMlgPVwYg NzwUCnq3yhfOc/Y943WhYLe367rocYOXyeMTY2Z/748MMHjVDsIx823nLLvd1QuLN9Ry zRNHRsqJwFx6gwhdXdiR1hDtYZwvl2yeulGWUL2i/tfZqOz7sGniy2PCMmxTFQB8Qrlu 0YDA== X-Gm-Message-State: AOJu0YyjUwntZxIAGp4yXfDh4JB1yYm3mc+Yd0jxbxVTB/v5z+uShTdO hG3ssbmRI8P0VH0bWmZkMHIohedpIRe0aTGX/4paX7Q4+5z/DHQR+klmpl3cMrYrZYHi6IdC83E = X-Google-Smtp-Source: AGHT+IFLLsDOF1ld9kMjpHpVAd1dyUn//VNJuQrIivpi+lfQ8MCQiurfjitGBhLCqqRkkPhBe7Geww== X-Received: by 2002:a5d:5402:0:b0:360:6e47:ce8a with SMTP id ffacd0b85a97d-36317c774fcmr3446836f8f.32.1718873628697; Thu, 20 Jun 2024 01:53:48 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-363c795febfsm3305522f8f.104.2024.06.20.01.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 01:53:48 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 21/30] ada: Fix bogus error with "=" operator on array of private unchecked union Date: Thu, 20 Jun 2024 10:53:11 +0200 Message-ID: <20240620085321.2412421-21-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620085321.2412421-1-poulhies@adacore.com> References: <20240620085321.2412421-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Eric Botcazou The code is legal and, therefore, must be accepted by the compiler, but it must raise Program_Error at run time due to operands not having inferable discriminants and a warning be given at compile time (RM B.3.3(22-23)). gcc/ada/ * exp_ch4.adb (Expand_Array_Equality.Component_Equality): Copy the Comes_From_Source flag from the original test to the new one, and remove obsolete code dealing with unchecked unions. * sem_util.adb (Has_Inferable_Discriminants): Return False for an incomplete or private nominal subtype. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 27 +++++++++------------------ gcc/ada/sem_util.adb | 7 +++++-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 7349dfc306f..983f66231a2 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -1570,26 +1570,17 @@ package body Exp_Ch4 is (Outer_Type => Typ, Nod => Nod, Comp_Type => Component_Type (Typ), Lhs => L, Rhs => R); - -- If some (sub)component is an unchecked_union, the whole operation - -- will raise program error. + -- This is necessary to give the warning about Program_Error being + -- raised when some (sub)component is an unchecked_union. - if Nkind (Test) = N_Raise_Program_Error then + Preserve_Comes_From_Source (Test, Nod); - -- This node is going to be inserted at a location where a - -- statement is expected: clear its Etype so analysis will set - -- it to the expected Standard_Void_Type. - - Set_Etype (Test, Empty); - return Test; - - else - return - Make_Implicit_If_Statement (Nod, - Condition => Make_Op_Not (Loc, Right_Opnd => Test), - Then_Statements => New_List ( - Make_Simple_Return_Statement (Loc, - Expression => New_Occurrence_Of (Standard_False, Loc)))); - end if; + return + Make_Implicit_If_Statement (Nod, + Condition => Make_Op_Not (Loc, Right_Opnd => Test), + Then_Statements => New_List ( + Make_Simple_Return_Statement (Loc, + Expression => New_Occurrence_Of (Standard_False, Loc)))); end Component_Equality; ------------------ diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 8425359e052..4cdac9443e6 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -12119,11 +12119,14 @@ package body Sem_Util is and then Is_Constrained (Etype (Subtype_Mark (N))); -- For all other names, it is sufficient to have a constrained - -- Unchecked_Union nominal subtype. + -- Unchecked_Union nominal subtype, unless it is incomplete or + -- private because it cannot have a known discriminant part in + -- this case (RM B.3.3 (11/2)). else return Is_Unchecked_Union (Etype (N)) - and then Is_Constrained (Etype (N)); + and then Is_Constrained (Etype (N)) + and then not Is_Incomplete_Or_Private_Type (Etype (N)); end if; end Has_Inferable_Discriminants;