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] |
This patch enables extended overflow handling for comparison ops so that the comparison can be done in an expanded type, or even in bignum mode if operating in ELIMINATED overflow check mode. The following test program: 1. with Text_IO; use Text_IO; 2. procedure Overflowm2 is 3. function r1 4. (a, b, c, d : Integer) return Boolean is 5. begin 6. return a + b + c + d <= Integer'Last; 7. end; 8. function r2 9. (a, b, c, d : Integer) return Boolean is 10. begin 11. return a * b * c * d >= Integer'First; 12. end; 13. begin 14. begin 15. Put_Line 16. ("r1 returns " & 17. Boolean'Image 18. (r1 (Integer'Last, Integer'Last, 19. -Integer'Last, -Integer'Last))); 20. exception 21. when Constraint_Error => 22. Put_Line ("r1 raises exception"); 23. end; 24. 25. begin 26. Put_Line 27. ("r2 returns " & 28. Boolean'Image 29. (r2 (Integer'Last, Integer'Last, 30. Integer'Last, 0))); 31. exception 32. when Constraint_Error => 33. Put_Line ("r2 raises exception"); 34. end; 35. end Overflowm2; In CHECKED mode (-gnato1) we get: r1 raises exception r2 raises exception since the first addition in r1 and the first multiplication in r2 result in values outside the bounds of Integer'Base. In MINIMIZED mode (-gnato2) we get: r1 returns TRUE r2 raises exception since we can compute the addition result in Long_Long_Integer, and do the comparison in Long_Long_Integer mode, but the second multiplication yields a value outside this range, so that causes an overflow. In ELIMINATE mode (-gnato3) we get: r1 returns TRUE r2 returns TRUE Because now we use Bignum arithmetic for the intermediate multiplication results, and the final comparison is also done in bignum mode. Tested on x86_64-pc-linux-gnu, committed on trunk 2012-10-01 Robert Dewar <dewar@adacore.com> * exp_ch4.adb (Expand_Compare_Minimize_Eliminate_Overflow): New procedure.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |