From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id D2B093835810 for ; Wed, 11 May 2022 08:54:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D2B093835810 Received: by mail-wr1-x42e.google.com with SMTP id v12so1927402wrv.10 for ; Wed, 11 May 2022 01:54:21 -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=FaVNjwPeiLZcsaP4uFLG1Q7H5kI1+0p4EsXOXKC2kx8=; b=YaXR4fwxpyIvKbiVPQpKJ0Jc6Hnx9STmfN9cA1M9VgsW0OB5fons/hfSgnLrsct9kK kMjJBB7mbiMhPJZrASfKBYO8YlkqRb+JfKbTG8pGzXqcbAssdy05sGGySPQBx6kQQqAU Xb/EYnosQW7o4udQZgpivPT1cuLdMMuNOPwbFIBqXu3EEp91DaOPLX7cf3df+RnmRyHl WzMRI+5nbZTCWH+8FKFP/Z7jXCMVknOfjnr6a+Gz2Fi5ddTNTgDOZ2olim+jbUUtXeHf EjxBWW6a0fRc4RCLFmaqKTflUvxcvODZGsY16aLrAHBYSrhoFCTPNSi5/6OOStHPpIOZ 4H0g== X-Gm-Message-State: AOAM5316smnc3MaxJRVZaMFTn2kCUG/SQ01aDg/wS5fm0NlLwIRpjG91 wZ3sCzTmGhyCYy2s3+QQGrIkJTQvV1lAxQ== X-Google-Smtp-Source: ABdhPJzMu/tqTVAA4RjvTPF0L0tbsaaWzGTqX9i1ZBDMW/i+egmOPtyNodhPVeHK0RN8mYty4NWSQw== X-Received: by 2002:a05:6000:178d:b0:20c:5bfd:4d7d with SMTP id e13-20020a056000178d00b0020c5bfd4d7dmr21599063wrg.23.1652259260486; Wed, 11 May 2022 01:54:20 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id a8-20020a7bc1c8000000b00394867d66ddsm1459402wmj.35.2022.05.11.01.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 01:54:20 -0700 (PDT) Date: Wed, 11 May 2022 08:54:19 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Avoid crash for -gnatR -gnatc Message-ID: <20220511085419.GA2165920@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9amGYk9869ThD9tj" Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Wed, 11 May 2022 08:54:24 -0000 --9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline If the -gnatR -gnatc are both given, then the compiler crashes. This patch fixes that, and avoids printing the uncomputed sizes and alignments that were causing the crash. (Previous versions of the compiler printed incorrect values in such cases.) Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * repinfo.adb (List_Object_Info): Do not try to print values that have not been computed (and so are No_Uint). (Rep_Not_Constant): Reverse sense and change name to Compile_Time_Known_Rep. This makes the code at call sites a little more readable. Simplify code to a single return statement. --9amGYk9869ThD9tj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb --- a/gcc/ada/repinfo.adb +++ b/gcc/ada/repinfo.adb @@ -190,9 +190,9 @@ package body Repinfo is procedure List_Type_Info (Ent : Entity_Id); -- List type info for type Ent - function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean; - -- Returns True if Val represents a variable value, and False if it - -- represents a value that is fixed at compile time. + function Compile_Time_Known_Rep (Val : Node_Ref_Or_Val) return Boolean; + -- Returns True if Val represents a representation value that is known at + -- compile time. procedure Spaces (N : Natural); -- Output given number of spaces @@ -908,10 +908,12 @@ package body Repinfo is procedure List_Object_Info (Ent : Entity_Id) is begin - -- The information has not been computed in a generic unit, so don't try - -- to print it. + -- If size and alignment have not been computed (e.g. if we are in a + -- generic unit, or if the back end is not being run), don't try to + -- print them. - if Sem_Util.In_Generic_Scope (Ent) then + pragma Assert (Known_Esize (Ent) = Known_Alignment (Ent)); + if not Known_Alignment (Ent) then return; end if; @@ -1055,20 +1057,7 @@ package body Repinfo is Get_Decoded_Name_String (Chars (Comp)); Name_Length := Prefix_Length + Name_Len; - if Rep_Not_Constant (Bofs) then - - -- If the record is not packed, then we know that all fields - -- whose position is not specified have starting normalized - -- bit position of zero. - - if not Known_Normalized_First_Bit (Comp) - and then not Is_Packed (Ent) - then - Set_Normalized_First_Bit (Comp, Uint_0); - end if; - - UI_Image_Length := 2; -- For "??" marker - else + if Compile_Time_Known_Rep (Bofs) then Npos := Bofs / SSU; Fbit := Bofs mod SSU; @@ -1098,6 +1087,18 @@ package body Repinfo is end if; UI_Image (Spos); + else + -- If the record is not packed, then we know that all fields + -- whose position is not specified have starting normalized + -- bit position of zero. + + if not Known_Normalized_First_Bit (Comp) + and then not Is_Packed (Ent) + then + Set_Normalized_First_Bit (Comp, Uint_0); + end if; + + UI_Image_Length := 2; -- For "??" marker end if; Max_Name_Length := Natural'Max (Max_Name_Length, Name_Length); @@ -2118,18 +2119,14 @@ package body Repinfo is end if; end List_Type_Info; - ---------------------- - -- Rep_Not_Constant -- - ---------------------- + ---------------------------- + -- Compile_Time_Known_Rep -- + ---------------------------- - function Rep_Not_Constant (Val : Node_Ref_Or_Val) return Boolean is + function Compile_Time_Known_Rep (Val : Node_Ref_Or_Val) return Boolean is begin - if No (Val) or else Val < 0 then - return True; - else - return False; - end if; - end Rep_Not_Constant; + return Present (Val) and then Val >= 0; + end Compile_Time_Known_Rep; --------------- -- Rep_Value -- @@ -2408,24 +2405,20 @@ package body Repinfo is procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is begin - if Rep_Not_Constant (Val) then - if List_Representation_Info < 3 or else No (Val) then - Write_Unknown_Val; - - else - if Paren then - Write_Char ('('); - end if; + if Compile_Time_Known_Rep (Val) then + UI_Write (Val, Decimal); + elsif List_Representation_Info < 3 or else No (Val) then + Write_Unknown_Val; + else + if Paren then + Write_Char ('('); + end if; - List_GCC_Expression (Val); + List_GCC_Expression (Val); - if Paren then - Write_Char (')'); - end if; + if Paren then + Write_Char (')'); end if; - - else - UI_Write (Val, Decimal); end if; end Write_Val; --9amGYk9869ThD9tj--