Index: lib/CodeGen/CGObjCGNU.cpp
===================================================================
--- lib/CodeGen/CGObjCGNU.cpp	(revision 62711)
+++ lib/CodeGen/CGObjCGNU.cpp	(working copy)
@@ -26,6 +26,8 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Target/TargetData.h"
 #include <map>
+
+
 using namespace clang;
 using namespace CodeGen;
 using llvm::dyn_cast;
@@ -40,7 +42,6 @@
 private:
   CodeGen::CodeGenModule &CGM;
   llvm::Module &TheModule;
-  const llvm::StructType *SelStructTy;
   const llvm::Type *SelectorTy;
   const llvm::Type *PtrToInt8Ty;
   const llvm::Type *IMPTy;
@@ -168,11 +169,9 @@
   PtrToInt8Ty = 
     llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
   // Get the selector Type.
-  SelStructTy = llvm::StructType::get(
-      PtrToInt8Ty,
-      PtrToInt8Ty,
-      NULL);
-  SelectorTy = llvm::PointerType::getUnqual(SelStructTy);
+  SelectorTy = 
+    CGM.getTypes().ConvertType(CGM.getContext().getObjCSelType());
+
   PtrToIntTy = llvm::PointerType::getUnqual(IntTy);
   PtrTy = PtrToInt8Ty;
  
@@ -194,7 +193,7 @@
 // techniques can modify the name -> class mapping.
 llvm::Value *CGObjCGNU::GetClass(CGBuilderTy &Builder,
                                  const ObjCInterfaceDecl *OID) {
-  llvm::Value *ClassName = CGM.GetAddrOfConstantCString(OID->getNameAsString());
+  llvm::Value *ClassName = CGM.GetAddrOfConstantCString(OID->getNameAsString(), "class_name");
   ClassName = Builder.CreateStructGEP(ClassName, 0);
 
   llvm::Constant *ClassLookupFn =
@@ -797,8 +796,18 @@
       UntypedSelectors.empty())
     return NULL;
 
+  const llvm::StructType *SelStructTy = dyn_cast<llvm::StructType>(
+		  cast<llvm::PointerType>(SelectorTy)->getTypeAtIndex((unsigned)0));
+  const llvm::Type *SelStructPtrTy = SelectorTy;
+  bool isSelOpaque = false;
+  if (0 == SelStructTy) {
+    SelStructTy = llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, NULL);
+	SelStructPtrTy = llvm::PointerType::getUnqual(SelStructTy);
+	isSelOpaque = true;
+  }
+
   // Name the ObjC types to make the IR a bit easier to read
-  TheModule.addTypeName(".objc_selector", SelectorTy);
+  TheModule.addTypeName(".objc_selector", SelStructPtrTy);
   TheModule.addTypeName(".objc_id", IdTy);
   TheModule.addTypeName(".objc_imp", IMPTy);
 
@@ -825,7 +834,7 @@
   // Array of classes, categories, and constant objects
   llvm::ArrayType *ClassListTy = llvm::ArrayType::get(PtrToInt8Ty,
       Classes.size() + Categories.size()  + 2);
-  llvm::StructType *SymTabTy = llvm::StructType::get(LongTy, SelectorTy,
+  llvm::StructType *SymTabTy = llvm::StructType::get(LongTy, SelStructPtrTy,
                                                      llvm::Type::Int16Ty,
                                                      llvm::Type::Int16Ty,
                                                      ClassListTy, NULL);
@@ -860,7 +869,8 @@
   llvm::Constant *SelectorList = MakeGlobal(
           llvm::ArrayType::get(SelStructTy, Selectors.size()), Selectors,
           ".objc_selector_list");
-  Elements.push_back(llvm::ConstantExpr::getBitCast(SelectorList, SelectorTy));
+  Elements.push_back(llvm::ConstantExpr::getBitCast(SelectorList, 
+    SelStructPtrTy));
 
   // Now that all of the static selectors exist, create pointers to them.
   int index = 0;
@@ -869,10 +879,16 @@
      iter != iterEnd; ++iter) {
     llvm::Constant *Idxs[] = {Zeros[0],
       llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]};
-    llvm::GlobalVariable *SelPtr = new llvm::GlobalVariable(SelectorTy, true,
-        llvm::GlobalValue::InternalLinkage,
+    llvm::Constant *SelPtr = new llvm::GlobalVariable(SelStructPtrTy,
+        true, llvm::GlobalValue::InternalLinkage,
         llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
         ".objc_sel_ptr", &TheModule);
+    // If selectors are defined as an opaque type, cast the pointer to this
+    // type.
+    if (isSelOpaque) {
+      SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
+        llvm::PointerType::getUnqual(SelectorTy));
+    }
     (*iter).second->setAliasee(SelPtr);
   }
   for (llvm::StringMap<llvm::GlobalAlias*>::iterator
@@ -880,10 +896,16 @@
       iter != iterEnd; iter++) {
     llvm::Constant *Idxs[] = {Zeros[0],
       llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]};
-    llvm::GlobalVariable *SelPtr = new llvm::GlobalVariable(SelectorTy, true,
+    llvm::Constant *SelPtr = new llvm::GlobalVariable(SelStructPtrTy, true,
         llvm::GlobalValue::InternalLinkage,
         llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
         ".objc_sel_ptr", &TheModule);
+    // If selectors are defined as an opaque type, cast the pointer to this
+    // type.
+    if (isSelOpaque) {
+      SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
+        llvm::PointerType::getUnqual(SelectorTy));
+    }
     (*iter).second->setAliasee(SelPtr);
   }
   // Number of classes defined.
