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

    <tr>
        <th>Summary</th>
        <td>
            [clang][BoundsSafety] Extend `-Wvla-potential-size-confusion` for struct fields and bounds annotations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            TBAA,
            clang:bounds-safety
      </td>
    </tr>

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

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

<pre>
    https://github.com/llvm/llvm-project/pull/129772

`-Wvla-potential-size-confusion` diagnoses when `n` references the file scope variable and not the parameter.

```
int n;
void func(int array[n], int n);
```

We may want to extend it to diagnose on situations mentioned in the PR:

- Diagnosing a similar situation in structures. e.g.,

```C
int n;
struct S {
  int n;
  int array[sizeof(n)]; // Refers to outer n, not member n
};
```

- Diagnosing with constant-size arrays (requires tracking the expression for the constant-size array in the `QualType`) e.g.,

```C
constexpr int n = 12;
void func(int array[n], int n);
```

- Potentially, also diagnosing with any ambiguous situations with bounds annotations like below (with or without the `-fexperimental-late-parse-attributes` flag: 

```
constexpr int n;
struct foo {
  int * ptr __counted_by(n);
  int n;
};
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVE2P2zYQ_TXUZSCDoix_HHSQ7fqcJgFyDEbSyGZDkSo_vOv--oKUtdnNLooWKCBAmOFwyPfm8aFz8qKJalYdmBAWJ9k7jUwIVp0yDP5qbL1ks9b09_rq_eRY2TBxZuJ8kf4a2lVnRibOSt2WXz5Z8wd1nonzFJRi4lyI_XYrGG_it-H5t5vCfDKetJeocif_orwzeghOGs02HHqJF20cOXi6kga24SltaSBLuiMH_kowSEXgOjMR3NBKbBUB6h608Wl9QosjebKrl6MfH2-k9qBZeWC8uRnZwxB0x8QuptFavLPqoFl1YuIIc6nYz9WvmzDefCMY8Q5PqD14A_TsSfcgU7CgAKPBSR_QS6MdjBG20dSD1Omenz5HTlO7HE7zJqkvgODkKBXan7vjFudt6Hyw5FZAq8uKieMv-I5vAc4b4AuwbQwBXq3NwQI5TsIMTOwS3urEygPMw4bPkXsXYZngyUZGjonpkcY2xbxh29OHJL1B9ST9FTqjnUft0-zn4x0wsbP0Z5A2ztdi9yOWR4LoebLkojhgMDalPmiw0Mk2_PeA6ut9ongDsf8HllKb2H7mBFh5gkL8D7rI4dOib3WP1ajciyJeaEB9BxxbeQkmuNcaSautCbp3gFob_8gr-YOgJWWeIlupythUbYJf0OcDPU9kZRQaqlyhp3xC6yhH761sgycXn9Og8MLKBt6_jl9oeSOjwZg3QmKigclb-P69M0F76r-390VB5Tu9vZdI1tdlvy_3mFFdbNdFITa82GXXet1t1ny75mWxL7As-33V7td9VbRFiR3tu0zWgouKl3wtBN9Uu1VbId-2ZT9UZdH2uGZrTiNKtYq2tDL2kknnAtXRj3ZlprAl5R7-1ynUkY3BGh3fcPRBcWRCfD00zUuwVM2jyR0O5O8Py7R1cr82XBxbcyWddz8P9tKrZLVzh-rEqsMhNfky96hO8NtsHv_KIeM7WAYiSSWZ9B8oJgtW_XffTjS5h3PvyuxWi78DAAD__1Y79co">