Skip to content

Commit

Permalink
[Modules] Fix a crash-on-invalid with overloaded functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bcardosolopes committed Apr 26, 2017
1 parent 9bc5210 commit cfe08f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/Modules/Inputs/malformed-overload/X.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@class NSString;
extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))) __attribute__((not_tail_called));
4 changes: 4 additions & 0 deletions test/Modules/Inputs/malformed-overload/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module X {
header "X.h"
export *
}
8 changes: 8 additions & 0 deletions test/Modules/malformed-overload.m
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit cfe08f4

Please sign in to comment.