diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c8e8ecda86..6c25c272f3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7683,7 +7683,10 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { } // FIXME: keep track of references to static functions - Function->setUsed(true); + + // Recursive functions should be marked when used from another function. + if (CurContext != Function) + Function->setUsed(true); return; } diff --git a/test/Sema/warn-unused-function.c b/test/Sema/warn-unused-function.c index 5ae0cce079..24d4fade9b 100644 --- a/test/Sema/warn-unused-function.c +++ b/test/Sema/warn-unused-function.c @@ -44,3 +44,6 @@ static void f11(void) { } // expected-warning{{unused}} static void f12(void) { } // expected-warning{{unused}} static void f12(void); + +// PR7923 +static void unused(void) { unused(); } // expected-warning{{unused}}