On Tue, 2006-02-28 at 18:59 -0500, Daniel Jacobowitz wrote: > On Tue, Feb 28, 2006 at 03:40:37PM -0700, Jeffrey A Law wrote: > > Here's a great example from uintp.adb (which is the cause of the > > testsuite hang FWIW) > > > > We have a loop with the following termination code in uintp.num_bits > > > > # BLOCK 8 > > # PRED: 5 [100.0%] (fallthru,exec) 6 (fallthru,dfs_back,exec) > > # num_2 = PHI <num_49(5), num_10(6)>; > > # bits_1 = PHI <bits_50(5), bits_13(6)>; > > <L7>:; > > num.265_5 = (types__TintB) num_2; > > if (num.265_5 <= 0) goto <L5>; else goto <L4>; > > # SUCC: 7 (true,exec) 6 (false,exec) > > ... > > > Sooooo, why am I bringing this up? Because num can actually have > > the value 0x80000000 at runtime, which is out of its type's > > MIN/MAX range. And what do you think happens? Well, given the > > (valid) simplification of the loop test and the way "num" is > > assigned within the loop (num = num / 2), the loop never terminates. > > I've been following this entire thread, and I think there's a serious > disconnect between the parties - it's unfortunate that none of the > tree-ssa folks involved know Ada as I suspect that would straighten > it out in a hurry. This is a perfect example. Now that we have some > concrete code that's causing a problem, let's take a look at it > (bear in mind, I don't know Ada either): > > function Num_Bits (Input : Uint) return Nat is > Bits : Nat; > Num : Nat; > > begin > if UI_Is_In_Int_Range (Input) then > Num := abs (UI_To_Int (Input)); > Bits := 0; > > else > Bits := Base_Bits * (Uints.Table (Input).Length - 1); > Num := abs (Udigits.Table (Uints.Table (Input).Loc)); > end if; > > while Types.">" (Num, 0) loop > Num := Num / 2; > Bits := Bits + 1; > end loop; > > return Bits; > end Num_Bits;
The specifications in uintp.ads says: function Num_Bits (Input : Uint) return Nat; -- Approximate number of binary bits in given universal integer. -- This function is used for capacity checks, and it can be one -- bit off without affecting its usage. So this is a hint function, anything not hanging should do, like if UI_Is_In_Int_Range (Input) then return Nat'Size; else ... > I'm going to assume that UI_Is_In_Int_Range isn't true for 0x80000000. > The other case is still assigning 0x80000000 to Nat somehow. I'd be > amazed if that's really valid Ada! Could someone who knows the > language comment, please? Ada checks are off when compiling the FE, in full Ada you should get a Constraint_Error on the abs line on int'first. You should get an exception it if you put a pragma Unsuppress (All_Checks); before begin. So this is likely to be a FE Ada coding bug and not a FE/ME/BE interface issue, thanks for spotting this! Laurent