llvm / llvm/llvm-project

[compiler-rt][tysan] False positives with vtable pointer initialization

Open
#208,651 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt:tysan false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

# static or global variables with `vtable`
#### Flags: `-stdlib=libc++ -fsanitize=type -O0`
#### Compiler: x86-64 clang 22.1.0
#### Link: https://godbolt.org/z/1f9na6h36
#### Code:
```.cpp
class A {
public:
virtual ~A() = default;
char byte;
};

static A a;

int main() {}
```
#### Logs:
```
==1==ERROR: TypeSanitizer: type-aliasing-violation on address 0x5f724336cee8 (pc 0x5f7242a12067 bp 0x7ffeec53b2a0 sp 0x7ffeec53b230 tid 1)
WRITE of size 8 at 0x5f724336cee8 with type vtable pointer accesses an existing object of type A
#0 0x5f7242a12066 (/app/output.s+0x36066)
```
#### Explanation:
Likely a static lifetime + virtual object initialization. Removal of `byte` variable does not reproduce.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the minimal C++ example with the listed libc++, TypeSanitizer, optimization, and x86-64 settings, using the linked Compiler Explorer case. Trace the static object's virtual initialization and the reported vtable-pointer access. Done means this example no longer reports a type-aliasing violation while the sanitizer's valid diagnostics remain covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.