[clang] Permit lifetimebound in all language modes (#115482)

Lifetimebound annotations can help diagnose common cases of dangling
including escaping the address of a stack variable from a function. This
is useful in all C family languages, restricting these diagnostics to
C++ is an artificial limitation.

Co-authored-by: Gabor Horvath <gaborh@apple.com>
This commit is contained in:
Gábor Horváth 2024-11-08 15:05:11 +00:00 committed by GitHub
parent 9aea667108
commit 8b29c05b73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -1886,7 +1886,6 @@ def LifetimeBound : DeclOrTypeAttr {
let Spellings = [Clang<"lifetimebound", 0>]; let Spellings = [Clang<"lifetimebound", 0>];
let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>; let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
let Documentation = [LifetimeBoundDocs]; let Documentation = [LifetimeBoundDocs];
let LangOpts = [CPlusPlus];
let SimpleHandler = 1; let SimpleHandler = 1;
} }

View File

@ -0,0 +1,8 @@
// RUN: %clang_cc1 -std=c99 -verify %s
int *f(int* p __attribute__((lifetimebound)));
int *g() {
int i;
return f(&i); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
}