Author: Gábor Horváth Date: 2024-11-08T15:05:11Z New Revision: 8b29c05b73310bba3d7abd007dbbd839c46b0ab4
URL: https://github.com/llvm/llvm-project/commit/8b29c05b73310bba3d7abd007dbbd839c46b0ab4 DIFF: https://github.com/llvm/llvm-project/commit/8b29c05b73310bba3d7abd007dbbd839c46b0ab4.diff LOG: [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 <gab...@apple.com> Added: clang/test/Sema/attr-lifetimebound.c Modified: clang/include/clang/Basic/Attr.td Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 24cfb5ddb6d4ca..a631e81d40aa68 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1886,7 +1886,6 @@ def LifetimeBound : DeclOrTypeAttr { let Spellings = [Clang<"lifetimebound", 0>]; let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>; let Documentation = [LifetimeBoundDocs]; - let LangOpts = [CPlusPlus]; let SimpleHandler = 1; } diff --git a/clang/test/Sema/attr-lifetimebound.c b/clang/test/Sema/attr-lifetimebound.c new file mode 100644 index 00000000000000..e1c714cb27dc8b --- /dev/null +++ b/clang/test/Sema/attr-lifetimebound.c @@ -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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits