[MSan] Destructor poisoning of trivial base includes reused tail padding
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
LLM Text. The problem is real, although I didn't check it's proposed solution
-----
MemorySanitizer's use-after-destructor instrumentation produces a false
positive when another base subobject occupies the reusable tail padding of
a trivially destructible polymorphic base.
Reproducer: https://godbolt.org/z/v59Yfs4Ea
Compile with:
clang++ -std=c++17 -O0 -g \
-fsanitize=memory \
-fsanitize-memory-use-after-dtor \
-fPIE -pie repro.cpp
Clang 14 exits successfully. Clang 15 and current trunk report
use-of-uninitialized-value inside ReadDuringDestruction::~ReadDuringDestruction().
The object layout is:
- Polymorphic: sizeof=16, data size=12
- ReadDuringDestruction base: offset 12
SanitizeDtorTrivialBase passes BaseLayout.getSize() (16) to the destructor
poisoning callback before ReadDuringDestruction's destructor runs. This
poisons bytes 12–15, even though they contain the still-live base's `value`
member.
Current code:
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGClass.cpp
The instrumentation appears to need the base's data size rather than its
standalone size, or otherwise avoid poisoning reusable tail padding.
Contributor guide
Research direction
Start in clang/lib/CodeGen/CGClass.cpp at SanitizeDtorTrivialBase and reproduce the report with the linked Godbolt example using the provided Clang and MemorySanitizer flags. Trace the size passed to the destructor-poisoning callback and verify that the still-live base member is not poisoned. Done means the reproducer no longer reports a false positive while destructor poisoning remains 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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100