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

    <tr>
        <th>Summary</th>
        <td>
            [clang] [asan] PDB is missing variable when compiled with address sanitizer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    I noticed when debugging my program that sometimes variables would be unavailable to the debugger. I tried multiple debuggers, then inspected the PDB and noticed the variable was missing. I determined that disabling address sanitizer would cause the variable to return in the debug information. I subsequently whittled down my program to a small one that would reproduce the issue.

With the below program, the variable `memval` will be present in the PDB when compiled without address sanitizer, but not available when compiled with address sanitizer. I am using llvm 20.1.0 built from source, and I got the source from the github release.

`foo.c`:
```c
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

long
bar(char **ps, int *perr)
{
    return 0;
}

int
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    int err = 0;
    char *memval = "test";
    if (bar(&memval,&err)) return 0;
    return 0;
}
```
```sh
$ clang.exe foo.c -g -fsanitize=address -o foo.exe && llvm-pdbutil.exe dump -modi=0000 --symbols foo.pdb | grep memval && echo yay
$ clang.exe foo.c -g -o foo.exe && llvm-pdbutil.exe dump -modi=0000 --symbols foo.pdb | grep memval && echo yay
     512 | S_LOCAL [size = 20] `memval`
yay
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VU1v4zYQ_TX0ZWCDoizHPvgg2wlqIHEXzQJ7DChxLLGlSJUfVr2_viBlrZMNWvRUwIDF4Xy892Y04s7JRiNuSbEjxWHGg2-N3b5w-8cLaoFKzSojrtsjaONljQKGFjUIrELTSN1Ad4XemsbyDnzLPTjToZcdOrhwK3ml0MFgghJQIQTNL1yqaAVvwLd4y4R2AUf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