diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -8369,9 +8369,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(); diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp --- a/llvm/lib/IR/DiagnosticInfo.cpp +++ b/llvm/lib/IR/DiagnosticInfo.cpp @@ -416,7 +416,9 @@ void OptimizationRemarkAnalysisAliasing::anchor() {} void llvm::diagnoseDontCall(const CallInst &CI) { - auto *F = CI.getCalledFunction(); + const auto *F = + dyn_cast(CI.getCalledOperand()->stripPointerCasts()); + if (!F) return; diff --git a/llvm/test/CodeGen/X86/attr-dontcall.ll b/llvm/test/CodeGen/X86/attr-dontcall.ll --- a/llvm/test/CodeGen/X86/attr-dontcall.ll +++ b/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 foo4 marked "dontcall-warn": cast