[llvm] e3d87fd - [IR][IPSCCP] Treat different function type as address taken (PR54258)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 01:46:58 PST 2022


Author: Nikita Popov
Date: 2022-03-09T10:46:51+01:00
New Revision: e3d87fd6e5a829d22c29db32679998bf818f526f

URL: https://github.com/llvm/llvm-project/commit/e3d87fd6e5a829d22c29db32679998bf818f526f
DIFF: https://github.com/llvm/llvm-project/commit/e3d87fd6e5a829d22c29db32679998bf818f526f.diff

LOG: [IR][IPSCCP] Treat different function type as address taken (PR54258)

Without opaque pointers, this code currently treats a call through
a bitcast as the function being address taken, and IPSCCP relies
on this for correctness. Match the same behavior under opaque
pointers by checking that the function types are the same.

Fixes https://github.com/llvm/llvm-project/issues/54258.

Added: 
    

Modified: 
    llvm/lib/IR/Function.cpp
    llvm/test/Transforms/SCCP/opaque-ptr.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 6ae3d0b4dcb94..fa0fd5ead2b42 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -1803,7 +1803,7 @@ bool Function::hasAddressTaken(const User **PutOffender,
         *PutOffender = FU;
       return true;
     }
-    if (!Call->isCallee(&U)) {
+    if (!Call->isCallee(&U) || Call->getFunctionType() != getFunctionType()) {
       if (IgnoreARCAttachedCall &&
           Call->isOperandBundleOfType(LLVMContext::OB_clang_arc_attachedcall,
                                       U.getOperandNo()))

diff  --git a/llvm/test/Transforms/SCCP/opaque-ptr.ll b/llvm/test/Transforms/SCCP/opaque-ptr.ll
index 9306ec397cf0e..f2d717831ca98 100644
--- a/llvm/test/Transforms/SCCP/opaque-ptr.ll
+++ b/llvm/test/Transforms/SCCP/opaque-ptr.ll
@@ -21,3 +21,19 @@ define void @test2() {
   store i8 2, ptr @g2
   ret void
 }
+
+define internal i32 @test4() {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT:    ret i32 42
+;
+  ret i32 42
+}
+
+define i64 @test3() {
+; CHECK-LABEL: @test3(
+; CHECK-NEXT:    [[CALL:%.*]] = call i64 @test4()
+; CHECK-NEXT:    ret i64 [[CALL]]
+;
+  %call = call i64 @test4()
+  ret i64 %call
+}


        


More information about the llvm-commits mailing list