]> granicus.if.org Git - clang/commitdiff
Allow user re-definition of SEL as well as accessing its fields.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 25 Nov 2009 23:07:42 +0000 (23:07 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 25 Nov 2009 23:07:42 +0000 (23:07 +0000)
This fixes pr5611.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89895 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp
test/CodeGenObjC/sel-as-builtin-type.m

index e265245782937beb112d79eea7b100cd03a93edb..4f29e5d8a6182c32d0c51a32e6927614750853fa 100644 (file)
@@ -243,7 +243,7 @@ public:
   // pseudo-builtins
   QualType ObjCIdRedefinitionType;
   QualType ObjCClassRedefinitionType;
-  QualType ObjCSELRedefinitionType;
+  QualType ObjCSelRedefinitionType;
 
   /// \brief Source ranges for all of the comments in the source file,
   /// sorted in order of appearance in the translation unit.
index 639e8f8b9eb89fcaceef7dafcb547d33716b81ad..2579a6e8795f98c66cf48b55d9d2b586bf3b0b99 100644 (file)
@@ -48,7 +48,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
   BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts) {
   ObjCIdRedefinitionType = QualType();
   ObjCClassRedefinitionType = QualType();
-  ObjCSELRedefinitionType = QualType();
+  ObjCSelRedefinitionType = QualType();
   if (size_reserve > 0) Types.reserve(size_reserve);
   TUDecl = TranslationUnitDecl::Create(*this);
   InitBuiltinTypes();
index 9c771e0473f9a4de11465bf76c501c81e47c8226..dc102bb6e0c7facc9e6889db980d07e8a6f46085 100644 (file)
@@ -1558,7 +1558,7 @@ void PCHReader::InitializeContext(ASTContext &Ctx) {
   // FIXME. Accommodate for this in several PCH/Index tests
   if (unsigned ObjCSelRedef
       = SpecialTypes[pch::SPECIAL_TYPE_OBJC_SEL_REDEFINITION])
-    Context->ObjCSELRedefinitionType = GetType(ObjCSelRedef);
+    Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef);
 #endif
   if (unsigned String = SpecialTypes[pch::SPECIAL_TYPE_BLOCK_DESCRIPTOR])
     Context->setBlockDescriptorType(GetType(String));
index 06727c4a50d25b1106e1a814e2d50f6a48b8ecb4..4e45d87fbea76ddc23944b0f58f24d233c6c3876 100644 (file)
@@ -1997,7 +1997,7 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   AddTypeRef(Context.ObjCClassRedefinitionType, Record);
 #if 0
   // FIXME. Accommodate for this in several PCH/Indexer tests
-  AddTypeRef(Context.ObjCSELRedefinitionType, Record);
+  AddTypeRef(Context.ObjCSelRedefinitionType, Record);
 #endif
   AddTypeRef(Context.getRawBlockdescriptorType(), Record);
   AddTypeRef(Context.getRawBlockdescriptorExtendedType(), Record);
index 11729e0dacf42f9f3d288b94eafccc29a6737da8..838fb6cbb00ce13fd7e5d6829afaa3a03e00e749 100644 (file)
@@ -307,7 +307,7 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
                             &Context.Idents.get("SEL"), SelInfo);
     PushOnScopeChains(SelTypedef, TUScope);
     Context.setObjCSelType(Context.getTypeDeclType(SelTypedef));
-    Context.ObjCSELRedefinitionType = Context.getObjCSelType();
+    Context.ObjCSelRedefinitionType = Context.getObjCSelType();
   }
 
   // Synthesize "@class Protocol;
index c0a409d043a0c9b6edb716f7eae7a950cd945093..31c6ab543dd6f74efb1e447c728f0e94bf85c0e3 100644 (file)
@@ -681,7 +681,7 @@ void Sema::MergeTypeDefDecl(TypedefDecl *New, LookupResult &OldDecls) {
     case 3:
       if (!TypeID->isStr("SEL"))
         break;
-      Context.ObjCSELRedefinitionType = New->getUnderlyingType();
+      Context.ObjCSelRedefinitionType = New->getUnderlyingType();
       // Install the built-in type for 'SEL', ignoring the current definition.
       New->setTypeForDecl(Context.getObjCSelType().getTypePtr());
       return;
index c37b7707b21c4c9519c3f41e02287e074b0bf7b3..5479ce65fa8a19ebadb10009512c0f85d33ff21d 100644 (file)
@@ -1937,6 +1937,16 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
       ImpCastExprToType(BaseExpr, BaseType, CastExpr::CK_BitCast);
     }
   }
+  // If this is an Objective-C pseudo-builtin and a definition is provided then
+  // use that.
+  if (Context.isObjCSelType(BaseType)) {
+    // We have an 'SEL' type. Rather than fall through, we check if this
+    // is a reference to 'sel_id'.
+    if (BaseType != Context.ObjCSelRedefinitionType) {
+      BaseType = Context.ObjCSelRedefinitionType;
+      ImpCastExprToType(BaseExpr, BaseType, CastExpr::CK_BitCast);
+    }
+  }
   assert(!BaseType.isNull() && "no type for member expression");
 
   // Handle properties on ObjC 'Class' types.
@@ -3440,6 +3450,17 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
     ImpCastExprToType(LHS, RHSTy, CastExpr::CK_BitCast);
     return RHSTy;
   }
+  // And the same for struct objc_selector* / SEL
+  if (Context.isObjCSelType(LHSTy) &&
+      (RHSTy.getDesugaredType() == Context.ObjCSelRedefinitionType)) {
+    ImpCastExprToType(RHS, LHSTy, CastExpr::CK_BitCast);
+    return LHSTy;
+  }
+  if (Context.isObjCSelType(RHSTy) &&
+      (LHSTy.getDesugaredType() == Context.ObjCSelRedefinitionType)) {
+    ImpCastExprToType(LHS, RHSTy, CastExpr::CK_BitCast);
+    return RHSTy;
+  }
   // Handle block pointer types.
   if (LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) {
     if (!LHSTy->isBlockPointerType() || !RHSTy->isBlockPointerType()) {
index cb129a139f39ce8b7dcd3ff90a0c00d085356eca..c65a5b280542d2839fdc14d81ced3f4daee605bc 100644 (file)
@@ -17,3 +17,7 @@ typedef const struct objc_selector {
 }
 @end
 
+int func(SEL s1, SEL s2)
+{
+        return s1->sel_id == s2->sel_id;
+}