https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108023
Bug ID: 108023 Summary: Incorrect line number in ASAN'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 ASAN at -O1 and above produce incorrect line numbers in the final reports (Line 15 v.s. Line 8). Compiler explorer: https://godbolt.org/z/4953EPr78 % cat a.c int a, b, c, g, f; static long d(int); long d(int h) { int **j = (int**)malloc(sizeof(int *) * sizeof(int)); for (int i = 0; i < sizeof(int); i++) j[i] = malloc(sizeof(f)); int *k = malloc(sizeof(int) * sizeof(g)); for (h=0; h <= 2; h++) { free(k); for (b=0; b <= 2; b++) k[3] = j[0][h]; } return k[a]; } void e() { c = d(0); } int main() { e(); return c; } % % gcc-tk -O0 -fsanitize=address -w -g a.c && ./a.out ================================================================= ==3175968==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200000009c at pc 0x00000040130f bp 0x7ffd47fc9fd0 sp 0x7ffd47fc9fc8 WRITE of size 4 at 0x60200000009c thread T0 #0 0x40130e in d /a.c:15 #1 0x4013a3 in e /a.c:21 #2 0x4013ba in main /a.c:25 ... % % gcc-tk -O2 -fsanitize=address -w -g a.c && ./a.out ================================================================ ==3254785==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200000009c at pc 0x000000401354 bp 0x7ffce8fa2e80 sp 0x7ffce8fa2e78 WRITE of size 4 at 0x60200000009c thread T0 #0 0x401353 in d /a.c:8 #1 0x4010e8 in e /a.c:21 #2 0x4010e8 in main /a.c:25 ... %