[llvm] [gold] Don't pass StringRef to message() (PR #95083)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 01:34:47 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lto

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

This is a printf style variadic function. If using a "%s" format, we should pass "const char *" rather than "StringRef".

The use of data() here is safe because we know that the StringRef was originally derived from a null-terminated string.

---
Full diff: https://github.com/llvm/llvm-project/pull/95083.diff


1 Files Affected:

- (modified) llvm/tools/gold/gold-plugin.cpp (+3-2) 


``````````diff
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 265ebcbff5877..0b175a3852e42 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -307,7 +307,8 @@ namespace options {
     } else if (opt.consume_front("opt-remarks-hotness-threshold=")) {
       auto ResultOrErr = remarks::parseHotnessThresholdOption(opt);
       if (!ResultOrErr)
-        message(LDPL_FATAL, "Invalid remarks hotness threshold: %s", opt);
+        message(LDPL_FATAL, "Invalid remarks hotness threshold: %s",
+                opt.data());
       else
         RemarksHotnessThreshold = *ResultOrErr;
     } else if (opt.consume_front("opt-remarks-format=")) {
@@ -319,7 +320,7 @@ namespace options {
     } else if (opt.consume_front("time-trace-granularity=")) {
       unsigned Granularity;
       if (opt.getAsInteger(10, Granularity))
-        message(LDPL_FATAL, "Invalid time trace granularity: %s", opt);
+        message(LDPL_FATAL, "Invalid time trace granularity: %s", opt.data());
       else
         time_trace_granularity = Granularity;
     } else {

``````````

</details>


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


More information about the llvm-commits mailing list