From: Fariborz Jahanian Date: Fri, 9 Mar 2012 18:47:16 +0000 (+0000) Subject: lldb support: under debugger support flag, when sending message X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=509fb3e2cdf31a0be375eb74bedfddeb648f7d36;p=clang lldb support: under debugger support flag, when sending message to forward class, and assigning to an 'id' type var, message sends default to 'id'. // rdar"//10988847 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152420 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7957473a6b..6c25a20e24 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6209,6 +6209,18 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // Get the decls type and save a reference for later, since // CheckInitializerTypes may change it. QualType DclT = VDecl->getType(), SavT = DclT; + + // Top-level message sends default to 'id' when we're in a debugger + // and we are assigning it to a variable of 'id' type. + if (getLangOptions().DebuggerCastResultToId && DclT->isObjCIdType()) + if (Init->getType() == Context.UnknownAnyTy && isa(Init)) { + ExprResult Result = forceUnknownAnyToType(Init, Context.getObjCIdType()); + if (Result.isInvalid()) { + VDecl->setInvalidDecl(); + return; + } + Init = Result.take(); + } // Perform the initialization. if (!VDecl->isInvalidDecl()) { diff --git a/test/SemaObjC/debugger-cast-result-to-id.m b/test/SemaObjC/debugger-cast-result-to-id.m index 81a630703e..00a02be2c3 100644 --- a/test/SemaObjC/debugger-cast-result-to-id.m +++ b/test/SemaObjC/debugger-cast-result-to-id.m @@ -7,3 +7,10 @@ void test_unknown_anytype_receiver() { (void)(int)[[test0 unknownMethod] otherUnknownMethod];; (void)(id)[[test1() unknownMethod] otherUnknownMethod]; } + +// rdar://10988847 +@class NSString; // expected-note {{forward declaration of class here}} + +void rdar10988847() { + id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}} +} diff --git a/test/SemaObjCXX/debugger-cast-result-to-id.mm b/test/SemaObjCXX/debugger-cast-result-to-id.mm index 9487a22b6c..cd7aa7b6ac 100644 --- a/test/SemaObjCXX/debugger-cast-result-to-id.mm +++ b/test/SemaObjCXX/debugger-cast-result-to-id.mm @@ -7,3 +7,11 @@ namespace test0 { [x foo]; } } + +// rdar://10988847 +@class NSString; // expected-note {{forward declaration of class here}} +namespace test1 { + void rdar10988847() { + id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}} + } +}