From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 5C820386D610 for ; Tue, 16 May 2023 08:41:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C820386D610 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f42c865535so80128725e9.1 for ; Tue, 16 May 2023 01:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684226491; x=1686818491; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=y4ufL05PQqHL559ccR6RanzPBAsEgQU+QWIpEVlP6ks=; b=DkWNciSAy24c8LXOdD12BK+mqMHTQfWIBJwp7/aHF2XnGjU3m198m0DD7Ex9yEd0Va 2TLcpqfWPLrwrc/BgYtSCRIWM44/AT2daPO5/pfAeFgMsfVB/8PWz5AEfVnQrbc2L3l8 hKiHnUvZd5eOBOOHVPqt1cGlRL3Ugz0zI7BeonL1Xsd7xDi0AA2NkPTWuCoC6c99v6zm ERARTl7ViElBrKVCbwWpuDcR8y9hhxcmZpyPpKLx16GJap15bggihyk1w7GAFm3L8u0w /k+gOy2jwDB6jnPCfWzACJy413e5QKDo+/SgJ5zsSeJrSn70OhtXF4QwRBPJJXJgFxPz 1oEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684226491; x=1686818491; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=y4ufL05PQqHL559ccR6RanzPBAsEgQU+QWIpEVlP6ks=; b=XYubB9L1yUPbM2LM4mbUrF38gXsZyPsDauZxAxY/VtRFZ/qh5Osa54lR+pQP5NUNij llyU49mI5W6MnhJmoXwNikwgIs5e/YiTE0l0Cav0ze8HH8ZiA8DyymTJ6yutkU6n2tkk AjRV6Y/Vb7+9fRjaPXnyhcITZeWIN7FHc8A/IBjtzm8ZOMFMgGgm+dv4iS3kXWD7UYo6 6cmVv6HxzLqIY4rywQi+Q5mZJS2ey7U9h8HmclZ7nC+g7ynnKWlEH9o33x69x5zq3hLq CUG87WrRATz3ITejeWdLJePBBjLG5rp1twwuX+UG1tN+9DQaVtbtqc0T6Hb0vvAc1kHY UuSA== X-Gm-Message-State: AC+VfDytVwEsJUkpbYVtWCGgTbsaFai5Gg88tBqC+etRA73jHP3TBKyt 7LqQFJo3JuGl4b2pljpZ+DQqgmsyLTVp+1PukTeTCw== X-Google-Smtp-Source: ACHHUZ7d8frPW3K3VaIKtaX/Gvc/zbuJvXMHCTcBz+AlmrVgl2WUQFcavTOKEI6uTJky0f9hJpvIlg== X-Received: by 2002:a05:600c:ac6:b0:3f4:2770:f7e9 with SMTP id c6-20020a05600c0ac600b003f42770f7e9mr18286930wmr.17.1684226491242; Tue, 16 May 2023 01:41:31 -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 f10-20020a7bcd0a000000b003f4f1b884b3sm1513482wmj.20.2023.05.16.01.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:41:30 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix internal error on 'Image applied to array component Date: Tue, 16 May 2023 10:41:29 +0200 Message-Id: <20230516084129.1502331-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.5 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 List-Id: From: Eric Botcazou This happens because the array component depends on a discriminant. gcc/ada/ * exp_imgv.adb (Rewrite_Object_Image): If the prefix is a component that depends on a discriminant, create an actual subtype for it. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_imgv.adb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb index 93fdb70306f..257f65badd0 100644 --- a/gcc/ada/exp_imgv.adb +++ b/gcc/ada/exp_imgv.adb @@ -2498,12 +2498,31 @@ package body Exp_Imgv is Attr_Name : Name_Id; Str_Typ : Entity_Id) is + Ptyp : Entity_Id; + begin + Ptyp := Etype (Pref); + + -- If the prefix is a component that depends on a discriminant, then + -- create an actual subtype for it. + + if Nkind (Pref) = N_Selected_Component then + declare + Decl : constant Node_Id := + Build_Actual_Subtype_Of_Component (Ptyp, Pref); + begin + if Present (Decl) then + Insert_Action (N, Decl); + Ptyp := Defining_Identifier (Decl); + end if; + end; + end if; + Rewrite (N, Make_Attribute_Reference (Sloc (N), - Prefix => New_Occurrence_Of (Etype (Pref), Sloc (N)), + Prefix => New_Occurrence_Of (Ptyp, Sloc (N)), Attribute_Name => Attr_Name, - Expressions => New_List (Relocate_Node (Pref)))); + Expressions => New_List (Unchecked_Convert_To (Ptyp, Pref)))); Analyze_And_Resolve (N, Str_Typ); end Rewrite_Object_Image; -- 2.40.0