Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: LeakSanitizer detects "leak" in immortal static object #1753

Open
jemfinch opened this issue May 1, 2024 · 1 comment
Open

Comments

@jemfinch
Copy link

jemfinch commented May 1, 2024

It seems like if your class stores a pointer as a uintptr_t and stores any information in the MSBs of the resulting integer, LeakSanitizer believes it's leaked the allocated memory:

#include <bit>
#include <cstdint>

struct StoresPointerAsInteger {
  static constexpr uintptr_t kMask = 1ULL << 63;
  StoresPointerAsInteger() : p(std::bit_cast<uintptr_t>(new int) | kMask) {}
  ~StoresPointerAsInteger() { delete std::bit_cast<int*>(p & ~kMask); }
  uintptr_t p;
};

int main(int argc, char** argv) {
  static auto* p = new StoresPointerAsInteger;
}

This tickles LeakSanitizer for me.

@jemfinch jemfinch changed the title LeakSanitizer detects "leak" in immortal static object False positive: LeakSanitizer detects "leak" in immortal static object May 1, 2024
@jemfinch
Copy link
Author

jemfinch commented May 2, 2024

So I think I'm running afoul of MaybeUserPointer at https://github.com/llvm/llvm-project/blob/3d65bd935a91439c483c56a966edc283a2b1130d/compiler-rt/lib/lsan/lsan_common.cpp#L260 which is returning false if certain MSBs of the word are set. I'm not personally familiar with LAM_U57, but I would like to keep using the 16 MSBs that my processor isn't using. Definitely willing to learn more about why I shouldn't, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant