diff options
author | Momchil Velikov <momchil.velikov@arm.com> | 2017-08-10 15:43:06 +0000 |
---|---|---|
committer | Momchil Velikov <momchil.velikov@arm.com> | 2017-08-10 15:43:06 +0000 |
commit | 57c681f33e56019ab92901e09d7bd26b0ccdffa5 (patch) | |
tree | d04a2d4992b1b8f97d8ac8aa0f7e07df124e5257 /clang/lib/Sema/SemaDecl.cpp | |
parent | c717041e847db8bd7dfee61ee2a00c3653704651 (diff) | |
download | bcm5719-llvm-57c681f33e56019ab92901e09d7bd26b0ccdffa5.tar.gz bcm5719-llvm-57c681f33e56019ab92901e09d7bd26b0ccdffa5.zip |
Place implictly declared functions at block scope
Such implicitly declared functions behave as if the enclosing block
contained the declaration extern int name() (C90, 6.3.3.2 Function calls),
thus their names should have block scope (C90, 6.1.2.1 Scope of identifiers).
This patch fixes https://bugs.llvm.org/show_bug.cgi?id=33224
Differential Revision: https://reviews.llvm.org/D33676
llvm-svn: 310616
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6bcb0231743..d19ace9c43b 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -12677,12 +12677,16 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, SourceLocation()); D.SetIdentifier(&II, Loc); - // Insert this function into translation-unit scope. + // Insert this function into the enclosing block scope. + while (S && !S->isCompoundStmtScope()) + S = S->getParent(); + if (S == nullptr) + S = TUScope; DeclContext *PrevDC = CurContext; CurContext = Context.getTranslationUnitDecl(); - FunctionDecl *FD = cast<FunctionDecl>(ActOnDeclarator(TUScope, D)); + FunctionDecl *FD = cast<FunctionDecl>(ActOnDeclarator(S, D)); FD->setImplicit(); CurContext = PrevDC; |