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 sanitizer/80350] New: UBSAN changes code semantics when -fno-sanitize-recover=undefined is used


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

            Bug ID: 80350
           Summary: UBSAN changes code semantics when
                    -fno-sanitize-recover=undefined is used
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: babokin at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---

Top of the trunk, x86_64.

The following test case when compiled with "-fsanitize=undefined
-fno-sanitize-recover=undefined -O0" produces incorrect result. Correct result
is 1. Incorrect is 0.

> cat f.cpp
#include <stdio.h>
unsigned int x = 3153848182U;
unsigned int y = 0;

void foo() {
  int a(!0 >> !x * 500740718);
  y = a;
}

int main () {
    foo ();
    printf("Result = %u\n", y);
    return 0;
}

> g++ f.cpp -o out -fsanitize=undefined -fno-sanitize-recover=undefined -O0
> ./out
Result = 0
> g++ f.cpp -o out -fsanitize=undefined -fno-sanitize-recover=undefined -O2
> ./out
Result = 1
> g++ f.cpp -o out -O0
> ./out
Result = 1
> g++ f.cpp -o out -O2
> ./out
Result = 1

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