This is the mail archive of the gcc-bugs@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]

[Bug middle-end/80362] New: gcc miscompiles arithmetic with signed char


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

            Bug ID: 80362
           Summary: gcc miscompiles arithmetic with signed char
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

Created attachment 41156
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41156&action=edit
Reproducer.

GCC produces wrong code for a bunch of different architectures.
Reproducer:
#include <stdio.h>

signed char var_0 = 0;
signed char var_1 = 128; 

void foo () {
    //(signed char)(-(signed char)(128)) / 3 should be equal to (signed
char)(-var_1) / 3;
    var_0 = (signed char)(-var_1) / 3;
}

int main () {
    foo ();
    printf("%d\n", var_0);
    return 0;
}
Error:
>$ g++ -O0 -march=broadwell repr.c ; ./a.out
-42
>$ g++ -O3 -march=broadwell repr.c ; ./a.out 
42

GCC version:
rev. 246778
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/vsevolod/workspace/gcc-dev/bin-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/vsevolod/workspace/gcc-dev/trunk/configure
--prefix=/home/vsevolod/workspace/gcc-dev/bin-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.1 20170407 (experimental) (GCC)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]