<div dir="ltr">Hello all,<div><br></div><div style>While I understand that debug data is best-effort, I am running into some trouble with an analysis tool I'm building partially using an LLVM pass.  There are two (seemingly directly related) cases where debug data is not missing (which wouldn't be a problem for me) but very misleading.</div>

<div style><br></div><div style>First, in the case of multi-line statements, clang will assign the debug data for each expression to be the first line of the statement but continue incrementing the column number past the number of columns on the line.  The following code gives an example:</div>

<div style>[1] int foo(){</div><div style>[2]   int x, y, z;</div><div style>[3]   if(x < y ||</div><div style>[4]      y < z){</div><div style>[5]     x++;</div><div style>[6]   }</div><div style>[7] }</div><div style>

In this example, when my LLVM pass gets the bitcode both the (x<y) and (y<z) expressions are assigned DebugLocs which have line number 3 (but with increasing column numbers).</div><div style><br></div><div style>Second, in the case of a do-while statement where the closing } and the while condition are not on the same line, all expressions in the while condition are assigned the line number of the }.  The following code gives an example:</div>

<div style>[1] int foo(){</div><div style>[2]   int x;</div><div style>[3]   do</div><div style>[4]   {</div><div style>[5]     x++;</div><div style>[6]   }</div><div style>[7]   while(x < 10);</div><div style>[8] }</div>

<div style>In this case, the DebugLoc for the (x<10) expression lists line number 6.</div><div style><br></div><div style>The first case is not so difficult for me to handle, but the second seems much more difficult to recognize and deal with.  Note that these problems will also show up in a normal gdb session if the debug symbols are generated by clang, and one will be unable to set a breakpoint on line 7 in example 2 above.</div>

<div style><br></div><div style>Does anyone have any insight into this issue?  I am willing to look into it myself if no one is extremely familiar with debug data generation, but I have very limited knowledge and experience with the clang codebase, so I would definitely appreciate any pointers to appropriate source locations and/or ideas about precisely what causes this behavior you would be willing to provide.</div>

<div style><br></div><div style>Thanks,</div><div style>Peter</div></div>