[clang] [clang][CodeGen] Fix stack-use-after-return in deferred annotations (PR #226942)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 03:14:04 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Philipp Dominik Schubert (pdschbrt)
<details>
<summary>Changes</summary>
CodeGenModule::DeferredAnnotations was keyed by StringRef, but not every mangled name passed to GetOrCreateLLVMFunction outlives the call. CodeGenVTables::maybeEmitThunk mangles the thunk name into a stack-local SmallString and hands it to GetAddrOfThunk, so for an annotated virtual function the map retained a reference into a frame that was gone by the time EmitGlobalAnnotations looked the key up.
ASan reports this as a stack-use-after-return in EmitGlobalAnnotations, with the freed frame being maybeEmitThunk's 'Name'. The user-visible effect is that annotations silently disappear from the this-adjusting thunks once the dead frame has been reused.
Make the key own its storage, using StringMap<unsigned> as the MapVector map type so lookups still hash a StringRef without allocating.
---
Full diff: https://github.com/llvm/llvm-project/pull/226942.diff
4 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+4)
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-2)
- (modified) clang/lib/CodeGen/CodeGenModule.h (+4-1)
- (added) clang/test/CodeGenCXX/attr-annotate-thunk.cpp (+40)
``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````
</details>
https://github.com/llvm/llvm-project/pull/226942
More information about the cfe-commits
mailing list