It may be possible, but it might not amount to much.
You have to understand that the very goal of optimizations is to alter the code to make it better (by some metric); and alteration means that the resulting code may not be meaningfully mapped to source code afterwards.
Some examples:
- Dead Code Elimination and the like will remove existing code, this mainly affect an attempt to place a breakpoint at a given source-line since there may not be code for that line
- Common Sub-Expression Elimination will create new temporary variables out of the blue to compute a sub-expression only once; those sub-expressions may have originally appeared in multiple expressions spread throughout the source code so the new instructions belong to multiple lines... or none at all
- Invariant Hoisting or Loop Rotation will change the order in which expressions are computed compared with the original source code so that you might see code executed at line 3 then 6 then 4, 5, 7...
- Loop Unrolling will copy/paste the body of a loop multiple times
And of course, those are local to a function, you also to have to account for
- Function Inlining will copy paste the body of a function at the call site
- Function Merging will take two different functions and remove one of them, forwarding its calls to the other (because they have the same behavior, of course)
After all that, is it even meaningful to try and reason in terms of source code ? No, not really. And of course I did not even account for the fact that all those transformations occurred on the Intermediate Representation and that the final emission of assembly code will scramble things even further (Strength Reduction, yeah!).
Honestly, even if addr2line
gives you some line, I would doubt its result... and then what is the point of asking in the first place ?