r301453 - [Modules] Fix a crash-on-invalid with overloaded functions
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 26 13:13:45 PDT 2017
Author: bruno
Date: Wed Apr 26 15:13:45 2017
New Revision: 301453
URL: http://llvm.org/viewvc/llvm-project?rev=301453&view=rev
Log:
[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
Added:
cfe/trunk/test/Modules/Inputs/malformed-overload/
cfe/trunk/test/Modules/Inputs/malformed-overload/X.h
cfe/trunk/test/Modules/Inputs/malformed-overload/module.modulemap
cfe/trunk/test/Modules/malformed-overload.m
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=301453&r1=301452&r2=301453&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Apr 26 15:13:45 2017
@@ -11426,6 +11426,10 @@ static void AddOverloadedCallCandidate(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);
Added: cfe/trunk/test/Modules/Inputs/malformed-overload/X.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/malformed-overload/X.h?rev=301453&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/malformed-overload/X.h (added)
+++ cfe/trunk/test/Modules/Inputs/malformed-overload/X.h Wed Apr 26 15:13:45 2017
@@ -0,0 +1,2 @@
+ at class NSString;
+extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))) __attribute__((not_tail_called));
Added: cfe/trunk/test/Modules/Inputs/malformed-overload/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/malformed-overload/module.modulemap?rev=301453&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/malformed-overload/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/malformed-overload/module.modulemap Wed Apr 26 15:13:45 2017
@@ -0,0 +1,4 @@
+module X {
+ header "X.h"
+ export *
+}
Added: cfe/trunk/test/Modules/malformed-overload.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/malformed-overload.m?rev=301453&view=auto
==============================================================================
--- cfe/trunk/test/Modules/malformed-overload.m (added)
+++ cfe/trunk/test/Modules/malformed-overload.m Wed Apr 26 15:13:45 2017
@@ -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"
+
+ at class NSString;
+void f(NSString *a) {
+ NSLog(@"***** failed to get URL for %@", a);
+}
More information about the cfe-commits
mailing list