Skip to content

Commit

Permalink
Add test ClassMethods_arc.m
Browse files Browse the repository at this point in the history
  • Loading branch information
weliveindetail committed Sep 21, 2022
1 parent 5a4d095 commit c8cf72d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(TESTS
AssociatedObject2.m
BlockImpTest.m
BlockTest_arc.m
ClassMethods_arc.m
ConstantString.m
Category.m
ExceptionTest.m
Expand Down
46 changes: 46 additions & 0 deletions Test/ClassMethods_arc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#import "objc/runtime.h"

#if __has_attribute(objc_root_class)
__attribute__((objc_root_class))
#endif
@interface TestObj { id isa; }
+ (Class)class;
+ (id)testObj;
+ (const char *)testStr;
+ (int)testNum;
@end

@implementation TestObj
+ (Class)class {
return self;
}
+ (id)testObj {
id testObj = @"Test";
printf("returning testObj: 0x%p\n", testObj);
return testObj;
}
+ (const char *)testStr {
return "forty two";
}
+ (int)testNum {
return 42;
}
@end

int main() {
id testClass = [TestObj class];
printf("testClass: %s (%p)\n", class_getName(testClass), testClass);
TestObj *testObj = [TestObj testObj];
printf("testObj: 0x%p\n", testObj);
const char *testStr = [TestObj testStr];
printf("testStr: %s\n", testStr);
int testNum = [TestObj testNum];
printf("testNum: %d\n", testNum);

if (testObj) {
return 0;
} else {
return 1;
}
}

2 comments on commit c8cf72d

@weliveindetail
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was supposed to reproduce llvm/llvm-project#56952 Building with Clang Release 14 on Windows 10, however, appears to work:

C:\libobjc2\build\Test>cmake -GNinja -DCMAKE_C_COMPILER="C:/LLVM14/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="C:/LLVM14/bin/clang-cl.exe" ..
C:\libobjc2\build\Test>ninja Test\ClassMethods_arc.exe

C:\libobjc2\build\Test>ClassMethods_arc.exe
testClass: TestObj (00007FF6577568E0)
returning testObj: 0xA9979F4000000024
testObj: 0xA9979F4000000024
testStr: forty two
testNum: 42

C:\libobjc2\build\Test>ClassMethods_arc_optimised.exe
testClass: TestObj (00007FF7052068E0)
returning testObj: 0xA9979F4000000024
testObj: 0xA9979F4000000024
testStr: forty two
testNum: 42

C:\libobjc2\build>C:/LLVM14/bin/clang-cl.exe --version
### CCC_OVERRIDE_OPTIONS: "x-TC x-TP x/TC x/TP"
### Unrecognized edit: "x-TC
clang version 14.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM14\bin

@weliveindetail
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to reproduce the issue, we have to build libobjc itself in release mode! Now both variants, with and without optimizations, fail in the same way:

C:\libobjc2\build-release>cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="C:/LLVM14/bin/clang-cl.exe" -DCMAKE_CXX_COMPILER="C:/LLVM14/bin/clang-cl.exe" ..

C:\libobjc2\build-release>Test\ClassMethods_arc_optimised.exe
testClass: TestObj (00007FF771C158E0)
returning testObj: 0xA9979F4000000024
testObj: 0x0000000000000000
testStr: forty two
testNum: 42

C:\libobjc2\build-release>Test\ClassMethods_arc.exe
testClass: TestObj (00007FF7D49158E0)
returning testObj: 0xA9979F4000000024
testObj: 0x0000000000000000
testStr: forty two
testNum: 42

Please sign in to comment.