[llvm] r270791 - Objective-C Class Properties: Autoupgrade "Class Properties" module flag.

Manman Ren via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 16:14:48 PDT 2016


Author: mren
Date: Wed May 25 18:14:48 2016
New Revision: 270791

URL: http://llvm.org/viewvc/llvm-project?rev=270791&view=rev
Log:
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

Added:
    llvm/trunk/test/Bitcode/upgrade-module-flag.ll
Modified:
    llvm/trunk/include/llvm/IR/AutoUpgrade.h
    llvm/trunk/lib/AsmParser/LLParser.cpp
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/IR/AutoUpgrade.cpp

Modified: llvm/trunk/include/llvm/IR/AutoUpgrade.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/AutoUpgrade.h?rev=270791&r1=270790&r2=270791&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/AutoUpgrade.h (original)
+++ llvm/trunk/include/llvm/IR/AutoUpgrade.h Wed May 25 18:14:48 2016
@@ -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);

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=270791&r1=270790&r2=270791&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed May 25 18:14:48 2016
@@ -212,6 +212,8 @@ bool LLParser::ValidateEndOfModule() {
 
   UpgradeDebugInfo(*M);
 
+  UpgradeModuleFlags(*M);
+
   if (!Slots)
     return false;
   // Initialize the slot mapping.

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=270791&r1=270790&r2=270791&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed May 25 18:14:48 2016
@@ -5634,6 +5634,8 @@ std::error_code BitcodeReader::materiali
   UpgradedIntrinsics.clear();
 
   UpgradeDebugInfo(*TheModule);
+
+  UpgradeModuleFlags(*TheModule);
   return std::error_code();
 }
 

Modified: llvm/trunk/lib/IR/AutoUpgrade.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AutoUpgrade.cpp?rev=270791&r1=270790&r2=270791&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AutoUpgrade.cpp (original)
+++ llvm/trunk/lib/IR/AutoUpgrade.cpp Wed May 25 18:14:48 2016
@@ -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)

Added: llvm/trunk/test/Bitcode/upgrade-module-flag.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/upgrade-module-flag.ll?rev=270791&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/upgrade-module-flag.ll (added)
+++ llvm/trunk/test/Bitcode/upgrade-module-flag.ll Wed May 25 18:14:48 2016
@@ -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}




More information about the llvm-commits mailing list