-
Notifications
You must be signed in to change notification settings - Fork 7
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
Parsing failures #158
Comments
n.b., the llvm-disasm helpfully shows the |
I think I'm encountering the same issue, or at least very similar one. To reproduce, compile the following file: double a = 0;
void b() {
for (int c = 0; c < 2; c++)
a++;
if (a)
a = 7;
}
int main() {
b();
return 0;
} With:
This will produce the following bitcode with Clang 10:
Attempting to parse this with
The code which parses llvm-pretty-bc-parser/src/Data/LLVM/BitCode/IR/Function.hs Lines 986 to 1026 in d1a6057
Comparing that with the corresponding code in LLVM, I'm skeptical that the code in |
Indeed, double a = 0;
int main() {
if (a) {
a++;
}
return 0;
} If you compile without
You will get this
And
You will get this
Note that we now have an
|
To add a wrinkle in all of this, the example in #158 (comment) demonstrates a situation where an
I'm not quite sure why this happens, but either way, the culprit is the presence of fast-math flags in the |
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
I'm seeing the following with the current
Does this mean the problem is fixed? |
I believe it is fixed, but I never figured out how to test against PX4_Autopilot, so I left this issue open as a reminder to do so—see #161 (comment). (Is the code you're testing from PX4_Autopilot?) |
I was encountering multiple issues with the PX4_Autopilot code base (using build-bom extracted BC files). It was definitely encountering the |
I've been unable to even compile PX4_Autopilot with Clang to obtain |
I can confirm that, after fixing some bugs in the handling of fast math flags, I also read the correct operand in a bitcode file obtained via LLVM 10. I need to fix some other bugs to be able to read the bitcode file obtained from LLVM 12. @RyanGlScott I am using a nix flake provided by @kquick to get bitcode files from PX4_Autopilot.
|
I have some candidate code (PX4_Autopilot) that is having parser decode failures with multiple symptoms:
fcmp
operation value. The operation values defined are 0-15, but the value that llvm-pretty-bc-parser is attempting to resolve is 24.ftrue
, I'm seeing invalid operand values for the instruction.Here's the llvm-dis output:
for llvm-pretty-bc-parser, the llvm-disasm has problems on
%149
, where the default toftrue
still shows:Note the second operand is decoded as
%147
whereas llvm decodes to%148
.It's unknown if there are other parsing problems, this one just happened to fail the parser due to the lookup in (1) above and therefore be detectable.
The text was updated successfully, but these errors were encountered: