objective-C blocks: under cc1 flag -encode-extended-block-signature,

generate expanded signature encoding to include types as we
already do this for protocol method lists.
// rdar://12109031

llvm-svn: 167997
This commit is contained in:
Fariborz Jahanian 2012-11-14 23:11:38 +00:00
parent e0db519ae9
commit 64223e6db1
5 changed files with 32 additions and 2 deletions

View 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")

View 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">;

View 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);
}

View 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;

View File

@ -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"