[cfe-commits] r64736 - in /cfe/trunk: lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp test/Sema/implicit-builtin-decl.c test/Sema/implicit-builtin-redecl.c
Douglas Gregor
dgregor at apple.com
Mon Feb 16 19:23:10 PST 2009
Author: dgregor
Date: Mon Feb 16 21:23:10 2009
New Revision: 64736
URL: http://llvm.org/viewvc/llvm-project?rev=64736&view=rev
Log:
Static variables and functions won't collide with standard library
functions, so if we're declaring a static we should implicitly declare
a library function by the same name (e.g., malloc, strdup). Fixes PR3592.
Added:
cfe/trunk/test/Sema/implicit-builtin-redecl.c
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/implicit-builtin-decl.c
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=64736&r1=64735&r2=64736&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Feb 16 21:23:10 2009
@@ -271,6 +271,10 @@
// function. Determine whether it actually refers to the C library
// function or whether it just has the same name.
+ // If this is a static function, it's not a builtin.
+ if (getStorageClass() == Static)
+ return 0;
+
// If this function is at translation-unit scope and we're not in
// C++, it refers to the C library function.
if (!Context.getLangOptions().CPlusPlus &&
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=64736&r1=64735&r2=64736&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 16 21:23:10 2009
@@ -1304,7 +1304,9 @@
// See if this is a redefinition of a variable in the same scope.
if (!D.getCXXScopeSpec().isSet() && !D.getCXXScopeSpec().isInvalid()) {
DC = CurContext;
- PrevDecl = LookupName(S, Name, LookupOrdinaryName, true, true,
+ PrevDecl = LookupName(S, Name, LookupOrdinaryName, true,
+ D.getDeclSpec().getStorageClassSpec() !=
+ DeclSpec::SCS_static,
D.getIdentifierLoc());
} else { // Something like "int foo::x;"
DC = static_cast<DeclContext*>(D.getCXXScopeSpec().getScopeRep());
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=64736&r1=64735&r2=64736&view=diff
==============================================================================
--- cfe/trunk/test/Sema/implicit-builtin-decl.c (original)
+++ cfe/trunk/test/Sema/implicit-builtin-decl.c Mon Feb 16 21:23:10 2009
@@ -41,4 +41,3 @@
// expected-note{{use -ffreestanding to compile as a freestanding implementation}}
return p;
}
-
Added: cfe/trunk/test/Sema/implicit-builtin-redecl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-builtin-redecl.c?rev=64736&view=auto
==============================================================================
--- cfe/trunk/test/Sema/implicit-builtin-redecl.c (added)
+++ cfe/trunk/test/Sema/implicit-builtin-redecl.c Mon Feb 16 21:23:10 2009
@@ -0,0 +1,7 @@
+// RUN: clang -fsyntax-only -verify %s
+
+// PR3592
+static void* malloc(int);
+static void* malloc(int size) {
+ return ((void*)0); /*do not use heap in this file*/
+}
More information about the cfe-commits
mailing list