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

            Bug ID: 108014
           Summary: Incorrect line number in UBSAN's report
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                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, marxin at 
gcc dot gnu.org
  Target Milestone: ---

For the following code, GCC's UBsan at -O1 and above produces incorrect line
number in the final report.

Compiler explorer: https://godbolt.org/z/jvvdrfPdo

% cat -n a.c
     1  int a, b;
     2  char c[5];
     3  int d[1];
     4  static int g() {
     5    long e;
     6    b = __INT_MAX__;
     7    for (int f = 0; f < sizeof(c); f++)
     8      e = b + 1;
     9    return 0;
    10  }
    11  int main() {
    12    for (b = 0;b<1; b++) {
    13      d[a];
    14      g();
    15    }
    16  }
%
% gcc-tk -O0 -fsanitize=undefined -fno-sanitize-recover=all a.c && ./a.out
a.c:8:11: runtime error: signed integer overflow: 2147483647 + 1 cannot be
represented in type 'int'
% gcc-tk -O1 -fsanitize=undefined -fno-sanitize-recover=all a.c && ./a.out
a.c:12:20: runtime error: signed integer overflow: 2147483647 + 1 cannot be
represented in type 'int'
%

Reply via email to