-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[llvm-size] Initialize Radix to correct value #128447
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
[llvm-size] Initialize Radix to correct value #128447
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-llvm-binary-utilities Author: Vitaly Buka (vitalybuka) ChangesThis is very uncommon to recover from such errors. Full diff: https://github.com/llvm/llvm-project/pull/128447.diff 1 Files Affected:
diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp
index 0d7bf24832670..045237f161322 100644
--- a/llvm/tools/llvm-size/llvm-size.cpp
+++ b/llvm/tools/llvm-size/llvm-size.cpp
@@ -899,8 +899,10 @@ int llvm_size_main(int argc, char **argv, const llvm::ToolContext &) {
OutputFormat = darwin;
else if (V == "sysv")
OutputFormat = sysv;
- else
+ else {
error("--format value should be one of: 'berkeley', 'darwin', 'sysv'");
+ return 1;
+ }
V = Args.getLastArgValue(OPT_radix_EQ, "10");
if (V == "8")
Radix = RadixTy::octal;
@@ -908,8 +910,10 @@ int llvm_size_main(int argc, char **argv, const llvm::ToolContext &) {
Radix = RadixTy::decimal;
else if (V == "16")
Radix = RadixTy::hexadecimal;
- else
+ else {
error("--radix value should be one of: 8, 10, 16 ");
+ return 1;
+ }
for (const auto *A : Args.filtered(OPT_arch_EQ)) {
SmallVector<StringRef, 2> Values;
|
A lot of utilities using LLVMOption, including clang and lld, are able to report multiple unknown option errors or other parsing errors before exiting. What the motivation behind this change? |
Bad printf format string, when radix is not one of enum. If you realy think recovery is important, I'll change fallback to default on error. |
Created using spr 1.3.4
Done |
@vitalybuka if I understand @MaskRay advice correctly, we just want to finish the command line argument parsing before exiting because of errors. |
The default value of |
Done |
@thurstond @fmayer |
d15c615
into
users/vitalybuka/spr/main.llvm-size-early-return-with-error-on-invalid-args
Without the patch, invalid --radix, makes Radix to be 0, and result in invalid format specifier ` %#7 `, instead of e.g ` %#7x `.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have a test case that shows the default value is correct? Presumably that test would have flagged the missing default initialization otherwise.
I thought that probably not, because it's about warning in Asan. It's not even report error, just log output, which is inconvenient noise for me. However, if I read standard correctly, this case is UB https://godbolt.org/z/4G8xocceP |
Without the patch, invalid --radix, makes Radix to be 0, and result
in invalid format specifier
%#7
, instead of e.g%#7x
.