aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-01-08 19:43:34 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-01-08 19:43:34 +0000
commitb9725cfb0a50731930a6331beb70f361b4d52a29 (patch)
treed5b325c55bff6ec06d00be7fbae9af927ae14fa3 /lib/Sema/SemaExpr.cpp
parentcb4d690820295d93c1cea6c13fb4409b8c1db2cf (diff)
Mark all subsequent decls used.
In the source static void f(); static void f(); template<typename T> static void g() { f(); } static void f() { } void h() { g<int>(); } the call to f refers to the second decl, but it is only marked used at the end of the translation unit during instantiation, after the third f decl has been linked in. With this patch we mark all subsequent decls used, so that it is easy to check if a symbol is used or not. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171888 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 3702aa037c..cc692cda63 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -10495,7 +10495,18 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func) {
if (old.isInvalid()) old = Loc;
}
- Func->setUsed(true);
+ // Normally the must current decl is marked used while processing the use and
+ // any subsequent decls are marked used by decl merging. This fails with
+ // template instantiation since marking can happen at the end of the file
+ // and, because of the two phase lookup, this function is called with at
+ // decl in the middle of a decl chain. We loop to maintain the invariant
+ // that once a decl is used, all decls after it are also used.
+ for (FunctionDecl *F = Func->getMostRecentDecl();;) {
+ F->setUsed(true);
+ if (F == Func)
+ break;
+ F = F->getPreviousDecl();
+ }
}
static void