[PATCH] D99897: Set IgnoreLLVMUsed to false in CallGraph::addToCallGraph()

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 5 13:23:47 PDT 2021


rampitec created this revision.
rampitec added reviewers: arsenm, madhur13490, chandlerc, ggeorgakoudis.
Herald added a subscriber: hiraditya.
rampitec requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

clang++ uses llvm.compiler.used in certain cases to preserve
symbol which is fully inlined. D96087 <https://reviews.llvm.org/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).


https://reviews.llvm.org/D99897

Files:
  llvm/lib/Analysis/CallGraph.cpp
  llvm/test/Analysis/CallGraph/ignore-llvm-used.ll
  llvm/test/Analysis/CallGraph/llvm-used.ll


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 <<null function>><<{{.*}}>>  #uses=0
+; CHECK-NEXT:  CS<None> calls function 'used1'
+; CHECK-NEXT:  CS<None> calls function 'used2'
 ; CHECK-NEXT:  CS<None> 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*)]
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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99897.335313.patch
Type: text/x-patch
Size: 1827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210405/1962d0b2/attachment.bin>


More information about the llvm-commits mailing list