[llvm] [DebugInfo] Pass string ownership to MarkupFilter (PR #75403)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 15:40:59 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
Last `getline` call destroys `InputString`, and `finish` fails
accesses dead `StringRef`.
Detected with #<!-- -->72677.
---
Full diff: https://github.com/llvm/llvm-project/pull/75403.diff
3 Files Affected:
- (modified) llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h (+2-2)
- (modified) llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp (+6-4)
- (modified) llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp (+1-1)
``````````diff
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h b/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h
index a1514d91702b9f..10613ec57586df 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h
@@ -39,7 +39,7 @@ class MarkupFilter {
///
/// Invalid or unimplemented markup elements are removed. Some output may be
/// deferred until future filter() or finish() call.
- void filter(StringRef Line);
+ void filter(std::string &&InputLine);
/// Records that the input stream has ended and writes any deferred output.
void finish();
@@ -142,7 +142,7 @@ class MarkupFilter {
MarkupParser Parser;
// Current line being filtered.
- StringRef Line;
+ std::string Line;
// A module info line currently being built. This incorporates as much mmap
// information as possible before being emitted.
diff --git a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
index f7503ef49693d8..01d49709f9b29c 100644
--- a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
@@ -41,8 +41,8 @@ MarkupFilter::MarkupFilter(raw_ostream &OS, LLVMSymbolizer &Symbolizer,
ColorsEnabled(
ColorsEnabled.value_or(WithColor::defaultAutoDetectFunction()(OS))) {}
-void MarkupFilter::filter(StringRef Line) {
- this->Line = Line;
+void MarkupFilter::filter(std::string &&InputLine) {
+ Line = std::move(InputLine);
resetColor();
Parser.parseLine(Line);
@@ -695,7 +695,9 @@ void MarkupFilter::reportTypeError(StringRef Str, StringRef TypeName) const {
// passed to beginLine().
void MarkupFilter::reportLocation(StringRef::iterator Loc) const {
errs() << Line;
- WithColor(errs().indent(Loc - Line.begin()), HighlightColor::String) << '^';
+ WithColor(errs().indent(Loc - StringRef(Line).begin()),
+ HighlightColor::String)
+ << '^';
errs() << '\n';
}
@@ -741,7 +743,7 @@ uint64_t MarkupFilter::adjustAddr(uint64_t Addr, PCType Type) const {
}
StringRef MarkupFilter::lineEnding() const {
- return Line.ends_with("\r\n") ? "\r\n" : "\n";
+ return StringRef(Line).ends_with("\r\n") ? "\r\n" : "\n";
}
bool MarkupFilter::MMap::contains(uint64_t Addr) const {
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 447c18abadc174..3d33534d95b7e0 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -430,7 +430,7 @@ static void filterMarkup(const opt::InputArgList &Args, LLVMSymbolizer &Symboliz
std::string InputString;
while (std::getline(std::cin, InputString)) {
InputString += '\n';
- Filter.filter(InputString);
+ Filter.filter(std::move(InputString));
}
Filter.finish();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/75403
More information about the llvm-commits
mailing list