Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jun 11, 2024

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.

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.
@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Jun 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 11, 2024

@llvm/pr-subscribers-lto

Author: Nikita Popov (nikic)

Changes

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 --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 {

@@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly use the variable opt_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that would also include the opt-remarks-hotness-threshold= prefix.

@nikic nikic merged commit 2b15fb1 into llvm:main Jun 11, 2024
7 of 8 checks passed
@nikic nikic deleted the gold-message-fix branch June 11, 2024 13:26
@HerrCai0907 HerrCai0907 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants