[cfe-commits] r67541 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/implicit-builtin-decl.c test/Sema/implicit-builtin-redecl.c
Douglas Gregor
dgregor at apple.com
Mon Mar 23 10:47:24 PDT 2009
Author: dgregor
Date: Mon Mar 23 12:47:24 2009
New Revision: 67541
URL: http://llvm.org/viewvc/llvm-project?rev=67541&view=rev
Log:
Fix PR3855. When we encounter an incompatible redeclaration of a
library function, accept this declaration and pretend that we do not
know that this is a library function. autoconf depends on this
(broken) behavior.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/implicit-builtin-decl.c
cfe/trunk/test/Sema/implicit-builtin-redecl.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67541&r1=67540&r2=67541&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Mar 23 12:47:24 2009
@@ -98,7 +98,7 @@
def err_implicit_decl_requires_stdio : Error<
"implicit declaration of '%0' requires inclusion of the header <stdio.h>">;
def warn_redecl_library_builtin : Warning<
- "incompatible redeclaration of library function %0 will be ignored">;
+ "incompatible redeclaration of library function %0">;
def err_builtin_definition : Error<"definition of builtin function %0">;
/// parser diagnostics
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=67541&r1=67540&r2=67541&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 23 12:47:24 2009
@@ -747,11 +747,14 @@
if (Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) {
// The function the user is redeclaring is a library-defined
// function like 'malloc' or 'printf'. Warn about the
- // redeclaration, then ignore it.
+ // redeclaration, then pretend that we don't know about this
+ // library built-in.
Diag(New->getLocation(), diag::warn_redecl_library_builtin) << New;
Diag(Old->getLocation(), diag::note_previous_builtin_declaration)
<< Old << Old->getType();
- return true;
+ New->getIdentifier()->setBuiltinID(Builtin::NotBuiltin);
+ Old->setInvalidDecl();
+ return false;
}
PrevDiag = diag::note_previous_builtin_declaration;
Modified: cfe/trunk/test/Sema/implicit-builtin-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-builtin-decl.c?rev=67541&r1=67540&r2=67541&view=diff
==============================================================================
--- cfe/trunk/test/Sema/implicit-builtin-decl.c (original)
+++ cfe/trunk/test/Sema/implicit-builtin-decl.c Mon Mar 23 12:47:24 2009
@@ -7,7 +7,7 @@
void *alloca(__SIZE_TYPE__); // redeclaration okay
-int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc' will be ignored}} \
+int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \
// expected-note{{'calloc' is a builtin with type 'void *}}
@@ -16,8 +16,8 @@
}
void h() {
- int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc' will be ignored}}
- int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy' will be ignored}} \
+ int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}}
+ int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \
// expected-note{{'strcpy' is a builtin with type 'char *(char *, char const *)'}}
}
@@ -35,7 +35,19 @@
return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
}
-void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc' will be ignored}} \
+void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \
// expected-note{{'realloc' is a builtin with type 'void *(void *,}}
return p;
}
+
+// PR3855
+void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \
+ // expected-note{{'snprintf' is a builtin with type 'int (char *, unsigned long, char const *, ...)'}}
+
+int
+main(int argc, char *argv[])
+{
+ snprintf();
+}
+
+void snprintf() { }
Modified: cfe/trunk/test/Sema/implicit-builtin-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-builtin-redecl.c?rev=67541&r1=67540&r2=67541&view=diff
==============================================================================
--- cfe/trunk/test/Sema/implicit-builtin-redecl.c (original)
+++ cfe/trunk/test/Sema/implicit-builtin-redecl.c Mon Mar 23 12:47:24 2009
@@ -10,5 +10,5 @@
// expected-note{{'calloc' is a builtin with type 'void *}}
void f1(void) {
- return calloc(0, 0, 0); // expected-error{{too many arguments to function call}}
+ calloc(0, 0, 0);
}
More information about the cfe-commits
mailing list