[llvm-commits] [llvm] r173240 - in /llvm/trunk/unittests: Bitcode/BitReaderTest.cpp IR/ConstantsTest.cpp IR/DominatorTreeTest.cpp Option/OptionParsingTest.cpp

NAKAMURA Takumi geek4civic at gmail.com
Wed Jan 23 16:06:50 PST 2013


I think i would work. That said, I wonder if we could create
LLVMContext-senstivie objects onto stack.

Unittests can be considered also examples, I think.

...Takumi

2013/1/24 David Blaikie <dblaikie at gmail.com>:
> In the cases of read new, could these just be directly stack allocated
> rather than using new at all?
>
> On Jan 23, 2013 12:35 AM, "NAKAMURA Takumi" <geek4civic at gmail.com> wrote:
>>
>> Author: chapuni
>> Date: Wed Jan 23 02:33:13 2013
>> New Revision: 173240
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=173240&view=rev
>> Log:
>> llvm/unittests: Use OwningPtr to fix --vg-leak.
>>
>> Modified:
>>     llvm/trunk/unittests/Bitcode/BitReaderTest.cpp
>>     llvm/trunk/unittests/IR/ConstantsTest.cpp
>>     llvm/trunk/unittests/IR/DominatorTreeTest.cpp
>>     llvm/trunk/unittests/Option/OptionParsingTest.cpp
>>
>> Modified: llvm/trunk/unittests/Bitcode/BitReaderTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitReaderTest.cpp?rev=173240&r1=173239&r2=173240&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/unittests/Bitcode/BitReaderTest.cpp (original)
>> +++ llvm/trunk/unittests/Bitcode/BitReaderTest.cpp Wed Jan 23 02:33:13
>> 2013
>> @@ -45,9 +45,9 @@
>>  }
>>
>>  static void writeModuleToBuffer(SmallVectorImpl<char> &Buffer) {
>> -  Module *Mod = makeLLVMModule();
>> +  OwningPtr<Module> Mod(makeLLVMModule());
>>    raw_svector_ostream OS(Buffer);
>> -  WriteBitcodeToFile(Mod, OS);
>> +  WriteBitcodeToFile(Mod.get(), OS);
>>  }
>>
>>  TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
>> @@ -55,7 +55,7 @@
>>    writeModuleToBuffer(Mem);
>>    MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test",
>> false);
>>    std::string errMsg;
>> -  Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);
>> +  OwningPtr<Module> m(getLazyBitcodeModule(Buffer, getGlobalContext(),
>> &errMsg));
>>    PassManager passes;
>>    passes.add(createVerifierPass());
>>    passes.run(*m);
>>
>> Modified: llvm/trunk/unittests/IR/ConstantsTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=173240&r1=173239&r2=173240&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/unittests/IR/ConstantsTest.cpp (original)
>> +++ llvm/trunk/unittests/IR/ConstantsTest.cpp Wed Jan 23 02:33:13 2013
>> @@ -162,7 +162,7 @@
>>    }
>>
>>  TEST(ConstantsTest, AsInstructionsTest) {
>> -  Module *M = new Module("MyModule", getGlobalContext());
>> +  OwningPtr<Module> M(new Module("MyModule", getGlobalContext()));
>>
>>    Type *Int64Ty = Type::getInt64Ty(getGlobalContext());
>>    Type *Int32Ty = Type::getInt32Ty(getGlobalContext());
>>
>> Modified: llvm/trunk/unittests/IR/DominatorTreeTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/DominatorTreeTest.cpp?rev=173240&r1=173239&r2=173240&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/unittests/IR/DominatorTreeTest.cpp (original)
>> +++ llvm/trunk/unittests/IR/DominatorTreeTest.cpp Wed Jan 23 02:33:13 2013
>> @@ -191,7 +191,7 @@
>>
>>      TEST(DominatorTree, Unreachable) {
>>        DPass *P = new DPass();
>> -      Module *M = makeLLVMModule(P);
>> +      OwningPtr<Module> M(makeLLVMModule(P));
>>        PassManager Passes;
>>        Passes.add(P);
>>        Passes.run(*M);
>>
>> Modified: llvm/trunk/unittests/Option/OptionParsingTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=173240&r1=173239&r2=173240&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/unittests/Option/OptionParsingTest.cpp (original)
>> +++ llvm/trunk/unittests/Option/OptionParsingTest.cpp Wed Jan 23 02:33:13
>> 2013
>> @@ -7,6 +7,7 @@
>>  //
>>
>> //===----------------------------------------------------------------------===//
>>
>> +#include "llvm/ADT/OwningPtr.h"
>>  #include "llvm/Option/Arg.h"
>>  #include "llvm/Option/ArgList.h"
>>  #include "llvm/Option/Option.h"
>> @@ -60,7 +61,11 @@
>>  TEST(Support, OptionParsing) {
>>    TestOptTable T;
>>    unsigned MAI, MAC;
>> -  InputArgList *AL = T.ParseArgs(Args, Args + (sizeof(Args) /
>> sizeof(Args[0])), MAI, MAC);
>> +  OwningPtr<InputArgList>
>> +    AL(T.ParseArgs(Args,
>> +                   Args + (sizeof(Args) / sizeof(Args[0])),
>> +                   MAI,
>> +                   MAC));
>>
>>    // Check they all exist.
>>    EXPECT_TRUE(AL->hasArg(OPT_A));
>>
>>
>> _______________________________________________
>> 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