-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Improve clarity of the implicit declaration diagnostic #149314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1f8871f
2fb5212
148a1ca
361cc9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,33 @@ class Context { | |
return getInfo(ID).Header.getName(); | ||
} | ||
|
||
/// Returns true if a library function is declared within a C or C++ standard | ||
/// header (like stdio.h) or POSIX header (like malloc.h), false if the | ||
/// function is not declared within a header or is declared in a non-standard | ||
/// header (like Microsoft or Objective-C headers). | ||
bool isDeclaredInStandardHeader(unsigned ID) const { | ||
switch (getInfo(ID).Header.ID) { | ||
default: | ||
return false; | ||
case HeaderDesc::COMPLEX_H: // C99 | ||
case HeaderDesc::CTYPE_H: // C89 | ||
case HeaderDesc::MATH_H: // C89 | ||
case HeaderDesc::MALLOC_H: // POSIX | ||
case HeaderDesc::MEMORY: // C++98 | ||
case HeaderDesc::PTHREAD_H: // POSIX | ||
case HeaderDesc::SETJMP_H: // C89 | ||
case HeaderDesc::STDARG_H: // C89 | ||
case HeaderDesc::STDIO_H: // C89 | ||
case HeaderDesc::STDLIB_H: // C89 | ||
case HeaderDesc::STRING_H: // C89 | ||
case HeaderDesc::STRINGS_H: // POSIX | ||
case HeaderDesc::UNISTD_H: // POSIX | ||
case HeaderDesc::UTILITY: // C++98 | ||
case HeaderDesc::WCHAR_H: // C99 | ||
return true; | ||
} | ||
} | ||
Comment on lines
+383
to
+404
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we modify the HEADER macro in BuiltinHeaders.def to generate that automatically? |
||
|
||
/// Determine whether this builtin is like printf in its | ||
/// formatting rules and, if so, set the index to the format string | ||
/// argument and whether this function as a va_list argument. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -816,11 +816,12 @@ def warn_unreachable_association : Warning< | |
|
||
/// Built-in functions. | ||
def ext_implicit_lib_function_decl : ExtWarn< | ||
"implicitly declaring library function '%0' with type %1">, | ||
InGroup<ImplicitFunctionDeclare>; | ||
"implicitly declaring library function '%0' with%select{| standards-mandated}2 " | ||
"type %1">, InGroup<ImplicitFunctionDeclare>; | ||
def ext_implicit_lib_function_decl_c99 : ExtWarn< | ||
"call to undeclared library function '%0' with type %1; ISO C99 and later " | ||
"do not support implicit function declarations">, | ||
"call to undeclared library function '%0', will assume it exists with" | ||
"%select{| standards-mandated}2 type %1; ISO C99 and later do not support " | ||
"implicit function declarations">, | ||
InGroup<ImplicitFunctionDeclare>, DefaultError; | ||
Comment on lines
818
to
825
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A way to simplify (ie, get rid of (where %2 is WDYT? |
||
def note_include_header_or_declare : Note< | ||
"include the header <%0> or explicitly provide a declaration for '%1'">; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ void_typedef f2_helper(void); | |
static void f2(void *buf) { | ||
F12_typedef* x; | ||
x = f2_helper(); | ||
memcpy((&x[1]), (buf), 1); // expected-warning{{call to undeclared library function 'memcpy' with type 'void *(void *, const void *}} \ | ||
memcpy((&x[1]), (buf), 1); // expected-warning{{call to undeclared library function 'memcpy', will assume it exists with standards-mandated type 'void *(void *, const void *,}} \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, there's another type in the parameter list, but it's size_t which resolves to different types on different systems, so it's dropped here for the same reason it was dropped before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The target tripple is pinned in the test. We could spell it out if we wanted. |
||
// expected-note{{include the header <string.h> or explicitly provide a declaration for 'memcpy'}} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -verify %s | ||
|
||
void f() { | ||
int *ptr = malloc(sizeof(int) * 10); // expected-error{{call to undeclared library function 'malloc' with type}} \ | ||
int *ptr = malloc(sizeof(int) * 10); // expected-error{{call to undeclared library function 'malloc'}} \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing happening here as above. |
||
// expected-note{{include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \ | ||
// expected-note{{'malloc' is a builtin with type 'void *}} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
// RUN: %clang_cc1 -x objective-c %s -fsyntax-only -verify | ||
Class f0(void) { return objc_getClass("a"); } // expected-error {{call to undeclared library function 'objc_getClass' with type 'id (const char *)'}} \ | ||
Class f0(void) { return objc_getClass("a"); } // expected-error {{call to undeclared library function 'objc_getClass', will assume it exists with type 'id (const char *)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// expected-note {{include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getClass'}} | ||
|
||
Class f1(void) { return objc_getMetaClass("a"); } // expected-error {{call to undeclared library function 'objc_getMetaClass' with type 'id (const char *)'}} \ | ||
Class f1(void) { return objc_getMetaClass("a"); } // expected-error {{call to undeclared library function 'objc_getMetaClass', will assume it exists with type 'id (const char *)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// expected-note {{include the header <objc/runtime.h> or explicitly provide a declaration for 'objc_getMetaClass'}} | ||
|
||
void f2(id val) { objc_enumerationMutation(val); } // expected-error {{call to undeclared library function 'objc_enumerationMutation' with type 'void (id)'}} \ | ||
void f2(id val) { objc_enumerationMutation(val); } // expected-error {{call to undeclared library function 'objc_enumerationMutation', will assume it exists with type 'void (id)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// 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-error {{call to undeclared library function 'objc_msgSend_fpret' with type 'long double (id, SEL, ...)'}} \ | ||
long double f3(id self, SEL op) { return objc_msgSend_fpret(self, op); } // expected-error {{call to undeclared library function 'objc_msgSend_fpret', will assume it exists with type 'long double (id, SEL, ...)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// 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-error {{call to undeclared library function 'objc_msgSendSuper' with type 'id (struct objc_super *, SEL, ...)'}} \ | ||
return objc_msgSendSuper(super, op); // expected-error {{call to undeclared library function 'objc_msgSendSuper', will assume it exists with type 'id (struct objc_super *, SEL, ...)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// 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-error {{call to undeclared library function 'objc_assign_strongCast' with type 'id (id, id *)'}} \ | ||
return objc_assign_strongCast(val, dest); // expected-error {{call to undeclared library function 'objc_assign_strongCast', will assume it exists with type 'id (id, id *)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// 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-error {{call to undeclared library function 'objc_exception_match' with type 'int (id, id)'}} \ | ||
return objc_exception_match(exceptionClass, exception); // expected-error {{call to undeclared library function 'objc_exception_match', will assume it exists with type 'int (id, id)'; ISO C99 and later do not support implicit function declarations}} \ | ||
// expected-note {{include the header <objc/objc-exception.h> or explicitly provide a declaration for 'objc_exception_match'}} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you double check this is aligned as it should?