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

    <tr>
        <th>Summary</th>
        <td>
            Unexpected sigbus error when trying to catch an exception in C++
        </td>
    </tr>

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

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

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

<pre>
    I have come across an interesting case, where C++ gives me a bus error, when I am trying to catch an exception.

The llvm version I used is
```
clang --version
Homebrew clang version 18.1.8
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
```

I already posted a stackoverflow question to this issue (https://stackoverflow.com/questions/78724605/c-sigbus-error-when-trying-to-catch-an-exception?noredirect=1#comment138800264_78724605)

The minimal example to reproduce the error is
```c++
#include <iostream>

using Vertex = std::vector<double>;

struct TestStruct {
    std::vector<Vertex> vertices;
};

void testFunction(TestStruct& set1, TestStruct& set2) {
    if (set1.vertices.front().size() != set2.vertices.front().size()) {
 throw std::invalid_argument("set1 has different dimensions (" +
 std::to_string(set1.vertices.front().size()) + ") than set2 (" +
 std::to_string(set2.vertices.front().size()) + ").");
 }
}

int main() {
    TestStruct set1;
    TestStruct set2;

    std::vector<Vertex> vertices1 = {{0.0, 0.0}};
 std::vector<Vertex> vertices2 = {{0.0, 0.0, 0.0}};

    set1.vertices = vertices1;
    set2.vertices = vertices2;

    try {
 testFunction(set1, set2);
    } catch (const std::invalid_argument& e) {
        std::cerr << "Exception: " << e.what() << std::endl;
 }
}
```

What I would expect here is that the code cathces the invalid_argument error and prints it. However, the actual output I get is:
`Process finished with exit code 138 (interrupted by signal 10:SIGBUS)`

The stack trace is 
```
(lldb) run
Process 16227 launched: '/Users/roland/Development/personal/minimal_example/build_arm_llvm/example' (arm64)
Process 16227 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=261, address=0xdac11410)
    frame #0: 0x000000018d12aa58 libunwind.dylib`_Unwind_GetIP + 224
libunwind.dylib`:
->  0x18d12aa58 <+224>: autib  x16, x0
    0x18d12aa5c <+228>: mov    x17, x16
 0x18d12aa60 <+232>: xpaci  x17
    0x18d12aa64 <+236>: cmp    x16, x17
Target 0: (example) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=261, address=0xdac11410)
  * frame #0: 0x000000018d12aa58 libunwind.dylib`_Unwind_GetIP + 224
    frame #1: 0x0000000180887c7c libc++abi.dylib`__gxx_personality_v0 + 588
    frame #2: 0x0000000100484930 libunwind.1.dylib`unwind_phase2 + 388
    frame #3: 0x0000000100484b68 libunwind.1.dylib`_Unwind_Resume + 100
    frame #4: 0x0000000100001ca4 example`testFunction(TestStruct&, TestStruct&) + 544
 frame #5: 0x0000000100001f80 example`main + 416
    frame #6: 0x000000018054d0e0 dyld`start + 2360
```


### Additional tests

I tested the exact same code with the following other compilers, and for all of them it produced the expected output.
arm64 gcc (version 14.1.0), arm64 apple clang (version 15.0.0), x86 gcc (version 13.2.0), x86 apple clang (version 15.0.0).

Therefore I suspect this to be an issue with llvm itself. But any help is appreciated, if you think the issue stems from anywhere else.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWE9z6riy_zTKpguXLBvbWbAI4TCT3dRkzntvR8lSg_VGtjySDGQ-_S3JxkDCPXMWd3FTVMBS96__St1t7pw6dIgrslyT5eaJD74xdvW70byT797ov59qIz9Wb9DwI4IwLQIX1jgHvAPVebTovOoOILhDwl7h1KBFeCVsTdgaDuqIDgIT1IMDtNbYiaqDN-AtePsR2L0Bwb1oAiyeBfZemS4hdEPoy_j_jwZB62MLR7ROmcA-OJSg3ERV0OkTH4Xm3QEWi4l6XPzVtFhbPMG4e0FKqyRNqkkMtwf0JHsBbtsiX_C-17iQ3J5Ux7KEJfSijkUuoTUSdaDujV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