Skip to content

Commit 8b29c05

Browse files
Xazax-hunGabor Horvath
andauthored
[clang] Permit lifetimebound in all language modes (llvm#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 <[email protected]>
1 parent 9aea667 commit 8b29c05

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,6 @@ def LifetimeBound : DeclOrTypeAttr {
18861886
let Spellings = [Clang<"lifetimebound", 0>];
18871887
let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
18881888
let Documentation = [LifetimeBoundDocs];
1889-
let LangOpts = [CPlusPlus];
18901889
let SimpleHandler = 1;
18911890
}
18921891

clang/test/Sema/attr-lifetimebound.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -std=c99 -verify %s
2+
3+
int *f(int* p __attribute__((lifetimebound)));
4+
5+
int *g() {
6+
int i;
7+
return f(&i); // expected-warning {{address of stack memory associated with local variable 'i' returned}}
8+
}

0 commit comments

Comments
 (0)