From ae778dec7a29cce7246ad39a02e4e3e3ef7f6226 Mon Sep 17 00:00:00 2001 From: Aleksei Sidorin Date: Mon, 20 Feb 2017 09:16:48 +0000 Subject: [PATCH] [analyzer] Do not duplicate call graph nodes for functions that have definition and forward declaration Patch by Ivan Sidorenko! Differential Revision: https://reviews.llvm.org/D29643 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295644 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/CallGraph.h | 2 +- test/Analysis/debug-CallGraph.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/clang/Analysis/CallGraph.h b/include/clang/Analysis/CallGraph.h index b8ae67cbba..a2a27a8e47 100644 --- a/include/clang/Analysis/CallGraph.h +++ b/include/clang/Analysis/CallGraph.h @@ -98,7 +98,7 @@ public: bool VisitFunctionDecl(FunctionDecl *FD) { // We skip function template definitions, as their semantics is // only determined when they are instantiated. - if (includeInGraph(FD)) { + if (includeInGraph(FD) && FD->isThisDeclarationADefinition()) { // Add all blocks declared inside this function to the graph. addNodesForBlocks(FD); // If this function has external linkage, anything could call it. diff --git a/test/Analysis/debug-CallGraph.c b/test/Analysis/debug-CallGraph.c index 686abb06e7..3488227605 100644 --- a/test/Analysis/debug-CallGraph.c +++ b/test/Analysis/debug-CallGraph.c @@ -43,8 +43,18 @@ void eee(); void eee() {} void fff() { eee(); } +// This test case tests that forward declaration for the top-level function +// does not affect call graph construction. +void do_nothing() {} +void test_single_call(); +void test_single_call() { + do_nothing(); +} + // CHECK:--- Call graph Dump --- -// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ccc ddd eee fff $}} +// CHECK-NEXT: {{Function: < root > calls: get5 add test_add mmm foo aaa < > bbb ddd ccc eee fff do_nothing test_single_call $}} +// CHECK-NEXT: {{Function: test_single_call calls: do_nothing $}} +// CHECK-NEXT: {{Function: do_nothing calls: $}} // CHECK-NEXT: {{Function: fff calls: eee $}} // CHECK-NEXT: {{Function: eee calls: $}} // CHECK-NEXT: {{Function: ddd calls: ccc $}} -- 2.40.0