[clang] [clang][CodeGen] Fix stack-use-after-return in deferred annotations (PR #226942)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 29 20:51:55 PDT 2026


================
@@ -506,7 +506,10 @@ class CodeGenModule : public CodeGenTypeCache {
 
   // Store deferred function annotations so they can be emitted at the end with
   // most up to date ValueDecl that will have all the inherited annotations.
-  llvm::MapVector<StringRef, const ValueDecl *> DeferredAnnotations;
+  // The key owns its storage: not every mangled name handed to
+  // GetOrCreateLLVMFunction outlives the call.
+  llvm::MapVector<std::string, const ValueDecl *, llvm::StringMap<unsigned>>
----------------
efriedma-quic wrote:

It's a pretty terrible datastructure from a theoretical standpoint: it stores two copies of every string, and makes an additional copy every time you perform a lookup.  But it looks like this isn't the first place we're doing this, and this code isn't performance-sensitive, so I guess it's fine.

https://github.com/llvm/llvm-project/pull/226942


More information about the cfe-commits mailing list