[llvm] def2042 - [llvm][DiagnosticInfo] handle function pointer casts
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 13:59:46 PST 2023
Author: Nick Desaulniers
Date: 2023-01-24T13:59:34-08:00
New Revision: def20427b401a839210ff27b34dd31b929fa82ef
URL: https://github.com/llvm/llvm-project/commit/def20427b401a839210ff27b34dd31b929fa82ef
DIFF: https://github.com/llvm/llvm-project/commit/def20427b401a839210ff27b34dd31b929fa82ef.diff
LOG: [llvm][DiagnosticInfo] handle function pointer casts
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.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D142058
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/DiagnosticInfo.cpp
llvm/test/CodeGen/X86/attr-dontcall.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 84e1a397d3a2..0bdfdac6a65f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -8369,9 +8369,9 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
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
index aed38b6927bd..fb238e2aac59 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -416,7 +416,9 @@ void OptimizationRemarkAnalysisFPCommute::anchor() {}
void OptimizationRemarkAnalysisAliasing::anchor() {}
void llvm::diagnoseDontCall(const CallInst &CI) {
- auto *F = CI.getCalledFunction();
+ const auto *F =
+ dyn_cast<Function>(CI.getCalledOperand()->stripPointerCasts());
+
if (!F)
return;
diff --git a/llvm/test/CodeGen/X86/attr-dontcall.ll b/llvm/test/CodeGen/X86/attr-dontcall.ll
index 4c2595f7d4ee..8b518aee6dce 100644
--- a/llvm/test/CodeGen/X86/attr-dontcall.ll
+++ b/llvm/test/CodeGen/X86/attr-dontcall.ll
@@ -20,6 +20,14 @@ define void @bar3() {
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
More information about the llvm-commits
mailing list