donat.nagy created this revision.
donat.nagy added reviewers: Szelethus, gamesh411, steakhal.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, mikhail.ramalho, 
a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
donat.nagy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`CheckerContext::getNoteTag` has a shorthand version that takes a plain 
'`StringRef Note`' instead of a lambda that calculates the note.

The old implementation of this method was incorrect because it created a lambda 
that captured the StringRef, which was dereferenced much later, when the 
NoteTags were visited.

In the current codebase this does not cause errors because this method is 
called only once, and there the `Note` argument is a string literal that 
remains valid. However, I tried to use this method in a checker that I was 
prototyping, and there it printed random memory junk (instead of the message 
that I composed in a local variable).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153889

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -316,8 +316,8 @@
   ///        bug path significantly shorter.
   const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
     return getNoteTag(
-        [Note](BugReporterContext &,
-               PathSensitiveBugReport &) { return std::string(Note); },
+        [Note = std::string(Note)](BugReporterContext &,
+               PathSensitiveBugReport &) { return Note; },
         IsPrunable);
   }
 


Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -316,8 +316,8 @@
   ///        bug path significantly shorter.
   const NoteTag *getNoteTag(StringRef Note, bool IsPrunable = false) {
     return getNoteTag(
-        [Note](BugReporterContext &,
-               PathSensitiveBugReport &) { return std::string(Note); },
+        [Note = std::string(Note)](BugReporterContext &,
+               PathSensitiveBugReport &) { return Note; },
         IsPrunable);
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to