[Modules] Fix a crash-on-invalid with overloaded functions

Do not add an overload if the function doesn't have a prototype; this
can happen if, for instance, a misplaced/malformed call site is
considered like a declaration for recovery purposes.

rdar://problem/31306325

llvm-svn: 301453
This commit is contained in:
Bruno Cardoso Lopes 2017-04-26 20:13:45 +00:00
parent d07620663d
commit 370296302d
4 changed files with 18 additions and 0 deletions

View File

@ -11426,6 +11426,10 @@ static void AddOverloadedCallCandidate(Sema &S,
assert(!KnownValid && "Explicit template arguments?");
return;
}
// Prevent ill-formed function decls to be added as overload candidates.
if (!dyn_cast<FunctionProtoType>(Func->getType()->getAs<FunctionType>()))
return;
S.AddOverloadCandidate(Func, FoundDecl, Args, CandidateSet,
/*SuppressUsedConversions=*/false,
PartialOverloading);

View File

@ -0,0 +1,2 @@
@class NSString;
extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))) __attribute__((not_tail_called));

View File

@ -0,0 +1,4 @@
module X {
header "X.h"
export *
}

View File

@ -0,0 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs/malformed-overload -fmodules -fimplicit-module-maps -fmodules-cache-path=tmp -verify %s
NSLog(@"%@", path); // expected-error {{expected parameter declarator}} expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-warning {{incompatible redeclaration}} expected-note {{to match this '('}} expected-note {{'NSLog' is a builtin with type}}
#import "X.h"
@class NSString;
void f(NSString *a) {
NSLog(@"***** failed to get URL for %@", a);
}