Author: ahatanak Date: Fri Nov 18 18:13:03 2016 New Revision: 287410 URL: http://llvm.org/viewvc/llvm-project?rev=287410&view=rev Log: [Sema] Don't allow applying address-of operator to a call to a function with __unknown_anytype return type.
When the following code is compiled, Sema infers that the type of __unknown_anytype is double: extern __unknown_anytype func(); double *d = (double*)&func(); This triggers an assert in CodeGenFunction::EmitCallExprLValue because it doesn't expect to see a call to a function with a non-reference scalar return type. This commit prevents the assert by making VisitUnaryAddrOf error out if the address-of operator is applied to a call to a function with __unknown_anytype return type. rdar://problem/20287610 Differential revision: https://reviews.llvm.org/D26808 Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/unknown-anytype.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=287410&r1=287409&r2=287410&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Nov 18 18:13:03 2016 @@ -8031,6 +8031,9 @@ def err_unsupported_unknown_any_call : E def err_unknown_any_addrof : Error< "the address of a declaration with unknown type " "can only be cast to a pointer type">; +def err_unknown_any_addrof_call : Error< + "address-of operator cannot be applied to a call to a function with " + "unknown return type">; def err_unknown_any_var_function_type : Error< "variable %0 with unknown type cannot be given a function type">; def err_unknown_any_function : Error< Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=287410&r1=287409&r2=287410&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Nov 18 18:13:03 2016 @@ -14774,6 +14774,13 @@ namespace { << E->getSourceRange(); return ExprError(); } + + if (isa<CallExpr>(E->getSubExpr())) { + S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof_call) + << E->getSourceRange(); + return ExprError(); + } + assert(E->getValueKind() == VK_RValue); assert(E->getObjectKind() == OK_Ordinary); E->setType(DestType); Modified: cfe/trunk/test/SemaCXX/unknown-anytype.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/unknown-anytype.cpp?rev=287410&r1=287409&r2=287410&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/unknown-anytype.cpp (original) +++ cfe/trunk/test/SemaCXX/unknown-anytype.cpp Fri Nov 18 18:13:03 2016 @@ -56,3 +56,15 @@ namespace test5 { (X<int>)test0(); // expected-error{{implicit instantiation of undefined template 'test5::X<int>'}} } } + +namespace test6 { + extern __unknown_anytype func(); + extern __unknown_anytype var; + double *d; + + void test() { + d = (double*)&func(); // expected-error{{address-of operator cannot be applied to a call to a function with unknown return type}} + d = (double*)&var; + } + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits