<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/69658>69658</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Regression(ed83797f3cbfc8): Behavior change in __weak in debug builds with -fno-objc-arc-exceptions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nico
      </td>
    </tr>
</table>

<pre>
    Phab is down, so I can't look, so I can't look at the discussion at https://reviews.llvm.org/D105671. Maybe this is intentional!

We noticed that ed83797f3cbfc8 changed the behavior of this code:

```
% cat test.mm
#import <Foundation/Foundation.h>

@class UILayoutGuide;

@interface LayoutGuideCenter : NSObject
- (UILayoutGuide * _Nonnull)makeLayoutGuideNamed:(NSString * _Nonnull)name;
@end

#define EXPECT_NE(a, b) if (a == b) return 1
#define EXPECT_EQ(a, b) if (a != b) return 2

int main() {
 LayoutGuideCenter* center_ = [[LayoutGuideCenter alloc] init];
 UILayoutGuide* layout_guide = [center_ makeLayoutGuideNamed:@"view"];

  EXPECT_NE(layout_guide, nil);

  // Create a weak reference to the layout guide, to check it gets nilled out.
  __weak UILayoutGuide* weak_layout_guide = layout_guide;

  @autoreleasepool {
    layout_guide = nil;
 }

  // This can fail if you are breaking in the debugger and inspecting the hash
  // table. This is due to NSHashTable not providing any guarantee as for when
  // the elements are released.
 EXPECT_EQ(weak_layout_guide, nil);
}
```

```
% cat center.mm
#import <Foundation/Foundation.h>

@interface UILayoutGuide : NSObject @end
@implementation UILayoutGuide @end

@interface LayoutGuideCenter : NSObject
- (UILayoutGuide * _Nonnull)makeLayoutGuideNamed:(NSString * _Nonnull)name;
@end

@implementation LayoutGuideCenter
- (UILayoutGuide * _Nonnull)makeLayoutGuideNamed:(NSString * _Nonnull)name
{
  return [[UILayoutGuide alloc] init];
}
@end
```

After the change, in non-optimized builds, this now exits with 2:

```
% third_party/llvm-build/Release+Asserts/bin/clang++  -isysroot $(xcrun -show-sdk-path) test.mm center.mm -fobjc-arc -fno-objc-arc-exceptions && ./a.out ; echo $?      
2
```

It exits with 0:
* when building with -O2
* when building without -fno-objc-arc-exceptions
* without ed83797f3cbfc8

Is this an intentional change? It seems surprising that it only changes in some build configs.

The code looks a little bit weird, but possibly ok to me.

@jroelofs
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVk1v4zYQ_TX0ZWBDomzLPvhgx3EboM1uNynam0GRI4lrihRIKl731xeU5ES2k_RQ9NAgCCJ-PM68mXkzzDlZaMQVmW3IbDtijS-NXWnJzSgz4rT6WrIMpANhjprQO3AGHoAzTWjqQRlzeHcRmAdfIgjpeOOcNDqslN7XjiRrQneE7iy-SDy6iVIv1cTYgtDdNo5m8zSewK_slCH4UrrwttQetZdGM0VoTKItidbd3z8QtPGSowBfMg8oFkm6TPOEZzlfAC-ZLto9hAxL9iKNBZN3wNwIDMYM4Mg86n-7TzoDHjxB5ydVdV5MZFUb64EkdzvTaMGCaYTu3j4mJUnuL4CnEVfMOfj94Rd2Mo3_qZHh9c3VoeCpzRlHGBy7w7AKJFnD49OX7Dty310YA6GLC0QgdA37R6N1oxShy4odcLD9yCoUbQAWj09P3kpdXN_QrBrYNY1QiwsbaSIwlxrh_s-v93fP-8d7QhcsJEFG6BJkHmxiQJItSbbdmkXfWA3xBwj3v72PQONrBDq0RGoPFZOa0EU4QtLe5lvmgoe8_W8f7II21Te3BDOlDCezLUgtPZltX2m4ihpdg2o_90XHeYd5fuIjzqcRoTSkPKF0iN6_cUHoED8wo2WIzc2VrpDgziLzCAyOyA5gMUeLmiN402Z-BwavYN4AL5EfQHoo0LuArlCAafzkjLzft1g3jofV_Y33F-beGDmNWOONRYXMYW2MGgQL4JbL4Owr9STdvuvzc1vCTEPOpApJczINMIuQWWSHkNhSdxKEWVMUIbxagNSuRu7DdtgrmSuvcD3LFE46-CB7TUvj49PPz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