From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 112293857028 for ; Tue, 18 Jul 2023 13:13:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 112293857028 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-wr1-x435.google.com with SMTP id ffacd0b85a97d-3159da54e95so5115313f8f.3 for ; Tue, 18 Jul 2023 06:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1689686025; x=1690290825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rcPEN1DykcQejiAc2US5coZPxxXZPFTU9wooK2/BJ0g=; b=lCfWjtW+bxqyASQeIbOM17Xa+udXzfzLg/73IAeZ0K7llDJ1HSHKJOXSlZ7DXPylBz g2bUaCrXRvgDU049HVX5AP+6iHn8zxljZPqilytzK282pXvo6s9reAVifWTac5ZJlFAc bvcsLH/zd7Oxss/4S24lwbJBVWSZnDQgWO/NIv/ST+N42OYBbMtg7bexdodOjY+1aLzf PQ2KBSr4X6q/WJe3t0Zqz8ufwFgTyTcaLLiz7YS+n7aUe/xTgNfQ7uZE7tCQvjkqU/kK DD9UpRZNrES36NzglXUig0BYb1yznISYycUlqc7MwG5yAuhswRUk0/HONIw7ebeWyfEN OHHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689686025; x=1690290825; 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=rcPEN1DykcQejiAc2US5coZPxxXZPFTU9wooK2/BJ0g=; b=gYdg5SRhiFpTz5Wpy6y4/QcNKqtxpzNfoK2egw6yqxE2HiK6WZXQFBfxjYpmePIZNc qB/vj0CspVzaJl+szOLb6eqozaWxQ6YkdoUSnVMOsakNTNIk1XvKiFBx9DoZP1Bekf3Q VZbHNwwj/8+G3Rge3XAQp3V2WyEMlzRx4q3YF8fdc8TAiMv5QiwQnNzIM9EUH5nEwpVN tyHAK/hXRMGaxnDSi4Oh09l0f7Sfq5Zx0Sm46eWgikpqNWWqjIaUUuYiJ4kuUsnEzw6q QyIa7KIOtg0agoh1XkYgTJACf8Q+ghVRTMaf9rcH0xJ76ctDwo0mbFQo/JyDUppr2ebL 2VVA== X-Gm-Message-State: ABy/qLaLfLgvwVglHNkSYB0n+iUy/8I1QxaCnWSCOPOSVFn0AtTl2Q0C gU9TtPjImNZNiwUPVDuzP7JUQJJR2peLh9dwUjSvPg== X-Google-Smtp-Source: APBJJlFsyXnA2HHxN6CEZDKlgbGWmsI0wsMvnq5EQv0S96v6hKTsmZf7D1SA/EYJG/XwT+N88hyBYA== X-Received: by 2002:adf:e0c3:0:b0:315:ad1a:5abc with SMTP id m3-20020adfe0c3000000b00315ad1a5abcmr1690748wri.5.1689686024962; Tue, 18 Jul 2023 06:13:44 -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 e16-20020adffc50000000b0031432c2fb95sm2390011wrs.88.2023.07.18.06.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 06:13:44 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Constraint_Error caused by 'Image applied to interface type Date: Tue, 18 Jul 2023 15:13:43 +0200 Message-Id: <20230718131343.81574-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.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 List-Id: From: Javier Miranda When the prefix of 'Image is used with a class-wide interface type object, the frontend does not generate code to displace the pointer to the underlying object to reference its base, and this is required to invoke Ada.Tags.Wide_Wide_Expanded_Name. gcc/ada/ * exp_imgv.adb (Rewrite_Object_Image): fix type of formal. Found reading sources. (Expand_Wide_Image_Attribute): ditto. (Expand_Wide_Wide_Image_Attribute): ditto. (Rewrite_Object_Image): ditto. * exp_put_image.adb (Build_Image_Call): For class-wide interface type prefix generate code to displace the pointer to the object to reference the base of the underlying object. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_imgv.adb | 8 ++++---- gcc/ada/exp_put_image.adb | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb index a31ce1d8c8f..6bcfec667a9 100644 --- a/gcc/ada/exp_imgv.adb +++ b/gcc/ada/exp_imgv.adb @@ -61,7 +61,7 @@ package body Exp_Imgv is procedure Rewrite_Object_Image (N : Node_Id; - Pref : Entity_Id; + Pref : Node_Id; Attr_Name : Name_Id; Str_Typ : Entity_Id); -- AI12-0124: Rewrite attribute 'Image when it is applied to an object @@ -1830,7 +1830,7 @@ package body Exp_Imgv is procedure Expand_Wide_Image_Attribute (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); - Pref : constant Entity_Id := Prefix (N); + Pref : constant Node_Id := Prefix (N); Rnn : constant Entity_Id := Make_Temporary (Loc, 'S'); Lnn : constant Entity_Id := Make_Temporary (Loc, 'P'); Rtyp : Entity_Id; @@ -1938,7 +1938,7 @@ package body Exp_Imgv is procedure Expand_Wide_Wide_Image_Attribute (N : Node_Id) is Loc : constant Source_Ptr := Sloc (N); - Pref : constant Entity_Id := Prefix (N); + Pref : constant Node_Id := Prefix (N); Rnn : constant Entity_Id := Make_Temporary (Loc, 'S'); Lnn : constant Entity_Id := Make_Temporary (Loc, 'P'); Rtyp : Entity_Id; @@ -2493,7 +2493,7 @@ package body Exp_Imgv is procedure Rewrite_Object_Image (N : Node_Id; - Pref : Entity_Id; + Pref : Node_Id; Attr_Name : Name_Id; Str_Typ : Entity_Id) is diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb index 9eda3231c6b..0c357f1c547 100644 --- a/gcc/ada/exp_put_image.adb +++ b/gcc/ada/exp_put_image.adb @@ -1190,10 +1190,41 @@ package body Exp_Put_Image is Parameter_Associations => New_List (Sink_Exp, String_Exp)); end Put_String_Exp; + -- Local variables + + Tag_Node : Node_Id; + -- Start of processing for Build_Image_Call begin if Is_Class_Wide_Type (U_Type) then + + -- For interface types we must generate code to displace the pointer + -- to the object to reference the base of the underlying object. + + -- Generate: + -- To_Tag_Ptr (Image_Prefix'Address).all + + -- Note that Image_Prefix'Address is recursively expanded into a + -- call to Ada.Tags.Base_Address (Image_Prefix'Address). + + if Is_Interface (U_Type) then + Tag_Node := + Make_Explicit_Dereference (Loc, + Unchecked_Convert_To (RTE (RE_Tag_Ptr), + Make_Attribute_Reference (Loc, + Prefix => Duplicate_Subexpr (Image_Prefix), + Attribute_Name => Name_Address))); + + -- Common case + + else + Tag_Node := + Make_Attribute_Reference (Loc, + Prefix => Duplicate_Subexpr (Image_Prefix), + Attribute_Name => Name_Tag); + end if; + -- Generate qualified-expression syntax; qualification name comes -- from calling Ada.Tags.Wide_Wide_Expanded_Name. @@ -1208,10 +1239,7 @@ package body Exp_Put_Image is (Make_Function_Call (Loc, Name => New_Occurrence_Of (RTE (RE_Wide_Wide_Expanded_Name), Loc), - Parameter_Associations => New_List ( - Make_Attribute_Reference (Loc, - Prefix => Duplicate_Subexpr (Image_Prefix), - Attribute_Name => Name_Tag))), + Parameter_Associations => New_List (Tag_Node)), Wide_Wide => True); Qualification : constant Node_Id := -- 2.40.0