Index: llvm/lib/Analysis/CallGraph.cpp =================================================================== --- llvm/lib/Analysis/CallGraph.cpp +++ llvm/lib/Analysis/CallGraph.cpp @@ -82,7 +82,7 @@ if (!F->hasLocalLinkage() || F->hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/true, /* IgnoreAssumeLikeCalls */ true, - /* IgnoreLLVMUsed */ true)) + /* IgnoreLLVMUsed */ false)) ExternalCallingNode->addCalledFunction(nullptr, Node); populateCallGraphNode(Node); Index: llvm/test/Analysis/CallGraph/llvm-used.ll =================================================================== --- llvm/test/Analysis/CallGraph/llvm-used.ll +++ llvm/test/Analysis/CallGraph/llvm-used.ll @@ -1,12 +1,20 @@ ; RUN: opt < %s -print-callgraph -disable-output 2>&1 | FileCheck %s + +; The test will report used1 and used2 functions as used on the grounds +; of llvm.*.used references. Passing IgnoreLLVMUsed = true into the +; Function::hasAddressTaken() in the CallGraph::addToCallGraph() has to +; change their uses to zero. + ; CHECK: Call graph node <><<{{.*}}>> #uses=0 +; CHECK-NEXT: CS calls function 'used1' +; CHECK-NEXT: CS calls function 'used2' ; CHECK-NEXT: CS calls function 'unused' ; CHECK-EMPTY: ; CHECK-NEXT: Call graph node for function: 'unused'<<{{.*}}>> #uses=1 ; CHECK-EMPTY: -; CHECK-NEXT: Call graph node for function: 'used1'<<{{.*}}>> #uses=0 +; CHECK-NEXT: Call graph node for function: 'used1'<<{{.*}}>> #uses=1 ; CHECK-EMPTY: -; CHECK-NEXT: Call graph node for function: 'used2'<<{{.*}}>> #uses=0 +; CHECK-NEXT: Call graph node for function: 'used2'<<{{.*}}>> #uses=1 ; CHECK-EMPTY: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @used1 to i8*)]