-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[YAML] Init local var not set by some branches #123137
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
[YAML] Init local var not set by some branches #123137
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-objectyaml Author: Vitaly Buka (vitalybuka) ChangesFull diff: https://github.com/llvm/llvm-project/pull/123137.diff 1 Files Affected:
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 7e94d01a971534..83e6cf76dd746f 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1588,7 +1588,7 @@ static bool isInteger(StringRef Val) {
void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) {
- ELFYAML::ELF_SHT Type;
+ ELFYAML::ELF_SHT Type = ELF::ET_NONE;
StringRef TypeStr;
if (IO.outputting()) {
if (auto *S = dyn_cast<ELFYAML::Section>(Section.get()))
|
Nevermind, that is an output parameter. It also gets set on hat branch |
OK, so I looked more. I think only on one branch this is not set, that is line 1601 if the condition below is false. For 1597 branch we should bail out in the 1613 condition below. |
it will not be set if:
|
nit: "Init local set by a single branche" typo and not sure what that is trying to tell me |
PTAL |
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.
This change is incorrect. For starters, ELF_SHT
is a section header type, but you're initialising it with an ELF type, which is an orthogonal concept.
I do agree that there is an unitialised variable usage. However, I don't think initialising the value like you have (even if it were a valid value to use) is correct. Please revert this PR and create a new one with the correct fix. (If necessary, I'll revert this PR, but would prefer it if the original contributor/reviewer did).
The "Type" field in the YAML is a mandatory field for sections. It doesn't make sense to try to parse the rest of the Section block if it doesn't have one, because the contents are meaningless. Instead, if the field has been found as unset when calling getStringValue
at line 1601 in this PR, we should bail out of the code. This could be detected either by TypeStr
being checked for being empty, or by checking the value of (I think) IO.EC
. I think I'd prefer the former, because this would mean (valid) section parsing isn't aborted because of unrelated errors elsewhere in the document.
I am sorry, I didn't realize this. I thought fallback to default is intentional.
Will do.
Thanks for the advice! |
This reverts commit 319c119.
Reverts #123137 It's a bug according to #123137 (review)
…123238) Reverts llvm/llvm-project#123137 It's a bug according to llvm/llvm-project#123137 (review)
Alternative to #123137 With -DMACHINE=EM_NONE, machine specific sections, like SHT_ARM_EXIDX, will fall to parse and set `Type`. This triggers msan on ``` yaml2obj llvm-project/llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml -DMACHINE=EM_NONE ```
It will not be set if:
(TypeStr.starts_with("SHT_") || isInteger(TypeStr)) == false
: here we want go to switch default.IO.mapRequired("Type", Type);
fail parsing. It sets error internally, so probably not important what happen next, so it's go to the switch