/// Built-in functions.
def ext_implicit_lib_function_decl : ExtWarn<
"implicitly declaring library function '%0' with type %1">;
-def note_please_include_header : Note<
- "please include the header <%0> or explicitly provide a "
- "declaration for '%1'">;
+def note_include_header_or_declare : Note<
+ "include the header <%0> or explicitly provide a declaration for '%1'">;
def note_previous_builtin_declaration : Note<"%0 is a builtin with type %1">;
-def warn_implicit_decl_requires_stdio : Warning<
- "declaration of built-in function '%0' requires inclusion of the header "
- "<stdio.h>">,
- InGroup<BuiltinRequiresHeader>;
-def warn_implicit_decl_requires_setjmp : Warning<
- "declaration of built-in function '%0' requires inclusion of the header "
- "<setjmp.h>">,
- InGroup<BuiltinRequiresHeader>;
-def warn_implicit_decl_requires_ucontext : Warning<
- "declaration of built-in function '%0' requires inclusion of the header "
- "<ucontext.h>">,
+def warn_implicit_decl_requires_sysheader : Warning<
+ "declaration of built-in function '%1' requires inclusion of the header <%0>">,
InGroup<BuiltinRequiresHeader>;
def warn_redecl_library_builtin : Warning<
"incompatible redeclaration of library function %0">,
if (!EmitHeaderHint)
return;
- S.Diag(Loc, diag::note_please_include_header) << HeaderName << FunctionName;
+ S.Diag(Loc, diag::note_include_header_or_declare) << HeaderName
+ << FunctionName;
}
static bool IsFunctionStdAbs(const FunctionDecl *FDecl) {
QualType ArgType = Call->getArg(0)->IgnoreParenImpCasts()->getType();
QualType ParamType = Call->getArg(0)->getType();
- // Unsigned types can not be negative. Suggest to drop the absolute value
- // function.
+ // Unsigned types cannot be negative. Suggest removing the absolute value
+ // function call.
if (ArgType->isUnsignedIntegerType()) {
const char *FunctionName =
IsStdAbs ? "std::abs" : Context.BuiltinInfo.GetName(AbsKind);
Context.setObjCSuperType(Context.getTagDeclType(TD));
}
+static StringRef getHeaderName(ASTContext::GetBuiltinTypeError Error) {
+ switch (Error) {
+ case ASTContext::GE_None:
+ return "";
+ case ASTContext::GE_Missing_stdio:
+ return "stdio.h";
+ case ASTContext::GE_Missing_setjmp:
+ return "setjmp.h";
+ case ASTContext::GE_Missing_ucontext:
+ return "ucontext.h";
+ }
+ llvm_unreachable("unhandled error kind");
+}
+
/// LazilyCreateBuiltin - The specified Builtin-ID was first used at
/// file scope. lazily create a decl for it. ForRedeclaration is true
/// if we're creating this built-in in anticipation of redeclaring the
ASTContext::GetBuiltinTypeError Error;
QualType R = Context.GetBuiltinType(BID, Error);
- switch (Error) {
- case ASTContext::GE_None:
- // Okay
- break;
-
- case ASTContext::GE_Missing_stdio:
- if (ForRedeclaration)
- Diag(Loc, diag::warn_implicit_decl_requires_stdio)
- << Context.BuiltinInfo.GetName(BID);
- return nullptr;
-
- case ASTContext::GE_Missing_setjmp:
- if (ForRedeclaration)
- Diag(Loc, diag::warn_implicit_decl_requires_setjmp)
- << Context.BuiltinInfo.GetName(BID);
- return nullptr;
-
- case ASTContext::GE_Missing_ucontext:
+ if (Error) {
if (ForRedeclaration)
- Diag(Loc, diag::warn_implicit_decl_requires_ucontext)
- << Context.BuiltinInfo.GetName(BID);
+ Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
+ << getHeaderName(Error)
+ << Context.BuiltinInfo.GetName(BID);
return nullptr;
}
<< R;
if (Context.BuiltinInfo.getHeaderName(BID) &&
!Diags.isIgnored(diag::ext_implicit_lib_function_decl, Loc))
- Diag(Loc, diag::note_please_include_header)
- << Context.BuiltinInfo.getHeaderName(BID)
- << Context.BuiltinInfo.GetName(BID);
+ Diag(Loc, diag::note_include_header_or_declare)
+ << Context.BuiltinInfo.getHeaderName(BID)
+ << Context.BuiltinInfo.GetName(BID);
}
DeclContext *Parent = Context.getTranslationUnitDecl();
char *c = (char*)b; // no-warning
char *d = b+1; // expected-warning {{never read}} expected-warning{{unused variable 'd'}}
printf("%s", c); // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \
- // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
+ // expected-note{{include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
}
int f();
F12_typedef* x;
x = f2_helper();
memcpy((&x[1]), (buf), 1); // expected-warning{{implicitly declaring library function 'memcpy' with type 'void *(void *, const void *}} \
- // expected-note{{please include the header <string.h> or explicitly provide a declaration for 'memcpy'}}
+ // expected-note{{include the header <string.h> or explicitly provide a declaration for 'memcpy'}}
}
int main() {
@try {
printf("executing try"); // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \
- // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
+ // expected-note{{include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
return(0); // expected-warning{{rewriter doesn't support user-specified control flow semantics for @try/@finally (code may not execute properly)}}
} @finally {
printf("executing finally");
int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(const char *)' with an expression of type 'int (char *)'}}
int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}} \
- // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
+ // expected-note{{include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
}
typedef void (^bptr)(void);
void f() {
int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
- // expected-note{{please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
+ // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
// expected-note{{'malloc' is a builtin with type 'void *}}
}
(void)abs(d);
// expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
// expected-note@-2{{use function 'fabs' instead}}
- // expected-note@-3{{please include the header <math.h> or explicitly provide a declaration for 'fabs'}}
+ // expected-note@-3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs"
}
(void)abs(d);
// expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
// expected-note@-2{{use function 'std::abs' instead}}
- // expected-note@-3{{please include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
+ // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs"
(void)fabsf(d);
// expected-warning@-1{{absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value}}
// expected-note@-2{{use function 'std::abs' instead}}
- // expected-note@-3{{please include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
+ // expected-note@-3{{include the header <cmath> or explicitly provide a declaration for 'std::abs'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs"
// Suggest including cstdlib
(void)abs(ll);
// expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}}
// expected-note@-2{{use function 'std::abs' instead}}
- // expected-note@-3{{please include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
+ // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs"
(void)fabsf(ll);
// expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}}
// expected-note@-2{{use function 'std::abs' instead}}
- // expected-note@-3{{please include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
+ // expected-note@-3{{include the header <cstdlib> or explicitly provide a declaration for 'std::abs'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs"
// Proper function already called, no warnings.
// RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify
// rdar://8592641
Class f0() { return objc_getClass("a"); } // expected-warning {{implicitly declaring library function 'objc_getClass' with type 'id (const char *)'}} \
- // expected-note {{please include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getClass'}}
+ // expected-note {{include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getClass'}}
// rdar://8735023
Class f1() { return objc_getMetaClass("a"); } // expected-warning {{implicitly declaring library function 'objc_getMetaClass' with type 'id (const char *)'}} \
- // expected-note {{please include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getMetaClass'}}
+ // expected-note {{include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getMetaClass'}}
void f2(id val) { objc_enumerationMutation(val); } // expected-warning {{implicitly declaring library function 'objc_enumerationMutation' with type 'void (id)'}} \
- // expected-note {{please include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_enumerationMutation'}}
+ // expected-note {{include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_enumerationMutation'}}
long double f3(id self, SEL op) { return objc_msgSend_fpret(self, op); } // expected-warning {{implicitly declaring library function 'objc_msgSend_fpret' with type 'long double (id, SEL, ...)'}} \
- // expected-note {{please include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSend_fpret'}}
+ // expected-note {{include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSend_fpret'}}
id f4(struct objc_super *super, SEL op) { // expected-warning {{declaration of 'struct objc_super' will not be visible outside of this function}}
return objc_msgSendSuper(super, op); // expected-warning {{implicitly declaring library function 'objc_msgSendSuper' with type 'id (struct objc_super *, SEL, ...)'}} \
- // expected-note {{please include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSendSuper'}}
+ // expected-note {{include the header <objc/message.h> or explicitly provide a declaration for 'objc_msgSendSuper'}}
}
id f5(id val, id *dest) {
return objc_assign_strongCast(val, dest); // expected-warning {{implicitly declaring library function 'objc_assign_strongCast' with type 'id (id, id *)'}} \
- // expected-note {{please include the header <objc/objc-auto.h> or explicitly provide a declaration for 'objc_assign_strongCast'}}
+ // expected-note {{include the header <objc/objc-auto.h> or explicitly provide a declaration for 'objc_assign_strongCast'}}
}
int f6(Class exceptionClass, id exception) {
return objc_exception_match(exceptionClass, exception); // expected-warning {{implicitly declaring library function 'objc_exception_match' with type 'int (id, id)'}} \
- // expected-note {{please include the header <objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}}
+ // expected-note {{include the header <objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}}
}
void f1(id arg) {
NSLog(@"%@", arg); // expected-warning {{implicitly declaring library function 'NSLog' with type 'void (id, ...)'}} \
- // expected-note {{please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLog'}}
+ // expected-note {{include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLog'}}
}
void f2(id str, va_list args) {
NSLogv(@"%@", args); // expected-warning {{implicitly declaring library function 'NSLogv' with type }} \
- // expected-note {{please include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLogv'}}
+ // expected-note {{include the header <Foundation/NSObjCRuntime.h> or explicitly provide a declaration for 'NSLogv'}}
}
- (int) InstMethod
{
return index; // expected-warning {{implicitly declaring library function 'index'}} \
- // expected-note {{please include the header <strings.h> or explicitly provide a declaration for 'index'}} \
+ // expected-note {{include the header <strings.h> or explicitly provide a declaration for 'index'}} \
// expected-warning {{incompatible pointer to integer conversion returning}}
}
+ (int) ClassMethod