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

Frédéric Riss via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 9 08:53:27 PDT 2015


Thanks for tracking this down!

> On 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());
>         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



More information about the llvm-commits mailing list