[llvm] r187302 - Fix yet another memory leak found by the vg-leak bot. Folks (including

Benjamin Kramer benny.kra at gmail.com
Sun Aug 4 02:12:28 PDT 2013


On 27.07.2013, at 13:23, Chandler Carruth <chandlerc at gmail.com> wrote:

> Author: chandlerc
> Date: Sat Jul 27 06:23:08 2013
> New Revision: 187302
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=187302&view=rev
> Log:
> Fix yet another memory leak found by the vg-leak bot. Folks (including
> me) should start watching this bot more as its catching lots of bugs.
> 
> The fix here is to not construct the global if we aren't going to need
> it. That's cheaper anyways, and globals have highly predictable types in
> practice. I've added an assert to catch skew between our manual testing
> of the type and the actual type just for paranoia's sake.
> 
> Note that this pattern is actually fine in most globals because when you
> build a global with a module it automatically is moved to be owned by
> that module. But here, we're in isel and don't really want to do that.
> The solution of not creating a global is simpler anyways.

The code for creating the global is still there, and when it creates one it's not owned by anyone and gets leaked. valgrind leaks bot still complains.

- Ben
> 
> Modified:
>    llvm/trunk/lib/Target/ARM/ARMFastISel.cpp
> 
> Modified: llvm/trunk/lib/Target/ARM/ARMFastISel.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMFastISel.cpp?rev=187302&r1=187301&r2=187302&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMFastISel.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMFastISel.cpp Sat Jul 27 06:23:08 2013
> @@ -2185,10 +2185,14 @@ unsigned ARMFastISel::ARMSelectCallOp(bo
> }
> 
> unsigned ARMFastISel::getLibcallReg(const Twine &Name) {
> +  // Manually compute the global's type to avoid building it when unnecessary.
> +  Type *GVTy = Type::getInt32PtrTy(*Context, /*AS=*/0);
> +  EVT LCREVT = TLI.getValueType(GVTy);
> +  if (!LCREVT.isSimple()) return 0;
> +
>   GlobalValue *GV = new GlobalVariable(Type::getInt32Ty(*Context), false,
>                                        GlobalValue::ExternalLinkage, 0, Name);
> -  EVT LCREVT = TLI.getValueType(GV->getType());
> -  if (!LCREVT.isSimple()) return 0;
> +  assert(GV->getType() == GVTy && "We miscomputed the type for the global!");
>   return ARMMaterializeGV(GV, LCREVT.getSimpleVT());
> }
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list