[PATCH] D142058: [llvm][DiagnosticInfo] handle function pointer casts

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 14:06:54 PST 2023


nickdesaulniers created this revision.
nickdesaulniers added reviewers: arsenm, nikic, aeubanks.
Herald added subscribers: StephenFan, pengfei, hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

As pointed out by @arsenm in https://reviews.llvm.org/D141451#4045099,
we don't handle ConstantExpressions for dontcall-{warn|error} IR Fn
Attrs.

Use CallBase::getCalledOperand() and Value::stripPointerCasts() should
the call to CallBase::getCalledFunction return nullptr.

I don't know how to express the IR test case in C, otherwise I'd add a
clang test, too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142058

Files:
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/test/CodeGen/X86/attr-dontcall.ll


Index: llvm/test/CodeGen/X86/attr-dontcall.ll
===================================================================
--- llvm/test/CodeGen/X86/attr-dontcall.ll
+++ llvm/test/CodeGen/X86/attr-dontcall.ll
@@ -20,6 +20,14 @@
   ret void
 }
 
+declare void @foo4(i32) addrspace(1) "dontcall-warn"="cast"
+
+define void @bar4() {
+  call void addrspacecast (ptr addrspace(1) @foo4 to ptr)(i32 0)
+  ret void
+}
+
 ; CHECK: error: call to foo marked "dontcall-error": e
 ; CHECK: warning: call to foo2 marked "dontcall-warn": w
-; CHECK: warning: call to foo3 marked "dontcall-warn"{{$}}
+; CHECK: warning: call to foo3 marked "dontcall-warn"
+; CHECK: warning: call to foo4 marked "dontcall-warn": cast
Index: llvm/lib/IR/DiagnosticInfo.cpp
===================================================================
--- llvm/lib/IR/DiagnosticInfo.cpp
+++ llvm/lib/IR/DiagnosticInfo.cpp
@@ -416,7 +416,9 @@
 void OptimizationRemarkAnalysisAliasing::anchor() {}
 
 void llvm::diagnoseDontCall(const CallInst &CI) {
-  auto *F = CI.getCalledFunction();
+  const Function *F = CI.getCalledFunction();
+  if (!F)
+    F = dyn_cast<Function>(CI.getCalledOperand()->stripPointerCasts());
   if (!F)
     return;
 
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -8364,9 +8364,9 @@
     return;
   }
 
-  if (Function *F = I.getCalledFunction()) {
-    diagnoseDontCall(I);
+  diagnoseDontCall(I);
 
+  if (Function *F = I.getCalledFunction()) {
     if (F->isDeclaration()) {
       // Is this an LLVM intrinsic or a target-specific intrinsic?
       unsigned IID = F->getIntrinsicID();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142058.490285.patch
Type: text/x-patch
Size: 1765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230118/cee34462/attachment.bin>


More information about the llvm-commits mailing list