[llvm] r244405 - Fix dangling reference in DwarfLinker.cpp. The original code

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 08:09:55 PDT 2015


On Sat, Aug 8, 2015 at 2:03 PM, Yaron Keren via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: yrnkrn
> Date: Sat Aug  8 16:03:19 2015
> New Revision: 244405
>
> URL: http://llvm.org/viewvc/llvm-project?rev=244405&view=rev
> Log:
> Fix dangling reference in DwarfLinker.cpp. The original code
>
>   Seq.emplace_back(Seq.back());
>
> does not work as planned, since Seq.back() may become a dangling reference
> when emplace_back is called and possibly reallocates vector. To avoid this,
> the vector allocation should be reserved first and only then used.
>
> This broke test/tools/dsymutil/X86/custom-line-table.test with Visual C++
> 2013.
>
>
> Modified:
>     llvm/trunk/tools/dsymutil/DwarfLinker.cpp
>
> Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=244405&r1=244404&r2=244405&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
> +++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Sat Aug  8 16:03:19 2015
> @@ -2884,6 +2884,7 @@ void DwarfLinker::patchLineTableForUnit(
>        if (StopAddress != -1ULL && !Seq.empty()) {
>          // Insert end sequence row with the computed end address, but
>          // the same line as the previous one.
> +        Seq.reserve(Seq.size() + 1);
>          Seq.emplace_back(Seq.back());
>

Might be less subtle to just write this as:

auto NextLine = Seq.back();
NextLine.Address = ...;
...
NextLine.EpilogueBegin = ...;
Seq.push_back(NextLine);

(alternatively: Seq.push_back(DWARFDebugLine::Row(Seq.back()); would also
avoid the need for the reserve, but would still be bit non-obvious/subtle,
like the reserve call is)


>          Seq.back().Address = StopAddress;
>          Seq.back().EndSequence = 1;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150810/64b419b8/attachment.html>


More information about the llvm-commits mailing list