[clang] [clang-tools-extra] [Clang] Add support for the C `defer` TS (PR #162848)

Thiago Adams via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 15 08:53:46 PST 2025


thradams wrote:

Suggestion:
Consider this code:

```c
void f2(int i) {}
void f(int k) {
    int i;
    _Defer f2(i);
    if (k > 1) return; //defer executed
    if (k > 2) return; //defer executed
    i = 1;
} //defer executed
```

The warning using -Wall  is: (https://godbolt.org/z/3PKxMKMKM)

```
<source>:4:15: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
    4 |     _Defer f2(i);
      |               ^
<source>:3:10: note: initialize the variable 'i' to silence this warning
    3 |     int i;
      |          ^
      |           = 0
1 warning generated.
ASM generation compiler returned: 0
<source>:4:15: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
    4 |     _Defer f2(i);
      |               ^
<source>:3:10: note: initialize the variable 'i' to silence this warning
    3 |     int i;
      |          ^
      |           = 0
1 warning generated.
Execution build compiler returned: 0
Program returned: 0
```

My suggestion is to add a note identifying the defer execution that triggered the warning.(The return line)
In complicated code with multiple defer executions, this may be hard to find.







https://github.com/llvm/llvm-project/pull/162848


More information about the cfe-commits mailing list