Issue 56056
Summary [GNU ObjC] Clang 14 regression: access violation when building with ARC and optimization
Labels new issue
Assignees
Reporter triplef
    Building the following Objective-C code using using Automatic Reference Counting and the GNU Objective-C 2.0 runtime and `-O1` or better optimization using Clang 14.0.5 causes an access violation at runtime.

This does not happen with Clang 13.0.1, or when using `-O0`, or when not using ARC.

```objc
#import "objc/runtime.h"

__attribute__((objc_root_class))
@interface Test {
  id isa;
}
+ (id)new;
@end

@implementation Test
+ (id)new {
  return class_createInstance(self, 0);
}
@end

int main(void) {
  [Test new];
  return 0;
}
```

Building:
```
"C:\Program Files\LLVM-14\bin\clang" -IC:\libobjc2\include -LC:\libobjc2\lib -fobjc-runtime=gnustep-2.0 -fobjc-arc -fuse-ld=lld -lobjc -O2 -o test.exe test.m
```

Result:
```
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffb16aea405: Access violation reading location 0xffffffffffffffff
    frame #0: 0x00007ffb16aea405 objc.dll`objc_retain + 149
objc.dll`objc_retain:
->  0x7ffb16aea405 <+149>: movq   (%rax), %rcx
    0x7ffb16aea408 <+152>: movl   $0x4000, %edx             ; imm = 0x4000
    0x7ffb16aea40d <+157>: callq  0x7ffb16aeacb0            ; objc_storeWeak + 1472
    0x7ffb16aea412 <+162>: movl   %eax, 0x54(%rsp)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to