[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-10 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106321 >From b17b93dc917077cb588befde683a621e096c4f85 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 15 Aug 2024 16:33:04 -0700 Subject: [PATCH] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on po

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
delcypher wrote: @Sirraide Apologies for taking so long to get back to this PR. I think I've addressed all your feedback now. Is this ok to land now? https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106321 >From e10de17bf7e56cfe50c144e82396851a47ceead5 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 15 Aug 2024 16:33:04 -0700 Subject: [PATCH] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on po

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-09 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-08 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-08 Thread Dan Liew via cfe-commits
@@ -186,4 +218,188 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-04-08 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106321 >From f5b291e55859265c227427d0d630f8f698320a84 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 15 Aug 2024 16:33:04 -0700 Subject: [PATCH] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on po

[clang] Ubsan: warn on -fsanitize-trap=undefined ignored when passed on its own (PR #132319)

2025-03-24 Thread Dan Liew via cfe-commits
delcypher wrote: @MaskRay So this is actually part of [my GSoc proposal](https://discourse.llvm.org/t/clang-gsoc-2025-usability-improvements-for-trapping-undefined-behavior-sanitizer/84568/15?u=dan_liew). There's an explanation in the discord post about why I believe it's the wrong behavior. I

[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

2025-02-26 Thread Dan Liew via cfe-commits
@@ -8663,31 +8663,95 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) { return RD; } -static bool -CheckCountExpr(Sema &S, FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl &Decls) { +enum class CountedByInvalidPointeeTypeKind {

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
@@ -0,0 +1,87 @@ +== +Adoption Guide for ``-fbounds-safety`` +== + +.. contents:: + :local: + +Where to get ``-fbounds-safety`` + + +The open sourcing to llvm.org's ``llvm-pro

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher requested changes to this pull request. Seems reasonable and something we can expand on. The main issue is the fact `-fbounds-safety` is a cc1 option while this doc is written assuming its a driver option. https://github.com/llvm/llvm-project/pull/120674 __

[clang] [BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (PR #120674)

2025-01-15 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/120674 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
delcypher wrote: [This comment](https://github.com/llvm/llvm-project/pull/106321/files#r1906005324) is not showing up in the conversation view for some reason. https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
delcypher wrote: @erichkeane @AaronBallman @Sirraide I've addressed everything I can. I seem to be running into a problem where some of my replies to comments are not showing up in the conversation tab. This seems to be a [known problem with GitHub reviews ](https://github.com/orgs/community

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -19,13 +19,12 @@ struct on_member_pointer_complete_ty { }; struct on_member_pointer_incomplete_ty { - struct size_unknown * buf __counted_by(count); // expected-error{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct size_unknown'

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -8207,6 +8207,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-08 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling +// of the attri

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling +// of the attri

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
delcypher wrote: @Sirraide Thanks for your review and sorry for the delay in getting back to this. I've tried to address as much as possible and left comment on things that still need discussion. Please take a look when time permits. https://github.com/llvm/llvm-project/pull/106321 ___

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher deleted https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -13559,6 +13562,27 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, QualType LHSType = LHSExpr->getType(); QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : CompoundType; + + if (RHS.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -19,13 +19,12 @@ struct on_member_pointer_complete_ty { }; struct on_member_pointer_incomplete_ty { - struct size_unknown * buf __counted_by(count); // expected-error{{'counted_by' cannot be applied to a pointer with pointee of unknown size because 'struct size_unknown'

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -13559,6 +13562,27 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, QualType LHSType = LHSExpr->getType(); QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : CompoundType; + + if (RHS.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,206 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +static void EmitIncompleteCountedByPointeeNotes(Sema &S, +const CountAttributedType *CATy, +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -102,7 +105,36 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, // only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable // when `FieldTy->isArrayType()`. bool ShouldWarn = false; - if (PointeeTy->isIncompleteType()

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -3907,6 +3923,31 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::getAttributeName(bool WithMacroPrefix) const { +// TODO: This method isn't really ideal because it doesn't return the spelling +// of the attri

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -2068,13 +2068,55 @@ class Sema final : public SemaBase { bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, bool OrNull); + /// Perform Bounds Safety Semantic checks for assigning to a `__counted_by` or + /// `__

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -8238,6 +8246,15 @@ ExprResult InitializationSequence::Perform(Sema &S, } } + // Note the return value isn't used to return early so that additional + // diagnostics can be emitted and to preserve the AST as best as possible + // even though an

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -8192,6 +8192,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -0,0 +1,584 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +// =

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -8207,6 +8207,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // This is an approximation that's not quite right. This points to the +

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2025-01-07 Thread Dan Liew via cfe-commits
@@ -2440,6 +2440,26 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { return !isFunctionType(); } + /// \returns True if the type is incomplete and it is also a type that + /// cannot be completed by a later type definition. + /// + /// E.g. For

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits
@@ -8238,6 +8246,15 @@ ExprResult InitializationSequence::Perform(Sema &S, } } + // Note the return value isn't used to return early so that additional + // diagnostics can be emitted and to preserve the AST as best as possible + // even though an

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // Note: This implementation relies on `CountAttributedType` being uniqu

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-25 Thread Dan Liew via cfe-commits
@@ -2438,6 +2438,22 @@ bool Type::isIncompleteType(NamedDecl **Def) const { } } +bool Type::isIncompletableIncompleteType() const { + if (!isIncompleteType()) +return false; + + // Forward declarations of structs, classes, enums, and unions could be later + // complet

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits
@@ -3343,6 +3363,8 @@ class CountAttributedType final static bool classof(const Type *T) { return T->getTypeClass() == CountAttributed; } + + StringRef GetAttributeName(bool WithMacroPrefix) const; delcypher wrote: I filed #113585 to track fixing this

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // Note: This implementation relies on `CountAttributedType` being uniqu

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { delcypher wrote: I've dropped the hacky implementation in

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits
@@ -13559,6 +13562,27 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, QualType LHSType = LHSExpr->getType(); QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : CompoundType; + + if (RHS.

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits
delcypher wrote: @Sirraide @erichkeane Sorry for the delay in addressing your feedback. This PR is ready for another round of reviews. Note I'm aware there are some code formatting problems. I'll fix them when I squash locally. I've tried to keep all my tweaks as separate commits so it's easi

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits
@@ -3862,6 +3878,27 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::GetAttributeName(bool WithMacroPrefix) const { delcypher wrote: I've filed #113585 to track fixing the properly. I don't thin

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-23 Thread Dan Liew via cfe-commits
@@ -13559,6 +13562,27 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS, QualType LHSType = LHSExpr->getType(); QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : CompoundType; + + if (RHS.

[clang] [Parser][BoundsSafety] Print attribute as macro if it's system defined (PR #107619)

2024-09-10 Thread Dan Liew via cfe-commits
@@ -5080,6 +5083,17 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr, nullptr, SourceLocation(), ParsedAttr::Form::GNU(), nullptr); + const auto &SM = P

[clang] [Parser][BoundsSafety] Print attribute as macro if it's system defined (PR #107619)

2024-09-10 Thread Dan Liew via cfe-commits
@@ -5080,6 +5083,17 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr, nullptr, SourceLocation(), ParsedAttr::Form::GNU(), nullptr); + const auto &SM = P

[clang] [Parser][BoundsSafety] Print attribute as macro if it's system defined (PR #107619)

2024-09-10 Thread Dan Liew via cfe-commits
@@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -Wthread-safety %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -Wthread-safety -std=c++98 %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -Wthread-safety -std=c++11 %s -D C

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-29 Thread Dan Liew via cfe-commits
https://github.com/delcypher closed https://github.com/llvm/llvm-project/pull/106453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-29 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-29 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106453 >From 5497f530a717ff302deb85fc30ff75e59dba Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Thu, 29 Aug 2024 11:48:12 -0700 Subject: [PATCH] [NFC][Sema] Move Sema::AssignmentAction into its own scoped enum

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-29 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106453 >From 54a5f90ce219aad942074d78d986d24d6690b30c Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 28 Aug 2024 13:44:44 -0700 Subject: [PATCH 1/6] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-29 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106453 >From 54a5f90ce219aad942074d78d986d24d6690b30c Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 28 Aug 2024 13:44:44 -0700 Subject: [PATCH 1/4] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-29 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106453 >From 54a5f90ce219aad942074d78d986d24d6690b30c Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 28 Aug 2024 13:44:44 -0700 Subject: [PATCH 1/5] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-28 Thread Dan Liew via cfe-commits
delcypher wrote: @Endilll I've tried to address your feedback. https://github.com/llvm/llvm-project/pull/106453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-28 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/106453 >From 54a5f90ce219aad942074d78d986d24d6690b30c Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 28 Aug 2024 13:44:44 -0700 Subject: [PATCH 1/3] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-28 Thread Dan Liew via cfe-commits
delcypher wrote: @Endilll This is my attempt at implementing what you asked for in https://github.com/llvm/llvm-project/pull/106321#discussion_r1734379624 I'm not a huge fan of this as I think this will be extremely annoying for downstream forks with very little upside vs just moving the unsco

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -2099,6 +2099,70 @@ class Sema final : public SemaBase { bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, bool OrNull); + // AssignmentAction - This is used by all the assignment diagnostic functions + // to repr

[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)

2024-08-28 Thread Dan Liew via cfe-commits
https://github.com/delcypher created https://github.com/llvm/llvm-project/pull/106453 The primary motivation behind this is to allow the enum type to be referred to earlier in the `Sema.h` file which is needed for #106321. It was requested in #106321 that a scoped enum be used (rather than movi

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -8192,6 +8192,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { delcypher wrote: Yeah this isn't great. The whole functio

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -3862,6 +3878,27 @@ CountAttributedType::CountAttributedType( DeclSlot[i] = CoupledDecls[i]; } +StringRef CountAttributedType::GetAttributeName(bool WithMacroPrefix) const { delcypher wrote: > but the way this works for AttributedTypes is that the Att

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // Note: This implementation relies on `CountAttributedType` being uniqu

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -8192,6 +8192,14 @@ ExprResult InitializationSequence::Perform(Sema &S, Kind.getRange().getEnd()); } else { CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type); +// Note the return value isn't used to return early +// to pres

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, return false; } +SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) { + // Note: This implementation relies on `CountAttributedType` being uniqu

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -2438,6 +2438,22 @@ bool Type::isIncompleteType(NamedDecl **Def) const { } } +bool Type::isIncompletableIncompleteType() const { + if (!isIncompleteType()) +return false; + + // Forward declarations of structs, classes, enums, and unions could be later + // complet

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -2438,6 +2438,22 @@ bool Type::isIncompleteType(NamedDecl **Def) const { } } +bool Type::isIncompletableIncompleteType() const { + if (!isIncompleteType()) +return false; + + // Forward declarations of structs, classes, enums, and unions could be later + // complet

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -2440,6 +2440,26 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { return !isFunctionType(); } + /// \returns True if the type is incomplete and it is also a type that + /// cannot be completed by a later type definition. + /// + /// E.g. For

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
https://github.com/delcypher edited https://github.com/llvm/llvm-project/pull/106321 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-28 Thread Dan Liew via cfe-commits
@@ -2099,6 +2099,70 @@ class Sema final : public SemaBase { bool CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes, bool OrNull); + // AssignmentAction - This is used by all the assignment diagnostic functions + // to repr

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-08-27 Thread Dan Liew via cfe-commits
delcypher wrote: @bwendling @kees Apologies for taking so long to get this change upstream. We spent quite a lot of time experimenting with different implementations that ended up not working out. Our internal version of this patch is larger because `counted_by` is allowed in many more context

[clang] [Bounds Safety][NFC] Add some missing coverage for `-fexperimental-late-parse-attributes` (PR #102236)

2024-08-08 Thread Dan Liew via cfe-commits
https://github.com/delcypher closed https://github.com/llvm/llvm-project/pull/102236 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Bounds Safety][NFC] Add some missing coverage for `-fexperimental-late-parse-attributes` (PR #102236)

2024-08-07 Thread Dan Liew via cfe-commits
delcypher wrote: @AaronBallman Thanks for the feedback. I've tried to make your suggested changes. https://github.com/llvm/llvm-project/pull/102236 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo

[clang] [Bounds Safety][NFC] Add some missing coverage for `-fexperimental-late-parse-attributes` (PR #102236)

2024-08-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/102236 >From b5ce9c1f8de1deb90b9473ab26cd25c5111f7b42 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 6 Aug 2024 14:38:16 -0700 Subject: [PATCH 1/2] [Bounds Safety][NFC] Add some missing coverage for `-fexperimen

[clang] [Bounds Safety][NFC] Add some missing coverage for `-fexperimental-late-parse-attributes` (PR #102236)

2024-08-07 Thread Dan Liew via cfe-commits
https://github.com/delcypher updated https://github.com/llvm/llvm-project/pull/102236 >From 885d40de074514cf349423e7ae387ccdf6dfbbc4 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 6 Aug 2024 14:38:16 -0700 Subject: [PATCH 1/2] [Bounds Safety][NFC] Add some missing coverage for `-fexperimen

  1   2   3   4   >