Files
TheRock/compiler/amd-llvm/clang/test/CodeGenObjC/expose-direct-method-linkedlist.m
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

99 lines
2.9 KiB
Objective-C

// RUN: %clang_cc1 -emit-llvm -fobjc-arc -fblocks -fobjc-runtime-has-weak \
// RUN: -triple arm64-apple-macos11.0 \
// RUN: -fobjc-direct-precondition-thunk %s -o - | FileCheck %s
#define nil ((id)0)
__attribute__((objc_root_class))
@interface LinkedList
@property(direct, readonly, nonatomic) int v;
@property(direct, strong, nonatomic) LinkedList* next;
@property(direct, readonly, nonatomic) int instanceId;
@property(strong, nonatomic, direct) void ( ^ printBlock )( void );
+ (instancetype)alloc;
- (instancetype)initWithV:(int)v Next:(id)next __attribute__((objc_direct));
- (instancetype)clone __attribute__((objc_direct));
- (void)print __attribute__((objc_direct));
- (instancetype) reverseWithPrev:(id) prev __attribute__((objc_direct));
- (int) size __attribute__((objc_direct));
- (int) sum __attribute__((objc_direct));
- (double) avg __attribute__((objc_direct));
- (int) sumWith:(LinkedList *) __attribute__((ns_consumed)) other __attribute__((objc_direct));
@end
@implementation LinkedList
static int numInstances=0;
- (instancetype)initWithV:(int)v Next:(id)next{
_v = v;
_next = next;
_instanceId = numInstances;
LinkedList* __weak weakSelf = self;
_printBlock = ^void(void) { [weakSelf print]; };
numInstances++;
return self;
}
- (instancetype) clone {
return [[LinkedList alloc] initWithV:self.v Next:[self.next clone]];
}
- (void) print {
[self.next print];
}
- (LinkedList*) reverseWithPrev:(LinkedList*) prev{
LinkedList* newHead = (self.next == nil) ? self : [self.next reverseWithPrev:self];
self.next = prev;
return newHead;
}
- (int) size {
return 1 + [self.next size];
}
- (int) sum {
return self.v + [self.next sum];
}
- (double) avg {
return (double)[self sum] / (double)[self size];
}
- (int) sumWith:(LinkedList *) __attribute__((ns_consumed)) other {
return [self sum] + [other sum];
}
@end
int main() {
// CHECK: call ptr @"-[LinkedList initWithV:Next:]D_thunk"
// CHECK: call ptr @"-[LinkedList initWithV:Next:]D_thunk"
LinkedList* ll = [[LinkedList alloc] initWithV:8 Next:[[LinkedList alloc] initWithV:7 Next:nil]];
// CHECK: call ptr @"-[LinkedList initWithV:Next:]D_thunk"
// CHECK: call ptr @"-[LinkedList next]D_thunk"
// CHECK: call void @"-[LinkedList setNext:]D_thunk"
ll.next.next = [[LinkedList alloc] initWithV:6 Next:nil];
// CHECK: call void @"-[LinkedList print]D_thunk"
[ll print];
// CHECK: call ptr @"-[LinkedList clone]D_thunk"
LinkedList* cloned = [ll clone];
// CHECK: call void @"-[LinkedList print]D_thunk"
[cloned print];
// CHECK: call ptr @"-[LinkedList printBlock]D_thunk"
cloned.printBlock();
// Test ns_consumed parameter with direct method thunk.
// CHECK: call i32 @"-[LinkedList sumWith:]D_thunk"
int combined = [ll sumWith:[cloned clone]];
// CHECK: call ptr @"-[LinkedList reverseWithPrev:]D_thunk"
ll = [ll reverseWithPrev:nil];
// CHECK: call void @"-[LinkedList print]D_thunk"
[ll print];
return 0;
}