This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] for PRs 27639 and 26719


> I you have f.i.
>
> unsigned:3 a = 0;
> a = a + 9;
>
> you will get
>
> a = (unsigned:3)((unsigned)a + 9);
>
> which is basically wrapping.  Is the Ada situation different here?

Yes, Ada has base types for its integral types.

> So, eventually, nowrap_type_p should return nowrap_type_p (TREE_TYPE
> (type)) in your case?

No, it simply shouldn't say that unsigned subtypes wrap, hence it shoudd 
return true (more precisely, not return false :-).

> Yes, somewhere there's a bug...  do you have a testcase, btw?

Attached.  Compile at -O2 on x86 after redirecting your system.ads file to 
system-solaris-x86.ads.

-- 
Eric Botcazou
package p is

   function Replace_Slice
     (Source : Wide_String;
      Low    : Positive;
      High   : Natural;
      By     : Wide_String) return Wide_String;

end p;
package body p is

   function Replace_Slice
     (Source : Wide_String;
      Low    : Positive;
      High   : Natural;
      By     : Wide_String) return Wide_String
   is
      Result_Length : Natural;

   begin
      if Low > Source'Last + 1 or else High < Source'First - 1 then
         raise Program_Error;
      else
         Result_Length :=
           Source'Length - Natural'Max (High - Low + 1, 0) + By'Length;

         declare
            Result : Wide_String (1 .. Result_Length);

         begin
            if High >= Low then
               Result :=
                  Source (Source'First .. Low - 1) & By &
                  Source (High + 1 .. Source'Last);
            else
               Result := Source (Source'First .. Low - 1) & By &
                         Source (Low .. Source'Last);
            end if;

            return Result;
         end;
      end if;
   end Replace_Slice;

end p;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]