llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

Use llvm.ptrmask instead of a ptrtoint + and + inttoptr sequence to mask out 
the thumb bit.

---
Full diff: https://github.com/llvm/llvm-project/pull/183535.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+3-7) 
- (modified) clang/test/CodeGen/ubsan-function-sugared.cpp (+1-3) 
- (modified) clang/test/CodeGen/ubsan-function.cpp (+1-3) 


``````````diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index fcadd1ec8b8be..2677b8a1fb3ff 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -6884,13 +6884,9 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
       // might be passed function pointers of both types.
       llvm::Value *AlignedCalleePtr;
       if (CGM.getTriple().isARM() || CGM.getTriple().isThumb()) {
-        llvm::Value *CalleeAddress =
-            Builder.CreatePtrToInt(CalleePtr, IntPtrTy);
-        llvm::Value *Mask = llvm::ConstantInt::getSigned(IntPtrTy, ~1);
-        llvm::Value *AlignedCalleeAddress =
-            Builder.CreateAnd(CalleeAddress, Mask);
-        AlignedCalleePtr =
-            Builder.CreateIntToPtr(AlignedCalleeAddress, CalleePtr->getType());
+        AlignedCalleePtr = Builder.CreateIntrinsic(
+            CalleePtr->getType(), llvm::Intrinsic::ptrmask,
+            {CalleePtr, llvm::ConstantInt::getSigned(IntPtrTy, ~1)});
       } else {
         AlignedCalleePtr = CalleePtr;
       }
diff --git a/clang/test/CodeGen/ubsan-function-sugared.cpp 
b/clang/test/CodeGen/ubsan-function-sugared.cpp
index 7eb37ca50c366..f097f7d5ca842 100644
--- a/clang/test/CodeGen/ubsan-function-sugared.cpp
+++ b/clang/test/CodeGen/ubsan-function-sugared.cpp
@@ -10,9 +10,7 @@ auto fun() {}
 
 // GNU-LABEL:  define{{.*}} void @_Z6callerv()
 // MSVC-LABEL: define{{.*}} void @"?caller@@YAXXZ"()
-// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !6
-// ARM:   and i32 {{.*}}, -2, !nosanitize !6
-// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !6
+// ARM:   call ptr @llvm.ptrmask.p0.i32(ptr {{.*}}, i32 -2), !nosanitize !6
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
 // CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
 // CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
diff --git a/clang/test/CodeGen/ubsan-function.cpp 
b/clang/test/CodeGen/ubsan-function.cpp
index 59f8d84d8c877..5d10d07bca519 100644
--- a/clang/test/CodeGen/ubsan-function.cpp
+++ b/clang/test/CodeGen/ubsan-function.cpp
@@ -13,9 +13,7 @@ void fun() {}
 
 // GNU-LABEL:  define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
 // MSVC-LABEL: define{{.*}} void @"?caller@@YAXP6AXXZ@Z"(ptr noundef %f)
-// ARM:   ptrtoint ptr {{.*}} to i32, !nosanitize !7
-// ARM:   and i32 {{.*}}, -2, !nosanitize !7
-// ARM:   inttoptr i32 {{.*}} to ptr, !nosanitize !7
+// ARM:   call ptr @llvm.ptrmask.p0.i32(ptr {{.*}}, i32 -2), !nosanitize !7
 // AUTH:  %[[STRIPPED:.*]] = ptrtoint ptr {{.*}} to i64, !nosanitize
 // AUTH:  call i64 @llvm.ptrauth.auth(i64 %[[STRIPPED]], i32 0, i64 0), 
!nosanitize
 // CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize

``````````

</details>


https://github.com/llvm/llvm-project/pull/183535
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to