[LLVMbugs] [Bug 6659] New: ConstantUniqueMap::freeConstants may not free all constants

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Mar 20 00:44:24 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=6659

           Summary: ConstantUniqueMap::freeConstants may not free all
                    constants
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Core LLVM classes
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: llvmbugs at cs.uiuc.edu


We have:

  void ConstantUniqueMap::freeConstants() {
    for (typename MapTy::iterator I=Map.begin(), E=Map.end();
         I != E; ++I) {
      if (I->second->use_empty())
        delete I->second;
    }
  }

Because this only deletes constants that aren't used anymore, its efficacy
depends on the order of the Map, which is unlikely to be exactly correct except
in tiny test cases where malloc's feeling cooperative. The obvious fix of
changing the "if() delete" to I->second->destroyConstant() doesn't work because
it can (but doesn't always) modify the very map we're iterating over. A
workset-based approach might work, where we insert all the possibly-cyclic
Constants into a single workset, pop one if it's used, or add its uses to the
workset and delete it if it's use-free. O(edges) rather than O(objects), but
that's still O(program-size).


This causes leaks like the one in CodeGen/X86/rodata-relocs.ll, where some
ConstantInts are kept alive because they're still used by some ConstantArrays
that should have been destroyed in freeConstants:

==27522== 248 (72 direct, 176 indirect) bytes in 1 blocks are definitely lost
in loss record 138 of 140
==27522==    at 0x4C229C7: operator new(unsigned long)
(vg_replace_malloc.c:220)
==27522==    by 0x11F0547: llvm::User::operator new(unsigned long, unsigned
int) (Use.cpp:171)
==27522==    by 0x1141F50: llvm::ConstantInt::operator new(unsigned long)
(Constants.h:57)
==27522==    by 0x11392E5: llvm::ConstantInt::get(llvm::LLVMContext&,
llvm::APInt const&) (Constants.cpp:296)
==27522==    by 0x996A20: llvm::LLParser::ConvertValIDToValue(llvm::Type
const*, llvm::ValID&, llvm::Value*&, llvm::LLParser::PerFunctionState*)
(LLParser.cpp:2515)
==27522==    by 0x995F53: llvm::LLParser::ParseGlobalValue(llvm::Type const*,
llvm::Constant*&) (LLParser.cpp:2431)
==27522==    by 0x9960A7:
llvm::LLParser::ParseGlobalTypeAndValue(llvm::Constant*&) (LLParser.cpp:2440)
==27522==    by 0x99615D:
llvm::LLParser::ParseGlobalValueVector(llvm::SmallVectorImpl<llvm::Constant*>&)
(LLParser.cpp:2455)
==27522==    by 0x993590: llvm::LLParser::ParseValID(llvm::ValID&,
llvm::LLParser::PerFunctionState*) (LLParser.cpp:2080)
==27522==    by 0x995F25: llvm::LLParser::ParseGlobalValue(llvm::Type const*,
llvm::Constant*&) (LLParser.cpp:2431)
==27522==    by 0x98BB51: llvm::LLParser::ParseGlobal(std::string const&,
llvm::SMLoc, unsigned int, bool, unsigned int) (LLParser.cpp:684)
==27522==    by 0x98A87C: llvm::LLParser::ParseNamedGlobal() (LLParser.cpp:460)
==27522== 
==27522== 248 (72 direct, 176 indirect) bytes in 1 blocks are definitely lost
in loss record 139 of 140
==27522==    at 0x4C229C7: operator new(unsigned long)
(vg_replace_malloc.c:220)
==27522==    by 0x11F0547: llvm::User::operator new(unsigned long, unsigned
int) (Use.cpp:171)
==27522==    by 0x1141F50: llvm::ConstantInt::operator new(unsigned long)
(Constants.h:57)
==27522==    by 0x11392E5: llvm::ConstantInt::get(llvm::LLVMContext&,
llvm::APInt const&) (Constants.cpp:296)
==27522==    by 0x996A20: llvm::LLParser::ConvertValIDToValue(llvm::Type
const*, llvm::ValID&, llvm::Value*&, llvm::LLParser::PerFunctionState*)
(LLParser.cpp:2515)
==27522==    by 0x995F53: llvm::LLParser::ParseGlobalValue(llvm::Type const*,
llvm::Constant*&) (LLParser.cpp:2431)
==27522==    by 0x9960A7:
llvm::LLParser::ParseGlobalTypeAndValue(llvm::Constant*&) (LLParser.cpp:2440)
==27522==    by 0x99615D:
llvm::LLParser::ParseGlobalValueVector(llvm::SmallVectorImpl<llvm::Constant*>&)
(LLParser.cpp:2455)
==27522==    by 0x993590: llvm::LLParser::ParseValID(llvm::ValID&,
llvm::LLParser::PerFunctionState*) (LLParser.cpp:2080)
==27522==    by 0x995F25: llvm::LLParser::ParseGlobalValue(llvm::Type const*,
llvm::Constant*&) (LLParser.cpp:2431)
==27522==    by 0x9960A7:
llvm::LLParser::ParseGlobalTypeAndValue(llvm::Constant*&) (LLParser.cpp:2440)
==27522==    by 0x996190:
llvm::LLParser::ParseGlobalValueVector(llvm::SmallVectorImpl<llvm::Constant*>&)
(LLParser.cpp:2459)
==27522== 


This may be related to or the same bug as PR2975.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list