This is an archive of the discontinued LLVM Phabricator instance.

[MSan] Fix determinism issue when using msan-track-origins.
ClosedPublic

Authored by rupprecht on Aug 31 2022, 10:33 AM.

Details

Summary

When instrumenting allocas, 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 allocas 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);
}

Diff Detail

Event Timeline

rupprecht created this revision.Aug 31 2022, 10:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 10:33 AM
rupprecht requested review of this revision.Aug 31 2022, 10:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 10:33 AM
rupprecht edited the summary of this revision. (Show Details)Aug 31 2022, 10:34 AM
kda accepted this revision.Aug 31 2022, 11:08 AM
This revision is now accepted and ready to land.Aug 31 2022, 11:08 AM
This revision was landed with ongoing or failed builds.Sep 1 2022, 9:17 AM
This revision was automatically updated to reflect the committed changes.