diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-02-25 22:23:04 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-02-25 22:23:04 +0000 |
| commit | 248ac139752aa61eab97ce6b80bb4160da4bd5fa (patch) | |
| tree | 4be9e42f9ec4c10ca79f375fefff618ffdd97877 /llvm/lib | |
| parent | afc9eb33fd9c0708ada37a285b635b4f492eaaca (diff) | |
| download | bcm5719-llvm-248ac139752aa61eab97ce6b80bb4160da4bd5fa.tar.gz bcm5719-llvm-248ac139752aa61eab97ce6b80bb4160da4bd5fa.zip | |
Fix resetting the DataLayout in a Module.
No tool does this currently, but as everything else in a module we should be
able to change its DataLayout.
Most of the fix is in DataLayout to make sure it can be reset properly.
The test uses Module::setDataLayout since the fact that we mutate a DataLayout
is an implementation detail. The module could hold a OwningPtr<DataLayout> and
the DataLayout itself could be immutable.
Thanks to Philip Reames for pushing me in the right direction.
llvm-svn: 202198
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 18 | ||||
| -rw-r--r-- | llvm/lib/IR/Module.cpp | 6 |
2 files changed, 19 insertions, 5 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index d60c79f52e8..ccdaec5e554 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -176,7 +176,9 @@ static const LayoutAlignElem DefaultAlignments[] = { { AGGREGATE_ALIGN, 0, 0, 8 } // struct }; -void DataLayout::init(StringRef Desc) { +void DataLayout::reset(StringRef Desc) { + clear(); + LayoutMap = 0; LittleEndian = false; StackNaturalAlign = 0; @@ -344,12 +346,12 @@ void DataLayout::parseSpecifier(StringRef Desc) { } } -DataLayout::DataLayout(const Module *M) { +DataLayout::DataLayout(const Module *M) : LayoutMap(0) { const DataLayout *Other = M->getDataLayout(); if (Other) *this = *Other; else - init(""); + reset(""); } void @@ -469,8 +471,16 @@ public: } // end anonymous namespace +void DataLayout::clear() { + LegalIntWidths.clear(); + Alignments.clear(); + Pointers.clear(); + delete static_cast<StructLayoutMap *>(LayoutMap); + LayoutMap = 0; +} + DataLayout::~DataLayout() { - delete static_cast<StructLayoutMap*>(LayoutMap); + clear(); } const StructLayout *DataLayout::getStructLayout(StructType *Ty) const { diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 739f8888f96..4204c8ef5fc 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -339,17 +339,21 @@ void Module::addModuleFlag(MDNode *Node) { } void Module::setDataLayout(StringRef Desc) { + DL.reset(Desc); + if (Desc.empty()) { DataLayoutStr = ""; } else { - DL.init(Desc); DataLayoutStr = DL.getStringRepresentation(); + // DataLayoutStr is now equivalent to Desc, but since the representation + // is not unique, they may not be identical. } } void Module::setDataLayout(const DataLayout *Other) { if (!Other) { DataLayoutStr = ""; + DL.reset(""); } else { DL = *Other; DataLayoutStr = DL.getStringRepresentation(); |

