Skip to content

[SYCL][ESIMD] Fix leak of the demangler output buffer - #23079

Open
uditagarwal97 wants to merge 1 commit into
intel:syclfrom
uditagarwal97:private/udit/esimd-demangler-buffer-leak
Open

[SYCL][ESIMD] Fix leak of the demangler output buffer#23079
uditagarwal97 wants to merge 1 commit into
intel:syclfrom
uditagarwal97:private/udit/esimd-demangler-buffer-leak

Conversation

@uditagarwal97

Copy link
Copy Markdown
Contributor

Problem

SYCLLowerESIMDPass::prepareForAlwaysInliner() demangles each function name to decide whether it belongs to the ESIMD namespaces:

id::OutputBuffer NameBuf;
NameNode->print(NameBuf);
StringRef Name(NameBuf.getBuffer(), NameBuf.getCurrentPosition());

return Name.starts_with("sycl::_V1::ext::intel::esimd::") ||
       Name.starts_with("sycl::_V1::ext::intel::experimental::esimd::");

llvm::itanium_demangle::OutputBuffer grows its storage with realloc and has a defaulted destructor — it does not own that storage, and the caller is required to std::free(getBuffer()). This lambda is invoked once per function in the module and leaks the buffer every time.

LeakSanitizer report (ASan+UBSan build, leak reached through clang++ -fsycl on an ESIMD test):

Direct leak of 998 byte(s) in 1 object(s) allocated from:
    #0 ... in realloc
    #1 ... in llvm::itanium_demangle::OutputBuffer::grow(unsigned long)
    #2 ... in SYCLLowerESIMDPass::prepareForAlwaysInliner(llvm::Module&)
    llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp:1985

Observed 998 B to ~14 KB per compilation depending on how many ESIMD functions the module contains.


Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

itanium_demangle's OutputBuffer does not own the buffer it reallocs; the caller
must free it. prepareForAlwaysInliner() created one for every function it
inspected and dropped it, leaking between 1 and 14 KB per compilation.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The cleanup follows OutputBuffer’s ownership contract without changing pass behavior.

Pull request overview

Fixes a per-function demangling buffer leak in ESIMD lowering.

Changes:

  • Adds <cstdlib> for std::free.
  • Frees the demangled-name buffer after namespace checks.
File summaries
File Description
llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp Releases OutputBuffer storage before returning.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@uditagarwal97
uditagarwal97 marked this pull request as ready for review September 1, 2026 23:44
@uditagarwal97
uditagarwal97 requested a review from a team as a code owner September 1, 2026 23:44
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

Successfully merging this pull request may close these issues.

2 participants