Skip to content

[TableGen] ASAN reports use-after-poison in StringInit::get, when used with BumpPtrAllocator #151430

@chanha-park

Description

@chanha-park

I've encountered an use-after-poison issue, while generating header using my own .td file and llvm::TableGenMain.

The below is the reduced input.

#include "llvm/Support/Allocator.h"
#include "llvm/TableGen/Record.h"

namespace dummy_ns {

// unused function
auto dummy_allocate(llvm::BumpPtrAllocator &allocator) {
  return allocator.Allocate(1, 16);
}

} // namespace dummy_ns

int main() {
  llvm::RecordKeeper records;

  auto foo = llvm::StringInit::get(records, "foo");
  auto bar = llvm::StringInit::get(records, "bar");
}

compiled with clang++ main.cc -lLLVMTableGen -lLLVMSupport -lLLVMDemangle -fsanitize=address -fno-rtti

The second StringInit::get causes use-after-poison.
Even though dummy_allocate is unused, the error is gone when I remove that function.
is this just false-positive?

Tested with libLLVM built in Release build, with sanitizer disabled.

I tested it in llvmorg-20.1.4 tag && main branch(d3f500f).
and reproducer in compiler-explorer: https://godbolt.org/z/rhYsK983j

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions