From 3071fb3566f4f03da63529ee5e37d93aca90ebf9 Mon Sep 17 00:00:00 2001 From: Stanislav Mekhanoshin Date: Mon, 5 Apr 2021 13:01:44 -0700 Subject: [PATCH] Set IgnoreLLVMUsed to false in CallGraph::addToCallGraph() clang++ uses llvm.compiler.used in certain cases to preserve symbol which is fully inlined. D96087 has resulted in undefined symbols in such cases. Set it to false by default to preserve old behavior but keep the option for specific uses where we want to ignore these (e.g. to detect a potential indirect call to a function). Differential Revision: https://reviews.llvm.org/D99897 --- lib/Analysis/CallGraph.cpp | 2 +- .../CallGraph/{ignore-llvm-used.ll => llvm-used.ll} | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename test/Analysis/CallGraph/{ignore-llvm-used.ll => llvm-used.ll} (69%) diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index bca45678c6a..dfbd29b7d63 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -82,7 +82,7 @@ void CallGraph::addToCallGraph(Function *F) { if (!F->hasLocalLinkage() || F->hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/true, /* IgnoreAssumeLikeCalls */ true, - /* IgnoreLLVMUsed */ true)) + /* IgnoreLLVMUsed */ false)) ExternalCallingNode->addCalledFunction(nullptr, Node); populateCallGraphNode(Node); diff --git a/test/Analysis/CallGraph/ignore-llvm-used.ll b/test/Analysis/CallGraph/llvm-used.ll similarity index 69% rename from test/Analysis/CallGraph/ignore-llvm-used.ll rename to test/Analysis/CallGraph/llvm-used.ll index ac6569b96f0..09d4e95d594 100644 --- a/test/Analysis/CallGraph/ignore-llvm-used.ll +++ b/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*)]