From f625c14487e59aaa7d6c7e548be654de949ecec8 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sat, 28 Sep 2013 01:08:00 +0000 Subject: Fix typo git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191595 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IR/Module.cpp') diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 968b8f4..ba4ee7f6 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -245,7 +245,7 @@ GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) { /// 1. If it does not exist, add a declaration of the global and return it. /// 2. Else, the global exists but has the wrong type: return the function /// with a constantexpr cast to the right type. -/// 3. Finally, if the existing global is the correct delclaration, return the +/// 3. Finally, if the existing global is the correct declaration, return the /// existing global. Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) { // See if we have a definition for the specified global already. -- cgit v1.1 From 2ebcd57e6adf2dc951eb7ad5f42952961f1a60c9 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 30 Sep 2013 21:23:03 +0000 Subject: Fix getOrInsertGlobal dropping the address space. Currently it will insert an illegal bitcast. Arguably, the address space argument should be added for the creation case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191702 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Module.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/IR/Module.cpp') diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index ba4ee7f6..f200da8 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -260,8 +260,10 @@ Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) { // If the variable exists but has the wrong type, return a bitcast to the // right type. - if (GV->getType() != PointerType::getUnqual(Ty)) - return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty)); + Type *GVTy = GV->getType(); + PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace()); + if (GV->getType() != PTy) + return ConstantExpr::getBitCast(GV, PTy); // Otherwise, we just found the existing function or a prototype. return GV; -- cgit v1.1 From b1d70af7b93c1e9161a4e7ca51659a1123c96177 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 30 Sep 2013 23:31:50 +0000 Subject: Reuse variable git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191712 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IR/Module.cpp') diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index f200da8..58115ef 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -262,7 +262,7 @@ Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) { // right type. Type *GVTy = GV->getType(); PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace()); - if (GV->getType() != PTy) + if (GVTy != PTy) return ConstantExpr::getBitCast(GV, PTy); // Otherwise, we just found the existing function or a prototype. -- cgit v1.1 From af9e8e60ae5118066e49730ae5a96aadf3a8f624 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 5 Nov 2013 19:36:34 +0000 Subject: Use error_code in GVMaterializer. They just propagate out the bitcode reader error, so we don't need a new enum. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194091 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Module.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/IR/Module.cpp') diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 58115ef..3dd1f7e 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -401,9 +401,15 @@ bool Module::isDematerializable(const GlobalValue *GV) const { } bool Module::Materialize(GlobalValue *GV, std::string *ErrInfo) { - if (Materializer) - return Materializer->Materialize(GV, ErrInfo); - return false; + if (!Materializer) + return false; + + error_code EC = Materializer->Materialize(GV); + if (!EC) + return false; + if (ErrInfo) + *ErrInfo = EC.message(); + return true; } void Module::Dematerialize(GlobalValue *GV) { @@ -414,7 +420,12 @@ void Module::Dematerialize(GlobalValue *GV) { bool Module::MaterializeAll(std::string *ErrInfo) { if (!Materializer) return false; - return Materializer->MaterializeModule(this, ErrInfo); + error_code EC = Materializer->MaterializeModule(this); + if (!EC) + return false; + if (ErrInfo) + *ErrInfo = EC.message(); + return true; } bool Module::MaterializeAllPermanently(std::string *ErrInfo) { -- cgit v1.1 From 27457ac42f7a9267ab7e0190424a95fecf0ea201 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Mon, 9 Dec 2013 21:06:30 +0000 Subject: Merging r196158: ------------------------------------------------------------------------ r196158 | mren | 2013-12-02 13:29:56 -0800 (Mon, 02 Dec 2013) | 12 lines Debug Info: drop debug info via upgrading path if version number does not match. Add a helper function getDebugInfoVersionFromModule to return the debug info version number for a module. "Verifier/module-flags-1.ll" checks for verification errors. It will seg fault when calling getDebugInfoVersionFromModule because of the incorrect format for module flags in the testing case. We make getModuleFlagsMetadata more robust by checking for error conditions. PR17982 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@196822 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Module.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/IR/Module.cpp') diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 3dd1f7e..4f240c7 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -318,11 +318,16 @@ getModuleFlagsMetadata(SmallVectorImpl &Flags) const { for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) { MDNode *Flag = ModFlags->getOperand(i); - ConstantInt *Behavior = cast(Flag->getOperand(0)); - MDString *Key = cast(Flag->getOperand(1)); - Value *Val = Flag->getOperand(2); - Flags.push_back(ModuleFlagEntry(ModFlagBehavior(Behavior->getZExtValue()), - Key, Val)); + if (Flag->getNumOperands() >= 3 && isa(Flag->getOperand(0)) && + isa(Flag->getOperand(1))) { + // Check the operands of the MDNode before accessing the operands. + // The verifier will actually catch these failures. + ConstantInt *Behavior = cast(Flag->getOperand(0)); + MDString *Key = cast(Flag->getOperand(1)); + Value *Val = Flag->getOperand(2); + Flags.push_back(ModuleFlagEntry(ModFlagBehavior(Behavior->getZExtValue()), + Key, Val)); + } } } -- cgit v1.1