llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jonas Paulsson (JonPsson1)

<details>
<summary>Changes</summary>

Add extension attributes in declarations of _Block_object_dispose and 
_Block_object_assign.

In order to make this one-liners wherever needed, a new casting method 
FunctionCallee::getAsFunction() has been added.

A problem is that it seems theoretically possible that the created Function is 
any other named Value in the module... Would it be ok to have the cast fail in 
such a case?

I realize this is not the approach you had in mind, but it would at least be 
nice to hear the reasoning as to why something more elaborate would be 
preferred?

Please help with the signedness for the _Block_object_dispose argument, which I 
have no clue about.

@<!-- -->efriedma-quic @<!-- -->nikic 


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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBlocks.cpp (+3) 
- (modified) llvm/include/llvm/IR/DerivedTypes.h (+3) 
- (modified) llvm/lib/IR/Type.cpp (+8) 


``````````diff
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 684fda74407313..0f71163b565d6e 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -2842,6 +2842,8 @@ llvm::FunctionCallee 
CodeGenModule::getBlockObjectDispose() {
   llvm::FunctionType *fty
     = llvm::FunctionType::get(VoidTy, args, false);
   BlockObjectDispose = CreateRuntimeFunction(fty, "_Block_object_dispose");
+  // FIXME: Correct signedness of extension??
+  BlockObjectDispose.getAsFunction()->addParamAttr(1, llvm::Attribute::SExt);
   configureBlocksRuntimeObject(
       *this, cast<llvm::Constant>(BlockObjectDispose.getCallee()));
   return BlockObjectDispose;
@@ -2855,6 +2857,7 @@ llvm::FunctionCallee 
CodeGenModule::getBlockObjectAssign() {
   llvm::FunctionType *fty
     = llvm::FunctionType::get(VoidTy, args, false);
   BlockObjectAssign = CreateRuntimeFunction(fty, "_Block_object_assign");
+  BlockObjectAssign.getAsFunction()->addParamAttr(2, llvm::Attribute::SExt);
   configureBlocksRuntimeObject(
       *this, cast<llvm::Constant>(BlockObjectAssign.getCallee()));
   return BlockObjectAssign;
diff --git a/llvm/include/llvm/IR/DerivedTypes.h 
b/llvm/include/llvm/IR/DerivedTypes.h
index a24801d8bdf834..efacca6d773abf 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -29,6 +29,7 @@
 
 namespace llvm {
 
+class Function;
 class Value;
 class APInt;
 class LLVMContext;
@@ -189,6 +190,8 @@ class FunctionCallee {
 
   explicit operator bool() { return Callee; }
 
+  Function *getAsFunction();
+
 private:
   FunctionType *FnTy = nullptr;
   Value *Callee = nullptr;
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index f618263f79c313..2252e4fb39fc6a 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -361,6 +361,14 @@ bool FunctionType::isValidArgumentType(Type *ArgTy) {
   return ArgTy->isFirstClassType();
 }
 
+//===----------------------------------------------------------------------===//
+//                       FunctionCallee Implementation
+//===----------------------------------------------------------------------===//
+
+Function* FunctionCallee::getAsFunction() {
+  return cast<llvm::Function>(Callee);
+}
+
 
//===----------------------------------------------------------------------===//
 //                       StructType Implementation
 
//===----------------------------------------------------------------------===//

``````````

</details>


https://github.com/llvm/llvm-project/pull/111740
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to