llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LifetimeSafety] Enable lifetime analysis for C language

Open NeKon69 opened this issue 5 months ago • 2 comments

Clang lifetime safety analysis currently does not run for C code.

It would be useful to support C as well, at least for primitive objects and C-compatible attribute spelling such as __attribute__((lifetimebound)).

Example:

int *id(int *p __attribute__((lifetimebound))) {
  return p;
}

int *bad(void) {
  int local;
  return id(&local);
}

Expected result: enabling lifetime safety warnings in C mode should diagnose cases where a pointer to a local object escapes its lifetime.

NeKon69 avatar Jun 11 '26 09:06 NeKon69

@llvm/issue-subscribers-clang-temporal-safety

Author: NeKon69

Clang lifetime safety analysis currently does not run for C code.

It would be useful to support C as well, at least for primitive objects and C-compatible attribute spelling such as __attribute__((lifetimebound)).

Example:

int *id(int *p __attribute__((lifetimebound))) {
  return p;
}

int *bad(void) {
  int local;
  return id(&local);
}

Expected result: enabling lifetime safety warnings in C mode should diagnose cases where a pointer to a local object escapes its lifetime.

Reopened this as the PR was reverted.

NeKon69 avatar Jun 18 '26 03:06 NeKon69