google / google/sanitizers

MSAN fails to detect simple case on clang-8 Ubuntu 19.04

Open
#1,122 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
12.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I may be missing something, but I cannot seem to get Memory Sanitizer to work on the following example:

```c++
// msan.cc

#include
#include // std::launder
#include // std::move

template
class Box {
public:
Box() {}
void set(T v) {
new (&storage_) T(v);
}
T* get() {
return std::launder(reinterpret_cast(&storage_));
}
private:
std::aligned_storage_t storage_;
};

template
class Box2 {
public:
Box2() {}
void set(T v) {
storage_ = std::move(v);
}
T* get() {
return &storage_;
}
private:
T storage_;
};

int main(void) {
Box bstack;
Box* bheap = new Box();
Box2 b2stack;
Box2* b2heap = new Box2();

int sum = 0 +
*bstack.get() +
*bheap->get() +
*b2stack.get() +
*b2heap->get();
std::fprintf(stderr, "sum = %d\n", sum);

return 0;
}
```

Copiled and run via:
```
$ clang++ -std=c++17 -Wall -Wextra -O2 -g -fno-omit-frame-pointer -fsanitize=memory ./msan.cc -o msan && ./msan
sum = -2012436376
```

This is clang-8 on Ubuntu 19.04.

```
$ clang++ --version
clang version 8.0.0-3 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

What am I missing here?

Thanks!

Contributor guide

Open the contributing guide

Research direction

The minimal reproduction is the inline msan.cc example; start by compiling and running it with the reported clang++ command on clang 8 and Ubuntu 19.04. Compare the uninitialized reads through Box and Box2 and determine why Memory Sanitizer emits no diagnostic. Done means identifying the cause and establishing the expected sanitizer behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.