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

            Bug ID: 80386
           Summary: UBSAN: false positive - constant folding and
                    reassosiation before instrumentation
           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: ---

gcc ubsan incorrectly does code instrumentation triggering false positive
alarm.

This looks like expression reassosiation and constant folding were done before
UBSAN instrumentation, turning legal code to illegal. 

> cat f.cpp
static unsigned long long int member_1_3 = 13996271126042720493ULL;

int main() {
  // 2921 - 14573 + MAX_INT
  (((2921 + 0) - short(member_1_3)) + 0x7fffffff) >> 0;
  return 0;
}


> g++ -fsanitize=undefined -O0 -o out f.cpp
> ./out
f.cpp:5:37: runtime error: signed integer overflow: -2147480728 - 14573 cannot
be represented in type 'int'


I'm using top of the trunk gcc.

Reply via email to