[TypeSan] GNU's `start_lifetime_as` barrier does not break strict aliasing assumption
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```c++
template inline T *start_lifetime_as(void *addr) noexcept {
auto ptr = reinterpret_cast(addr);
// GNU's version of TBAA barrier
asm volatile("" : "=g"(ptr), "=m"(*ptr) : "0"(ptr), "m"(*ptr) : "memory");
return ptr;
}
int main(int argc, char **argv) {
int x = 100;
float *y = start_lifetime_as(&x);
*y += 2.0f; // Strict aliasing violation
return 0;
}
```
According to libstdc++'s expectation, the above code should be sufficient to let the compiler drop the strict aliasing assumption. However, TypeSan still reports
```
==3532943==ERROR: TypeSanitizer: type-aliasing-violation on address 0x7ffffae04d94 (pc 0x564a1b1da754 bp 0x7ffffae04cd0 sp 0x7ffffae04478 tid 3532943)
READ of size 4 at 0x7ffffae04d94 with type float accesses an existing object of type int
#0 0x564a1b1da753 in main (/tmp/a.out+0x43753) (BuildId: c8f8c3a13a92b6723d1c016387c3bb41b5d83332)
==3532943==ERROR: TypeSanitizer: type-aliasing-violation on address 0x7ffffae04d94 (pc 0x564a1b1da781 bp 0x7ffffae04cd0 sp 0x7ffffae04478 tid 3532943)
WRITE of size 4 at 0x7ffffae04d94 with type float accesses an existing object of type int
#0 0x564a1b1da780 in main (/tmp/a.out+0x43780) (BuildId: c8f8c3a13a92b6723d1c016387c3bb41b5d83332)
```
Contributor guide
Research direction
No project file or test is named; start with the C++ reproducer using GNU's start_lifetime_as barrier and run it under TypeSan. Compare the expected barrier behavior with the reported strict-aliasing diagnostics, and consider the issue done when the reproducer no longer reports the shown violations.
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
- 45/100