Use-after-poison error in clang::Decl::addAttr when linking with pre-compiled clang

I am using clang libTooling as a third party dependency in a project I’m working on. I would like to build and test my project using AddressSanitizer. However, I am running into a problem where I get a use-after-poison error in clang::Decl::addAttr, during parsing.

My test case is this:

TEST(MutationReplaceBinaryOperatorTest, BasicTest) {
  std::string original = "void foo() { }";
  auto ast_unit = clang::tooling::buildASTFromCodeWithArgs(original, {"-w"});
}```

and at the end of this message is part of the stack trace I get from asan.

When I build the clang unit tests from source with asan, and add this test into one of the clang unit test files, it runs without error.

So it seems there's some issue with me using a pre-built version of clang and then compiling my project with asan flags.

My understanding of asan is that it offers binary compatibility - i.e., it should be OK to link asan-compiled code (my project) with non-asan-compiled code (the release of clang that I downloaded).

Does anyone have advice on whether there are some gotchas there I might be missing?

Thanks!


==190092==ERROR: AddressSanitizer: use-after-poison on address 0x62100000fbe8 at pc 0x00000044fa63 bp 0x7ffe33b99450 sp 0x7ffe33b98c10
WRITE of size 8 at 0x62100000fbe8 thread T0
#0 0x44fa62 in memcpy (/home/afd/dev/dredd/tempbuild/src/libdreddtest/libdreddtest+0x44fa62)
#1 0x13c43f5 in clang::Decl::addAttr(clang::Attr*) (/home/afd/dev/dredd/tempbuild/src/libdreddtest/libdreddtest+0x13c43f5)
#2 0x128fa55 in clang::ASTContext::buildImplicitRecord(llvm::StringRef, clang::TagTypeKind) const (/home/afd/dev/dredd/tempbuild/src/libdreddtest/libdreddtest+0x128fa55)
#3 0x12a8d33 in clang::ASTContext::getCFConstantStringDecl() const (/home/afd/dev/dredd/tempbuild/src/libdreddtest/libdreddtest+0x12a8d33)