From: Bruno Cardoso Lopes Date: Wed, 26 Apr 2017 20:13:45 +0000 (+0000) Subject: [Modules] Fix a crash-on-invalid with overloaded functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfe08f4f9084dde84191a0095c3970ee07654a09;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301453 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 29ba34479d..782c377e32 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -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(Func->getType()->getAs())) + return; + S.AddOverloadCandidate(Func, FoundDecl, Args, CandidateSet, /*SuppressUsedConversions=*/false, PartialOverloading); diff --git a/test/Modules/Inputs/malformed-overload/X.h b/test/Modules/Inputs/malformed-overload/X.h new file mode 100644 index 0000000000..b659406e16 --- /dev/null +++ b/test/Modules/Inputs/malformed-overload/X.h @@ -0,0 +1,2 @@ +@class NSString; +extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))) __attribute__((not_tail_called)); diff --git a/test/Modules/Inputs/malformed-overload/module.modulemap b/test/Modules/Inputs/malformed-overload/module.modulemap new file mode 100644 index 0000000000..8fe4c92a17 --- /dev/null +++ b/test/Modules/Inputs/malformed-overload/module.modulemap @@ -0,0 +1,4 @@ +module X { + header "X.h" + export * +} diff --git a/test/Modules/malformed-overload.m b/test/Modules/malformed-overload.m new file mode 100644 index 0000000000..ad6db8a46c --- /dev/null +++ b/test/Modules/malformed-overload.m @@ -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); +}