[all-commits] [llvm/llvm-project] 3031a2: [MSan] Fix determinism issue when using msan-track...

Jordan Rupprecht via All-commits all-commits at lists.llvm.org
Thu Sep 1 09:17:06 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3031a250dea9a2e92de8ed0d10dd8d471c6a1cb7
      https://github.com/llvm/llvm-project/commit/3031a250dea9a2e92de8ed0d10dd8d471c6a1cb7
  Author: Jordan Rupprecht <rupprecht at google.com>
  Date:   2022-09-01 (Thu, 01 Sep 2022)

  Changed paths:
    M llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
    A llvm/test/Instrumentation/MemorySanitizer/stable_set_alloca_origin.ll

  Log Message:
  -----------
  [MSan] Fix determinism issue when using msan-track-origins.

When instrumenting `alloca`s, we use a `SmallSet` (i.e. `SmallPtrSet`). When there are fewer elements than the `SmallSet` size, it behaves like a vector, offering stable iteration order. Once we have too many `alloca`s to instrument, the iteration order becomes unstable. This manifests as non-deterministic builds because of the global constant we create while instrumenting the alloca.

The test added is a simple IR file, but was discovered while building `libcxx/src/filesystem/operations.cpp` from libc++. A reduced C++ example from that:

```
// clang++ -fsanitize=memory -fsanitize-memory-track-origins \
//   -fno-discard-value-names -S -emit-llvm \
//   -c op.cpp -o op.ll
struct Foo {
  ~Foo();
};
bool func1(Foo);
void func2(Foo);
void func3(int) {
  int f_st, t_st;
  Foo f, t;
  func1(f) || func1(f) || func1(t) || func1(f) && func1(t);
  func2(f);
}
```

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D133034




More information about the All-commits mailing list