http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50865

             Bug #: 50865
           Summary: Invalid code generation for INT64_MIN % -1 on x86_64
    Classification: Unclassified
           Product: gcc
           Version: 4.5.3
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: j...@ristioja.ee


/*
 * Compiled under 64-bit enviroments with: -O0 -std=c99 -pedantic
 * Happens with GCC 4.5.3 on Gentoo, 4.4.5 on Debian and Apple's 4.2.1 on Mac.
 * The error does not appear when compiler is passed -m32.
 */

#include <inttypes.h>
#include <stdio.h>

#define PRINT_INT64(n, x) printf("(" #n ") r = %" PRId64 "\n", x)

int main(void) {

    /* (1) No crash: */
    PRINT_INT64(1, INT64_MIN % 1);

    /* (2) No crash: */
    {
      volatile int64_t m1 = 1;
      PRINT_INT64(2, INT64_MIN % m1);
    }

    /* (3) No crash: */
    {
      volatile int64_t m2 = -1;
      if (m2 == -1)
          PRINT_INT64(3, INT64_MIN % 1);
      else
          PRINT_INT64(3, INT64_MIN % -m2);
    }

    /* (4) Crash: */
    {
      volatile int64_t m3 = -1;
      PRINT_INT64(4, INT64_MIN % -m3);
    }

    return 0;
}

Reply via email to