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

    <tr>
        <th>Summary</th>
        <td>
            Extra unexpected stack frame in the backtrace of a C program on macos M1
        </td>
    </tr>

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

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

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

<pre>
    I'm not sure if this is the right place to report this, but looking at the clang and llvm website, I thought of raising it here.

Consider the following trivial code, which intentionally is written to generate a segmentation fault when the program is run. Line number 26 is where it intentionally writes to a uninitialized reference to trigger the crash. The program is compiled with `-g` flag with source level debug information enabled.

```c
#include <stdio.h>

struct Bar {
        int i;
};

typedef struct Bar Bar_t;

struct Foo {
        Bar_t **bar;
};

typedef struct Foo Foo_t;


void b() {
        printf("Entered b\n");
}

void a() {
        

        b();

        Foo_t *s = NULL;
        s->bar[0] = NULL;
}

int main() {
        printf("Entered main\n");
        a();
}
```
Compiled as follows:

```
cc -g -o test.o test.c
```
Then run as:
```
./test.o
```
When this is run on macos M1 system the program crashes and generates a crash report which contains the backtrace. The backtrace is what looks odd:

```
Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   crash.o 0x10052ff58 a + 24 (crash.c:26)
1   crash.o 0x10052ff50 a + 16 (crash.c:23)
2   crash.o 0x10052ff84 main + 24 (crash.c:31)
3   dyld 0x191aebe50 start + 2544
```
Notice the stack frame numbered `1` in that backtrace. I don't understand why that is listed in the backtrace. That line 23 represents a call to method `b()` from which the code flow has returned back and then moved to line 26 in method `a()`, which is where the crash occurs. So why is there that extra stack frame in the backtrace?
The macos M1 version and `cc` version is as follows:
```
$> sw_vers
ProductName:            macOS
ProductVersion:         13.0.1
BuildVersion:           22A400
```
```
$> cc --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
```
Just to be sure that I am not missing something obvious, I ran this same code on a Linux system (of course recompiling there first) and the backtrace I get there is what I would expect:

```
(gdb) bt
#0  0x00000000004005b5 in a () at test.c:26
#1  0x00000000004005da in main () at test.c:31
```
Linux and `cc` version where it works as expected is:
```
$> uname -a
Linux foo-bar 4.18.0-408.el8.x86_64 #1 SMP Mon Jul 18 17:42:52 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
```

```
$> cc --version
cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-17)
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUV92S4roRfhpx04VLljHgCy6YH07m1O7mVHY2udyS5TbWGVsikjzM5OlTLQELs67NydQUYKm__lF3f2pL7_XeIG5YecfKh5kcQ2fd5k-pX7STZlbb5n3zxMRqAGMD-NEh6BZCpz1oD6FDcHrfBTj0UiEECw4P1oUowcQ91GOA3toXbfYgQwSoXtKDaaDvXwc4Yu11QBJ-gtDZkdTZFpzUnlA6QIcOM8YfGN-mz3trvG7QRX2t7Xt7JNHg9KuWPSjbRH3HTqsOtAlogrZG9v07eX10OgQ05O0eDToZECR43A9ogiRJaOXYBzh2JNUhHJzdOzkQ2I0mg0_aIJhxqNGBWEad5CP5emuNTKEnSxJGo40OWvb6P9iAwxYdmnRowen9_hSOctJ3GTzfmlV2OOgeGzjq0AFb8vmeLTm0vdynJW9HpxB6fMUeGqzHPWjTWjekgNDIusfm5hTZkqd_dXoWhTaqHxsEVtz70Gibdax4vMb44EYV4E46YKu7806lTQDNivPC6uHH7_gZ3g_YYAtX8DvpvocPYqftnbU32qMoMLFlYltL99ftkKKdtT_ZSZ-vVjdQM7Fmorqxd3DahDZuiEcT0CHJlfeGCcFEdWP_oz45oe_WdHUy-ZNPVXSV4vTAigf48u3Tpyuhys9Z8Ujxl3eclQ8TMrf-UFIGqc1fjDCKTgTJK_nR4YudcwWd2_JUpNKfutKzYjtZculRKZjvYW4hoA_Z6UtNij5TL7rRgLzSeSuSMbFL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