diff options
| author | Manman Ren <manman.ren@gmail.com> | 2016-05-25 23:14:48 +0000 |
|---|---|---|
| committer | Manman Ren <manman.ren@gmail.com> | 2016-05-25 23:14:48 +0000 |
| commit | b5d7ff4fa363363aff9f27a216bd72b008089422 (patch) | |
| tree | 80fef0ad209c5aceffba42316e6d06b91a2c9643 | |
| parent | fea8a8d70a851e8b3f45d65c07d11452a47d1357 (diff) | |
| download | bcm5719-llvm-b5d7ff4fa363363aff9f27a216bd72b008089422.tar.gz bcm5719-llvm-b5d7ff4fa363363aff9f27a216bd72b008089422.zip | |
Objective-C Class Properties: Autoupgrade "Class Properties" module flag.
When we have "Image Info Version" module flag but don't have "Class Properties"
module flag, set "Class Properties" module flag to 0, so we can correctly emit
errors when one module has the flag set and another module does not.
rdar://26469641
llvm-svn: 270791
| -rw-r--r-- | llvm/include/llvm/IR/AutoUpgrade.h | 4 | ||||
| -rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 31 | ||||
| -rw-r--r-- | llvm/test/Bitcode/upgrade-module-flag.ll | 9 |
5 files changed, 48 insertions, 0 deletions
diff --git a/llvm/include/llvm/IR/AutoUpgrade.h b/llvm/include/llvm/IR/AutoUpgrade.h index 24665c4e367..9eb358682c6 100644 --- a/llvm/include/llvm/IR/AutoUpgrade.h +++ b/llvm/include/llvm/IR/AutoUpgrade.h @@ -47,6 +47,10 @@ namespace llvm { /// if it requires upgrading. bool UpgradeGlobalVariable(GlobalVariable *GV); + /// This checks for module flags which should be upgraded. It returns true if + /// module is modified. + bool UpgradeModuleFlags(Module &M); + /// If the TBAA tag for the given instruction uses the scalar TBAA format, /// we upgrade it to the struct-path aware TBAA format. void UpgradeInstWithTBAATag(Instruction *I); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 56667bdead4..d1f9d4701a3 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -212,6 +212,8 @@ bool LLParser::ValidateEndOfModule() { UpgradeDebugInfo(*M); + UpgradeModuleFlags(*M); + if (!Slots) return false; // Initialize the slot mapping. diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 9796a10edb4..bd902ba386b 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5634,6 +5634,8 @@ std::error_code BitcodeReader::materializeModule() { UpgradedIntrinsics.clear(); UpgradeDebugInfo(*TheModule); + + UpgradeModuleFlags(*TheModule); return std::error_code(); } diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index aff89775a5a..d05bb47a68c 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -958,6 +958,37 @@ bool llvm::UpgradeDebugInfo(Module &M) { return RetCode; } +bool llvm::UpgradeModuleFlags(Module &M) { + const NamedMDNode *ModFlags = M.getModuleFlagsMetadata(); + if (!ModFlags) + return false; + + bool HasObjCFlag = false, HasClassProperties = false; + for (unsigned I = 0, E = ModFlags->getNumOperands(); I != E; ++I) { + MDNode *Op = ModFlags->getOperand(I); + if (Op->getNumOperands() < 2) + continue; + MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1)); + if (!ID) + continue; + if (ID->getString() == "Objective-C Image Info Version") + HasObjCFlag = true; + if (ID->getString() == "Objective-C Class Properties") + HasClassProperties = true; + } + // "Objective-C Class Properties" is recently added for Objective-C. We + // upgrade ObjC bitcodes to contain a "Objective-C Class Properties" module + // flag of value 0, so we can correclty report error when trying to link + // an ObjC bitcode without this module flag with an ObjC bitcode with this + // module flag. + if (HasObjCFlag && !HasClassProperties) { + M.addModuleFlag(llvm::Module::Error, "Objective-C Class Properties", + (uint32_t)0); + return true; + } + return false; +} + static bool isOldLoopArgument(Metadata *MD) { auto *T = dyn_cast_or_null<MDTuple>(MD); if (!T) diff --git a/llvm/test/Bitcode/upgrade-module-flag.ll b/llvm/test/Bitcode/upgrade-module-flag.ll new file mode 100644 index 00000000000..fe52a3298e4 --- /dev/null +++ b/llvm/test/Bitcode/upgrade-module-flag.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s +; RUN: verify-uselistorder < %s + +!llvm.module.flags = !{!0} + +!0 = !{i32 1, !"Objective-C Image Info Version", i32 0} + +; CHECK: !0 = !{i32 1, !"Objective-C Image Info Version", i32 0} +; CHECK: !1 = !{i32 1, !"Objective-C Class Properties", i32 0} |

