#2095 Broken compile-time int division (gcc-torture-execute-20021)


It seems division of integer literals is broken, resulting in nonzero results when small numbers are divided by big ones. To reproduce, remove the #if0 in gcc-torture-execute-20021010-1.c regression test.



  • Erik Petrich

    Erik Petrich - 2012-11-15
    • labels: --> C-Front End
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • status: open --> closed-fixed
  • Erik Petrich

    Erik Petrich - 2012-11-15

    Fixed in revision #8219.

  • Erik Petrich

    Erik Petrich - 2012-11-15

    Just to clarify the problem: (a/b)/c when b and c are literals was converted to (a/(b*c))/1. Because the multiplication was done using the C integer promotion rules, (b*c) may be too large to fit in an int and overflow yielding a different result than the original (a/b)/c. While conceivably one might be able to determine whether or not overflow would occur, there was also the problem of ensuring the expression would have the same type as the original. Because of these complications I decided it would be safest to simply disable this optimization.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks