[llvm-commits] [llvm] r98537 - in /llvm/trunk: include/llvm/MC/MCSection.h include/llvm/MC/MCSectionELF.h lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Chris Lattner
sabre at nondot.org
Sun Mar 14 23:23:53 PDT 2010
Author: lattner
Date: Mon Mar 15 01:23:52 2010
New Revision: 98537
URL: http://llvm.org/viewvc/llvm-project?rev=98537&view=rev
Log:
fix MCSectionELF to not leak memory, just like I did for MCSymbol.
MCSectionMachO is already fine (yay for fixed size arrays?),
MCSectionCOFF still leaks.
Modified:
llvm/trunk/include/llvm/MC/MCSection.h
llvm/trunk/include/llvm/MC/MCSectionELF.h
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=98537&r1=98536&r2=98537&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Mon Mar 15 01:23:52 2010
@@ -42,6 +42,8 @@
};
class MCSectionCOFF : public MCSection {
+ // FIXME: This memory is leaked because MCSectionCOFF is bump pointer
+ // allocated and this never gets freed.
std::string Name;
/// IsDirective - This is true if the section name is a directive, not
Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=98537&r1=98536&r2=98537&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Mon Mar 15 01:23:52 2010
@@ -21,7 +21,9 @@
/// MCSectionELF - This represents a section on linux, lots of unix variants
/// and some bare metal systems.
class MCSectionELF : public MCSection {
- std::string SectionName;
+ /// SectionName - This is the name of the section. The referenced memory is
+ /// owned by TargetLoweringObjectFileELF's ELFUniqueMap.
+ StringRef SectionName;
/// Type - This is the sh_type field of a section, drawn from the enums below.
unsigned Type;
@@ -163,10 +165,7 @@
TARGET_INDEP_SHF = FIRST_TARGET_DEP_FLAG-1U
};
- StringRef getSectionName() const {
- return StringRef(SectionName);
- }
-
+ StringRef getSectionName() const { return SectionName; }
unsigned getType() const { return Type; }
unsigned getFlags() const { return Flags; }
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=98537&r1=98536&r2=98537&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Mon Mar 15 01:23:52 2010
@@ -53,11 +53,13 @@
ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
// Do the lookup, if we have a hit, return it.
- const MCSectionELF *&Entry = Map[Section];
- if (Entry) return Entry;
+ StringMapEntry<const MCSectionELF*> &Entry = Map.GetOrCreateValue(Section);
+ if (Entry.getValue()) return Entry.getValue();
- return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, IsExplicit,
- getContext());
+ MCSectionELF *Result = MCSectionELF::Create(Entry.getKey(), Type, Flags, Kind,
+ IsExplicit, getContext());
+ Entry.setValue(Result);
+ return Result;
}
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
More information about the llvm-commits
mailing list