objective-C blocks: under cc1 flag -encode-extended-block-signature,
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 14 Nov 2012 23:11:38 +0000 (23:11 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 14 Nov 2012 23:11:38 +0000 (23:11 +0000)
generate expanded signature encoding to include types as we
already do this for protocol method lists.
// rdar://12109031

llvm-svn: 167997

clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/AST/ASTContext.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGenObjC/extended-block-signature-encode.m [new file with mode: 0644]

index 7e255c2..e72a368 100644 (file)
@@ -104,6 +104,7 @@ LANGOPT(FastMath          , 1, 0, "__FAST_MATH__ predefined macro")
 LANGOPT(FiniteMathOnly    , 1, 0, "__FINITE_MATH_ONLY__ predefined macro")
 
 BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for __weak/__strong ivars")
+BENIGN_LANGOPT(ObjCExtendedBlockEncode , 1, 0, "Do extended encoding of block type signature")
 
 BENIGN_LANGOPT(AccessControl     , 1, 1, "C++ access control")
 LANGOPT(CharIsSigned      , 1, 1, "signed char")
index 77ba17a..7d437a6 100644 (file)
@@ -929,6 +929,8 @@ def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
   HelpText<"Print the full library path of <file>">, MetaVarName<"<file>">;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">, Flags<[CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">;
+def encode_extended_block_sig : Flag<["-"], "encode-extended-block-signature">, Flags<[CC1Option]>,
+  HelpText<"Enable encoding of the extended block type signature">;
 def print_libgcc_file_name : Flag<["-", "--"], "print-libgcc-file-name">,
   HelpText<"Print the library path for \"libgcc.a\"">;
 def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
index 7b61c25..d5107b0 100644 (file)
@@ -4511,7 +4511,13 @@ std::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const {
   QualType BlockTy =
       Expr->getType()->getAs<BlockPointerType>()->getPointeeType();
   // Encode result type.
-  getObjCEncodingForType(BlockTy->getAs<FunctionType>()->getResultType(), S);
+  if (getLangOpts().ObjCExtendedBlockEncode)
+    getObjCEncodingForMethodParameter(Decl::OBJC_TQ_None,
+                            BlockTy->getAs<FunctionType>()->getResultType(),
+                            S, true /*Extended*/);
+  else
+    getObjCEncodingForType(BlockTy->getAs<FunctionType>()->getResultType(),
+                           S);
   // Compute size of all parameters.
   // Start with computing size of a pointer in number of bytes.
   // FIXME: There might(should) be a better way of doing this computation!
@@ -4546,7 +4552,11 @@ std::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const {
         PType = PVDecl->getType();
     } else if (PType->isFunctionType())
       PType = PVDecl->getType();
-    getObjCEncodingForType(PType, S);
+    if (getLangOpts().ObjCExtendedBlockEncode)
+      getObjCEncodingForMethodParameter(Decl::OBJC_TQ_None, PType,
+                                      S, true /*Extended*/);
+    else
+      getObjCEncodingForType(PType, S);
     S += charUnitsToString(ParmOffset);
     ParmOffset += getObjCEncodingTypeSize(PType);
   }
index 8baad79..31dcb23 100644 (file)
@@ -1113,6 +1113,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
 
   if (Args.hasArg(OPT_print_ivar_layout))
     Opts.ObjCGCBitmapPrint = 1;
+  if (Args.hasArg(OPT_encode_extended_block_sig))
+    Opts.ObjCExtendedBlockEncode = 1;
   if (Args.hasArg(OPT_fno_constant_cfstrings))
     Opts.NoConstantCFStrings = 1;
 
diff --git a/clang/test/CodeGenObjC/extended-block-signature-encode.m b/clang/test/CodeGenObjC/extended-block-signature-encode.m
new file mode 100644 (file)
index 0000000..11d5784
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin -encode-extended-block-signature -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s -check-prefix=BRIEF
+// rdar://12109031
+
+@class NSString, NSArray;
+
+typedef NSString*(^BBB)(NSArray*);
+
+int main ()
+{
+  BBB b1;
+  ^(BBB arg1, double arg2){ return b1; }(0, 3.14);
+}
+// CHECK: @{{.*}} = private unnamed_addr constant [64 x i8] c"@?<@\22NSString\22@?@\22NSArray\22>24@?0@?<@\22NSString\22@?@\22NSArray\22>8d16\00"
+// CHECK-BRIEF: @{{.*}} = private unnamed_addr constant [14 x i8] c"@?24@?0@?8d16\00"