[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-10-06 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

LGTM after fixing the assertion ✅


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-10-03 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added a comment.

In D131424#3828656 , @mwyman wrote:

> In D131424#3828647 , @ahatanak 
> wrote:
>
>> `-fobjc-arc` is needed to see the assertion fail.
>
> Oops, yep I'll send a patch.

Sent https://reviews.llvm.org/D135091


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-30 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added a comment.

In D131424#3828647 , @ahatanak wrote:

> `-fobjc-arc` is needed to see the assertion fail.

Oops, yep I'll send a patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

`-fobjc-arc` is needed to see the assertion fail.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

It looks like this patch causes an assertion to fail (`Assertion failed: (it != 
LocalDeclMap.end() && "Invalid argument to GetAddrOfLocalVar(), no decl!")`) 
when the following code is compiled.

  __attribute__((objc_direct_members))
  @interface C
  @property id prop;
  -(void)m0;
  @end
  
  @implementation C
  -(void)m0 {
  }
  @end

Do we need to synthesize `_cmd` in `generateObjCGetterBody` and 
`generateObjCSetterBody` if the property is direct too?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-21 Thread Michael Wyman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa4bcaab9600: Remove the unused/undefined `_cmd` parameter 
in `objc_direct` methods. (authored by mwyman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/direct-method.m

Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -28,9 +28,7 @@
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[RETVAL:%.*]] = alloca
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -60,9 +58,7 @@
   // loading parameters
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca i8*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store i8* %{{.*}}, i8** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // [self self]
   // CHECK-NEXT: [[SELF:%.*]] = load i8*, i8** [[SELFADDR]],
@@ -81,9 +77,7 @@
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[RETVAL:%.*]] = alloca
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -125,9 +119,7 @@
   // loading parameters
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -159,6 +151,19 @@
   // CHECK: ret void
 }
 
+// CHECK-LABEL: define hidden void @"\01-[Root accessCmd]"(
+- (void)accessCmd __attribute__((objc_direct)) {
+  // CHECK-LABEL: entry:
+  // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
+  // CHECK-NEXT: [[CMDVAL:%_cmd]] = alloca i8*,
+
+  // loading the _cmd selector
+  // CHECK-LABEL: objc_direct_method.cont:
+  // CHECK-NEXT: [[CMD1:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+  // CHECK-NEXT: store i8* [[CMD1]], i8** [[CMDVAL]],
+  SEL sel = _cmd;
+}
+
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
@@ -205,19 +210,19 @@
 
 int useRoot(Root *r) {
   // CHECK-LABEL: define{{.*}} i32 @useRoot
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root getInt]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty2]"
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root getInt]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty2]" to i32 (i8*)
   return [r getInt] + [r intProperty] + [r intProperty2];
 }
 
 int useFoo(Foo *f) {
   // CHECK-LABEL: define{{.*}} i32 @useFoo
-  // CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInExtension]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategory]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategoryNoDecl]"
+  // CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]" to void (i8*, i32)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInExtension]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategory]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategoryNoDecl]" to i32 (i8*)
   [f setGetDynamic_setDirect:1];
   return [f getDirect_setDynamic] +
  [f directMethodInExtension] +
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2145,7 +2145,8 @@
   if (!IsSuper)
 Arg0 = CGF.Builder.CreateBitCast(Arg0, ObjCTypes.ObjectPtrTy);
   ActualArgs.add(RValue::get(Arg0), Arg0Ty);
-  ActualArgs.add(RValue::get(SelValue), selTy);
+  if (!Method || !Method->isDirectMethod())
+ActualArgs.add(RValue::get(SelValue), selTy);
   

[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak accepted this revision.
ahatanak added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-20 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D131424#3803190 , @mwyman wrote:

> Hi Akira,
>
> I'd reached out to John offline and he'd mentioned you might be able to help 
> on some of these objc_direct reviews; if so, that would be wonderful!
>
> -Michael

I would also be open to review for https://reviews.llvm.org/D86049 Akira.

-Puyan


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-20 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added a reviewer: ahatanak.
mwyman added a comment.

Hi Akira,

I'd reached out to John offline and he'd mentioned you might be able to help on 
some of these objc_direct reviews; if so, that would be wonderful!

-Michael


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-09-07 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added a comment.

This is related to changes for https://reviews.llvm.org/D86049.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-08-08 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 451051.
mwyman added a comment.

Fixed assert due to mis-matched number of expected parameters.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/direct-method.m

Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -28,9 +28,7 @@
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[RETVAL:%.*]] = alloca
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -60,9 +58,7 @@
   // loading parameters
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca i8*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store i8* %{{.*}}, i8** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // [self self]
   // CHECK-NEXT: [[SELF:%.*]] = load i8*, i8** [[SELFADDR]],
@@ -81,9 +77,7 @@
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[RETVAL:%.*]] = alloca
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -125,9 +119,7 @@
   // loading parameters
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -159,6 +151,19 @@
   // CHECK: ret void
 }
 
+// CHECK-LABEL: define hidden void @"\01-[Root accessCmd]"(
+- (void)accessCmd __attribute__((objc_direct)) {
+  // CHECK-LABEL: entry:
+  // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
+  // CHECK-NEXT: [[CMDVAL:%_cmd]] = alloca i8*,
+
+  // loading the _cmd selector
+  // CHECK-LABEL: objc_direct_method.cont:
+  // CHECK-NEXT: [[CMD1:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+  // CHECK-NEXT: store i8* [[CMD1]], i8** [[CMDVAL]],
+  SEL sel = _cmd;
+}
+
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
@@ -205,19 +210,19 @@
 
 int useRoot(Root *r) {
   // CHECK-LABEL: define{{.*}} i32 @useRoot
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root getInt]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty2]"
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root getInt]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty2]" to i32 (i8*)
   return [r getInt] + [r intProperty] + [r intProperty2];
 }
 
 int useFoo(Foo *f) {
   // CHECK-LABEL: define{{.*}} i32 @useFoo
-  // CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInExtension]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategory]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategoryNoDecl]"
+  // CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]" to void (i8*, i32)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInExtension]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategory]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategoryNoDecl]" to i32 (i8*)
   [f setGetDynamic_setDirect:1];
   return [f getDirect_setDynamic] +
  [f directMethodInExtension] +
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -2145,7 +2145,8 @@
   if (!IsSuper)
 Arg0 = CGF.Builder.CreateBitCast(Arg0, ObjCTypes.ObjectPtrTy);
   ActualArgs.add(RValue::get(Arg0), Arg0Ty);
-  ActualArgs.add(RValue::get(SelValue), selTy);
+  if (!Method || !Method->isDirectMethod())
+ActualArgs.add(RValue::get(SelValue), selTy);
   ActualArgs.addFrom(CallArgs);
 
   // If we're calling a method, use the formal signature.
@@ -4103,6 +4104,9 @@
 
   // 

[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-08-08 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

Updated D86049 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-08-08 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:487
   SmallVector argTys;
   SmallVector extParamInfos(2);
   argTys.push_back(Context.getCanonicalParamType(receiverType));

In order to fix the assert try this instead on line 487:

```
  SmallVector extParamInfos(
  MD->isDirectMethod() ? 1 : 2);
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-08-08 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

I tried running the following on some example code and got a stacktrace:

  // RUN: clang -cc1 -no-opaque-pointers -emit-llvm -fobjc-arc -triple 
x86_64-apple-darwin10 -o - %s  -O0
  
  @interface C
  - (int)getInt __attribute__((objc_direct));
  @end
  
  @implementation C
  - (int)getInt __attribute__((objc_direct)) {
  }
  @end
  
  void f() {
C *c;
[c getInt];
  }



  7  clang-16 0x0001054ee160 
clang::CodeGen::CGFunctionInfo::create(unsigned int, bool, bool, 
clang::FunctionType::ExtInfo const&, 
llvm::ArrayRef, 
clang::CanQual, llvm::ArrayRef>, 
clang::CodeGen::RequiredArgs) (.cold.2) + 0
  8  clang-16 0x00010291f50c 
clang::CodeGen::CGFunctionInfo::create(unsigned int, bool, bool, 
clang::FunctionType::ExtInfo const&, 
llvm::ArrayRef, 
clang::CanQual, llvm::ArrayRef>, 
clang::CodeGen::RequiredArgs) + 608
  9  clang-16 0x00010291b390 
clang::CodeGen::CodeGenTypes::arrangeLLVMFunctionInfo(clang::CanQual,
 bool, bool, llvm::ArrayRef>, 
clang::FunctionType::ExtInfo, 
llvm::ArrayRef, 
clang::CodeGen::RequiredArgs) + 568
  10 clang-16 0x00010291d24c 
clang::CodeGen::CodeGenTypes::arrangeObjCMessageSendSignature(clang::ObjCMethodDecl
 const*, clang::QualType) + 760
  11 clang-16 0x000102a45844 (anonymous 
namespace)::CGObjCCommonMac::GenerateDirectMethod(clang::ObjCMethodDecl const*, 
clang::ObjCContainerDecl const*) + 320
  12 clang-16 0x000102a3e044 (anonymous 
namespace)::CGObjCCommonMac::GenerateMethod(clang::ObjCMethodDecl const*, 
clang::ObjCContainerDecl const*) + 56
  13 clang-16 0x000102a13674 
clang::CodeGen::CodeGenFunction::StartObjCMethod(clang::ObjCMethodDecl const*, 
clang::ObjCContainerDecl const*) + 176
  14 clang-16 0x000102a13b2c 
clang::CodeGen::CodeGenFunction::GenerateObjCMethod(clang::ObjCMethodDecl 
const*) + 68


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131424/new/

https://reviews.llvm.org/D131424

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131424: Remove the unused/undefined _cmd parameter to objc_direct methods.

2022-08-08 Thread Michael Wyman via Phabricator via cfe-commits
mwyman created this revision.
mwyman added reviewers: dmaclach, plotfi.
mwyman added a project: clang.
Herald added a project: All.
mwyman requested review of this revision.
Herald added a subscriber: cfe-commits.

When `objc_direct` methods were implemented, the implicit `_cmd` parameter was 
left as an argument to the method implementation function, but was unset by 
callers; if the method body referenced the `_cmd` variable, a selector load 
would be emitted inside the body. However, this leaves an unused argument in 
the ABI, and is unnecessary.

This change removes the empty/unset argument, and if `_cmd` is referenced 
inside an `objc_direct` method it will emit local storage for the implicit 
variable. From the ABI perspective, `objc_direct` methods will have the 
implicit `self` parameter, immediately followed by whatever explicit arguments 
are defined on the method, rather than having one unset/undefined register in 
the middle.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131424

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/direct-method.m

Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -28,9 +28,7 @@
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[RETVAL:%.*]] = alloca
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -60,9 +58,7 @@
   // loading parameters
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca i8*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store i8* %{{.*}}, i8** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // [self self]
   // CHECK-NEXT: [[SELF:%.*]] = load i8*, i8** [[SELFADDR]],
@@ -81,9 +77,7 @@
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[RETVAL:%.*]] = alloca
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -125,9 +119,7 @@
   // loading parameters
   // CHECK-LABEL: entry:
   // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
-  // CHECK-NEXT: [[_CMDADDR:%.*]] = alloca i8*,
   // CHECK-NEXT: store %0* %{{.*}}, %0** [[SELFADDR]],
-  // CHECK-NEXT: store i8* %{{.*}}, i8** [[_CMDADDR]],
 
   // self nil-check
   // CHECK-NEXT: [[SELF:%.*]] = load %0*, %0** [[SELFADDR]],
@@ -159,6 +151,19 @@
   // CHECK: ret void
 }
 
+// CHECK-LABEL: define hidden void @"\01-[Root accessCmd]"(
+- (void)accessCmd __attribute__((objc_direct)) {
+  // CHECK-LABEL: entry:
+  // CHECK-NEXT: [[SELFADDR:%.*]] = alloca %0*,
+  // CHECK-NEXT: [[CMDVAL:%_cmd]] = alloca i8*,
+
+  // loading the _cmd selector
+  // CHECK-LABEL: objc_direct_method.cont:
+  // CHECK-NEXT: [[CMD1:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+  // CHECK-NEXT: store i8* [[CMD1]], i8** [[CMDVAL]],
+  SEL sel = _cmd;
+}
+
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
@@ -205,19 +210,19 @@
 
 int useRoot(Root *r) {
   // CHECK-LABEL: define{{.*}} i32 @useRoot
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root getInt]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty2]"
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root getInt]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Root intProperty2]" to i32 (i8*)
   return [r getInt] + [r intProperty] + [r intProperty2];
 }
 
 int useFoo(Foo *f) {
   // CHECK-LABEL: define{{.*}} i32 @useFoo
-  // CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInExtension]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategory]"
-  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategoryNoDecl]"
+  // CHECK: call void bitcast {{.*}} @"\01-[Foo setGetDynamic_setDirect:]" to void (i8*, i32)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo getDirect_setDynamic]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInExtension]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} = call i32 bitcast {{.*}} @"\01-[Foo directMethodInCategory]" to i32 (i8*)
+  // CHECK: %{{[^ ]*}} =