Issue 180822
Summary [TSan] Missed location information
Labels new issue
Assignees
Reporter DrSergei
    I found regression between clang in master and system clang  (18.1.3 Ubuntu 24) in TSan when location information is missed.

main.cpp:
```c++
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

long my_global_variable;  // global variable

void *f1(void *p) {
 my_global_variable = 42;
    return NULL;
}

void *f2(void *p) {
 my_global_variable = 43;
    return NULL;
}

int main (int argc, char const *argv[])
{
    pthread_t t1;
    pthread_create(&t1, NULL, f1, NULL);

    pthread_t t2;
    pthread_create(&t2, NULL, f2, NULL);

 pthread_join(t1, NULL);
    pthread_join(t2, NULL);

    return 0;
}
```

output:
```sh
sergei@DrSergei:~/test$ clang++ --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
sergei@DrSergei:~/test$ clang++ -g -fsanitize=thread main.cpp -o main.exe
sergei@DrSergei:~/test$ ./main.exe
==================
WARNING: ThreadSanitizer: data race (pid=556025)
  Write of size 8 at 0x555556a60aa8 by thread T2:
    #0 f2(void*) /home/sergei/test/main.cpp:14:24 (main.exe+0xe0b08) (BuildId: 031b8bfb9def44034282a8f7be3fc92ccb67754c)

 Previous write of size 8 at 0x555556a60aa8 by thread T1:
    #0 f1(void*) /home/sergei/test/main.cpp:9:24 (main.exe+0xe0ab8) (BuildId: 031b8bfb9def44034282a8f7be3fc92ccb67754c)

  Location is global 'my_global_variable' of size 8 at 0x555556a60aa8 (main.exe+0x150caa8)

 Thread T2 (tid=556031, running) created by main thread at:
    #0 pthread_create <null> (main.exe+0x605ef) (BuildId: 031b8bfb9def44034282a8f7be3fc92ccb67754c)
    #1 main /home/sergei/test/main.cpp:24:5 (main.exe+0xe0b92) (BuildId: 031b8bfb9def44034282a8f7be3fc92ccb67754c)

  Thread T1 (tid=556030, finished) created by main thread at:
    #0 pthread_create <null> (main.exe+0x605ef) (BuildId: 031b8bfb9def44034282a8f7be3fc92ccb67754c)
 #1 main /home/sergei/test/main.cpp:21:5 (main.exe+0xe0b7b) (BuildId: 031b8bfb9def44034282a8f7be3fc92ccb67754c)

SUMMARY: ThreadSanitizer: data race /home/sergei/test/main.cpp:14:24 in f2(void*)
==================
ThreadSanitizer: reported 1 warnings
sergei@DrSergei:~/test$ /home/sergei/llvm-project/build/bin/clang++ -g -fsanitize=thread main.cpp -o main.exe
sergei@DrSergei:~/test$ ./main.exe
==================
WARNING: ThreadSanitizer: data race (pid=556105)
  Write of size 8 at 0x5555569ec798 by thread T2:
    #0 f2(void*) /home/sergei/test/main.cpp:14 (main.exe+0xea618)

  Previous write of size 8 at 0x5555569ec798 by thread T1:
    #0 f1(void*) /home/sergei/test/main.cpp:9 (main.exe+0xea5c8)

  Thread T2 (tid=556108, running) created by main thread at:
    #0 pthread_create /home/sergei/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1078 (main.exe+0x64aaa)
    #1 main /home/sergei/test/main.cpp:24 (main.exe+0xea6a2)

  Thread T1 (tid=556107, finished) created by main thread at:
    #0 pthread_create /home/sergei/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1078 (main.exe+0x64aaa)
    #1 main /home/sergei/test/main.cpp:21 (main.exe+0xea68b)

SUMMARY: ThreadSanitizer: data race /home/sergei/test/main.cpp:14 in f2(void*)
==================
ThreadSanitizer: reported 1 warnings
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to