public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/96015] New: [regression] gcc-10.1.0 miscompiles Python on hppa
@ 2020-07-01  7:29 slyfox at inbox dot ru
  2020-07-01  7:30 ` [Bug target/96015] " slyfox at inbox dot ru
                   ` (44 more replies)
  0 siblings, 45 replies; 46+ messages in thread
From: slyfox at inbox dot ru @ 2020-07-01  7:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96015

            Bug ID: 96015
           Summary: [regression] gcc-10.1.0 miscompiles Python on hppa
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at inbox dot ru
                CC: dave.anglin at bell dot net, law at redhat dot com
  Target Milestone: ---
            Target: hppa2.0-unknown-linux-gnu

Originally reported as https://bugs.gentoo.org/729570 where gcc-10.1.0
miscompiles Python into generating invalid bytecode. I shrunk Python's code
into single file that illustrates the problem:

// $ cat bug_test.c
/*
   The test is extracted from Python-3.9.0 miscompilation
   on hppa2.0: https://bugs.gentoo.org/729570

   Original bug happens as an invalid bytecode generation
   due to bad results from 'long_richcompare(0xFFFFffff, 1, EQ)' calls.

Failure example:
  $ hppa2.0-unknown-linux-gnu-gcc -lm -Wsign-compare -Wall -O1 bug_test.c -o
good-bug
  $ hppa2.0-unknown-linux-gnu-gcc -lm -Wsign-compare -Wall -O2 bug_test.c -o
bad-bug
  $ ./good-bug
  long_richcompare(2, 1, EQ) = FALSE (expect FALSE)
  $ ./bad-bug
  long_richcompare(2, 1, EQ) = TRUE (expect FALSE)

*/

// We use '__attribute__((noipa));' aggressively to simulate
// unavailable function definitions from outside translation units.

static int cmp(int *lhs, int *rhs)
{
    int sign = *lhs - *rhs;

    // semantically this should be 'return 0;' but this condition is not
    // supposed to trigger on our input data.
    if (sign == 0) return 1;

    return sign;
}

static int yes(void) __attribute__((noipa));
static int yes(void) { return 1; }

static int long_richcompare(int *self, int *other, int op)
__attribute__((noipa));
static int long_richcompare(int *self, int *other, int op)
{
    int result;

    if (!yes() || !yes())
        return 0;

    if (self == other)
        result = 0;
    else
        result = cmp(self, other);

    // has to force jump table
    switch (op) {
        // only 0 case is used on actual data
        case 0: return (result == 0);

        case 1: return 0;
        case 3: return 0;
        case 5: if (result == 0) return 1; else return 0;
        default:
            __builtin_unreachable();
    }
}

#include <stdio.h>

int main() {
    int l = 2;
    int r = 1;

    int res = long_richcompare(&l, &r, 0);
    printf("long_richcompare(2, 1, EQ) = %s (expect FALSE)\n", res ? "TRUE" :
"FALSE");
}

^ permalink raw reply	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2021-02-09 20:21 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01  7:29 [Bug target/96015] New: [regression] gcc-10.1.0 miscompiles Python on hppa slyfox at inbox dot ru
2020-07-01  7:30 ` [Bug target/96015] " slyfox at inbox dot ru
2020-07-01  7:32 ` slyfox at inbox dot ru
2020-07-01  7:38 ` slyfox at inbox dot ru
2020-07-01  8:03 ` [Bug target/96015] [10/11 Regression] " rguenth at gcc dot gnu.org
2020-07-01  8:11 ` marxin at gcc dot gnu.org
2020-07-01  9:14 ` slyfox at inbox dot ru
2020-07-01  9:15 ` slyfox at inbox dot ru
2020-07-01 13:11 ` marxin at gcc dot gnu.org
2020-07-01 13:12 ` marxin at gcc dot gnu.org
2020-07-01 15:39 ` slyfox at inbox dot ru
2020-07-01 15:40 ` slyfox at inbox dot ru
2020-07-01 15:46 ` slyfox at inbox dot ru
2020-07-01 16:35 ` law at redhat dot com
2020-07-01 17:33 ` law at redhat dot com
2020-07-01 17:57 ` slyfox at inbox dot ru
2020-07-01 19:15 ` slyfox at inbox dot ru
2020-07-02  6:58 ` slyfox at inbox dot ru
2020-07-02  7:58 ` marxin at gcc dot gnu.org
2020-07-02  9:34 ` ebotcazou at gcc dot gnu.org
2020-07-02 17:15 ` slyfox at inbox dot ru
2020-07-02 17:15 ` slyfox at inbox dot ru
2020-07-02 17:16 ` slyfox at inbox dot ru
2020-07-02 20:21 ` slyfox at inbox dot ru
2020-07-02 20:50 ` slyfox at inbox dot ru
2020-07-02 21:35 ` slyfox at inbox dot ru
2020-07-02 22:36 ` slyfox at inbox dot ru
2020-07-02 23:16 ` [Bug rtl-optimization/96015] " ebotcazou at gcc dot gnu.org
2020-07-03  7:19 ` slyfox at inbox dot ru
2020-07-03  7:45 ` marxin at gcc dot gnu.org
2020-07-03  8:23 ` ebotcazou at gcc dot gnu.org
2020-07-03  9:23 ` ebotcazou at gcc dot gnu.org
2020-07-03 17:24 ` slyfox at inbox dot ru
2020-07-03 19:29 ` ebotcazou at gcc dot gnu.org
2020-07-06 20:31 ` law at redhat dot com
2020-07-07  8:09 ` ebotcazou at gcc dot gnu.org
2020-07-08 17:01 ` law at redhat dot com
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2021-01-14  9:04 ` rguenth at gcc dot gnu.org
2021-01-14 16:33 ` law at redhat dot com
2021-01-14 19:14 ` mikpelinux at gmail dot com
2021-01-15 16:54 ` ebotcazou at gcc dot gnu.org
2021-02-09 18:56 ` cvs-commit at gcc dot gnu.org
2021-02-09 18:59 ` cvs-commit at gcc dot gnu.org
2021-02-09 19:01 ` ebotcazou at gcc dot gnu.org
2021-02-09 20:21 ` dave.anglin at bell dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).