diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-17 03:23:10 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-17 03:23:10 +0000 |
commit | a908e7fcccf038abcb665be9192a71a7ec0b8394 (patch) | |
tree | 38a3e4a3d813860f8f57242fd4b102607a9c5873 /clang | |
parent | b317efdf818b7cbbb5fb3f707d2c7113a26c182a (diff) | |
download | bcm5719-llvm-a908e7fcccf038abcb665be9192a71a7ec0b8394.tar.gz bcm5719-llvm-a908e7fcccf038abcb665be9192a71a7ec0b8394.zip |
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.
llvm-svn: 64736
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 4 | ||||
-rw-r--r-- | clang/test/Sema/implicit-builtin-decl.c | 1 | ||||
-rw-r--r-- | clang/test/Sema/implicit-builtin-redecl.c | 7 |
4 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index ca1fa0c1e12..387f79a013f 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -271,6 +271,10 @@ unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const { // 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 && diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7b8373ca390..bf6a637ac26 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1304,7 +1304,9 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl, // 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()); diff --git a/clang/test/Sema/implicit-builtin-decl.c b/clang/test/Sema/implicit-builtin-decl.c index 892e372eff6..efaf3ed4553 100644 --- a/clang/test/Sema/implicit-builtin-decl.c +++ b/clang/test/Sema/implicit-builtin-decl.c @@ -41,4 +41,3 @@ void * realloc(void *p, int size) { // expected-warning{{incompatible redeclarat // expected-note{{use -ffreestanding to compile as a freestanding implementation}} return p; } - diff --git a/clang/test/Sema/implicit-builtin-redecl.c b/clang/test/Sema/implicit-builtin-redecl.c new file mode 100644 index 00000000000..837f79f4ef6 --- /dev/null +++ b/clang/test/Sema/implicit-builtin-redecl.c @@ -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*/ +} |