From 248ac139752aa61eab97ce6b80bb4160da4bd5fa Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Feb 2014 22:23:04 +0000 Subject: 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 and the DataLayout itself could be immutable. Thanks to Philip Reames for pushing me in the right direction. llvm-svn: 202198 --- llvm/lib/IR/Module.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'llvm/lib/IR/Module.cpp') diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 739f888..4204c8e 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(); -- cgit v1.1