-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
[DebugInfo@O2][Dexter] Speculated BB presents illegal variable value to debugger #38111
Comments
assigned to @CarlosAlbertoEnciso |
Could you add the version number of llvm/clang you were using? Also, it might be helpful to paste in the output of |
The testcase is so short that the output of llc -stop-after=livedebugvalues would even fit :-) |
I think the bad IR is coming out of FoldTwoEntryPHINode in SimplifyCFG: instead of erasing or fixing the llvm.dbg.value calls when the transform triggers, it just unconditionally sinks them out of the if statement. |
Version of clang/llvm is trunk @ r340912 built yesterday, output of a.out: file format ELF64-x86-64 0x00000060: DW_TAG_variable |
I have followed your suggestion of erasing the 'llvm.dbg.value' calls when the transform triggers. Created a general utility function that can be used, in other similar problems that have been reported by the use of DExTer. |
Proposed fix: [https://reviews.llvm.org/D51976 | D51976] |
[Copying my comment from https://reviews.llvm.org/D51976] Having read the testcase now, I understand why you are dropping the debug info. I would like to point out that we could do better. If we extended llvm.dbg.value to take more than one LLVM SSA Value, then we could produce a DIExpression that selects either %add or %sub depending on the value of %cmp. Let me know if you are interested in implementing this, it should be relatively straight forward to do and would come in useful in all sorts of other situations, too. |
Davide and I recently sketched an idea for how to extend dbg.value but then never implemented it. The idea was to turn @llvm.dbg.value(metadata %val, metadata !DILocalVariable(), metadata !DIExpression()) into a varargs function @llvm.dbg.value(metadata %val0, metadata !DILocalVariable(), metadata !DIExpression(), [metadata %val1, ...]) and in DIExpression we add new operators DW_OP_LLVM_ARG1, DW_OP_LLVM_ARG2, ... that push the contents of %val1, %val2, ... onto the DIExpression stack. Argument0 would remain implicit, this way the scheme is fully backwards compatible. |
The patch has been committed at: |
mentioned in issue #38116 |
Extended Description
Speculating a basic block into a select IR insn causes an illegal variable value to be presented to the debugger. Taking the code below, compiled -O2 -g for x86_64 with trunk, on the line "if (read == 4)" both gdb and lldb report that the value of "result" is two, where it should be zero.
The value two isn't calculated in the execution of this program, and when compiled with -O0 "result" is correctly reported zero on that line. More interestingly, the illegal value doesn't actually seem to be read from a speculated instruction, "result" is reported as two from the moment the volatile loads are done.
I get the impression that something DWARFy is going wrong, as the DW_AT_location expression for "result" looks way more complicated that it needs to be.
Found using DExTer ( https://github.com/SNSystems/dexter ).
-------->8--------
int
main()
{
volatile int foo = 4;
int read = foo;
int read1 = foo;
int result = 0;
if (read == 4) {
result = read1 + 2;
} else {
result = read1 - 2;
}
return result;
}
--------8<--------
The text was updated successfully, but these errors were encountered: