[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-31 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna approved this pull request. https://github.com/llvm/llvm-project/pull/93231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-05-31 Thread Yeoul Na via cfe-commits
@@ -425,6 +425,12 @@ Attribute Changes in Clang size_t count; }; +- The attributes ``sized_by``, ``counted_by_or_null`` and ``sized_by_or_null``` + have been added as variants on ``counted_by``, each with slightly different semantics. + ``sized_by`` takes a

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

2024-05-23 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna edited https://github.com/llvm/llvm-project/pull/93121 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2024-05-23 Thread Yeoul Na via cfe-commits
@@ -4944,6 +4944,26 @@ void Parser::ParseStructDeclaration( } } +// TODO: All callers of this function should be moved to +// `Parser::ParseLexedAttributeList`. +void Parser::ParseLexedCAttributeList(LateParsedAttrList , bool EnterScope, +

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

2024-05-23 Thread Yeoul Na via cfe-commits
@@ -4944,6 +4944,26 @@ void Parser::ParseStructDeclaration( } } +// TODO: All callers of this function should be moved to +// `Parser::ParseLexedAttributeList`. +void Parser::ParseLexedCAttributeList(LateParsedAttrList , bool EnterScope, +

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

2024-05-23 Thread Yeoul Na via cfe-commits
@@ -0,0 +1,196 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +struct bar; + +struct not_found { + int count; + struct bar *fam[] __counted_by(bork); // expected-error {{use of undeclared identifier 'bork'}} +}; +

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

2024-05-23 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna edited https://github.com/llvm/llvm-project/pull/93121 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2024-05-23 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/93121 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2024-05-17 Thread Yeoul Na via cfe-commits
rapidsna wrote: @bwendling @kees Likely, we should not put `__counted_by` in that case. Could we fix the source? https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

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

2024-05-17 Thread Yeoul Na via cfe-commits
rapidsna wrote: @bwendling @kees Wait. `ATOM_PPLIB_STATE_V2` is also a struct with flexible array member? This is concerning because `ucNumEntries * sizeof(ATOM_PPLIB_STATE_V2)` is not the correct size anyway. Do you know the semantics of this structure?

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

2024-05-17 Thread Yeoul Na via cfe-commits
rapidsna wrote: @bwendling Thanks for reporting. We will relax the restrictions for arrays to not break the existing users. https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

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

2024-05-13 Thread Yeoul Na via cfe-commits
rapidsna wrote: > The main concern I have with delaying support for this is that header files > could find themselves in a state where they could not be refactored without > removing counted_by attributes that refer to now-incomplete structs. @kees Agreed. We will work on a follow up patch to

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

2024-05-09 Thread Yeoul Na via cfe-commits
rapidsna wrote: > I've been thinking about this restriction. Why is this necessary? My > assumption was that applying counted_by to a pointer causes a bounds check on > an index into the pointer rather than its underlying type. @bwendling It's because these types are not indexable really.

[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-05-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna closed https://github.com/llvm/llvm-project/pull/87596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-23 Thread Yeoul Na via cfe-commits
@@ -8547,15 +8547,25 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) { return RD; } -static bool -CheckCountExpr(Sema , FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl ) { +static bool CheckCountedByAttrOnField( +Sema ,

[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-23 Thread Yeoul Na via cfe-commits
@@ -1371,14 +1371,23 @@ class Parser : public CodeCompletionHandler { }; // A list of late-parsed attributes. Used by ParseGNUAttributes. - class LateParsedAttrList: public SmallVector { + class LateParsedAttrList : public SmallVector { rapidsna wrote:

[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-23 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/88596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-23 Thread Yeoul Na via cfe-commits
@@ -2101,9 +2173,21 @@ bool PragmaClangAttributeSupport::isAttributedSupported( return SpecifiedResult; // Opt-out rules: - // An attribute requires delayed parsing (LateParsed is on) - if (Attribute.getValueAsBit("LateParsed")) + + // An attribute requires delayed

[clang] [Attributes] Support Attributes being declared as supporting an experimental late parsing mode "extension" (PR #88596)

2024-04-23 Thread Yeoul Na via cfe-commits
@@ -89,13 +89,23 @@ static StringRef normalizeAttrName(StringRef Name) { return Name; } -/// isAttributeLateParsed - Return true if the attribute has arguments that -/// require late parsing. -static bool isAttributeLateParsed(const IdentifierInfo ) { +/// returns true iff

[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-17 Thread Yeoul Na via cfe-commits
@@ -91,11 +91,24 @@ static StringRef normalizeAttrName(StringRef Name) { /// isAttributeLateParsed - Return true if the attribute has arguments that /// require late parsing. -static bool isAttributeLateParsed(const IdentifierInfo ) { +bool Parser::isAttributeLateParsed(const

[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-17 Thread Yeoul Na via cfe-commits
@@ -592,6 +592,46 @@ class AttrSubjectMatcherAggregateRule { def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule; +// Late Attribute parsing mode enum +class LateAttrParseKind { + int Kind = val; +} + +// Never late parsed +def LateAttrParseNever :

[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-17 Thread Yeoul Na via cfe-commits
@@ -592,6 +592,46 @@ class AttrSubjectMatcherAggregateRule { def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule; +// Late Attribute parsing mode enum rapidsna wrote: @delcypher Thanks! LGTM. https://github.com/llvm/llvm-project/pull/88596

[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

2024-04-15 Thread Yeoul Na via cfe-commits
@@ -592,6 +592,16 @@ class AttrSubjectMatcherAggregateRule { def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule; +// Late Attribute parsing mode enum +class LateAttrParseKind { + int Kind = val; +} +def LateAttrParseNever : LateAttrParseKind<0>; // Never late

[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-12 Thread Yeoul Na via cfe-commits
rapidsna wrote: > This should be fine, because count is declared before use—unless I'm getting > type attributes confused with field attributes.. `struct size_unknown *__counted_by(count) buf` indicates that `buf` has `sizeof(struct size_unknown) * count`

[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-05 Thread Yeoul Na via cfe-commits
@@ -4997,7 +5087,11 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, ParsedAttributes attrs(AttrFactory); // If attributes exist after struct contents, parse them. - MaybeParseGNUAttributes(attrs); + MaybeParseGNUAttributes(attrs, ); + +

[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-22 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna closed https://github.com/llvm/llvm-project/pull/86017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-21 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/86017 >From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Thu, 21 Mar 2024 06:47:05 +0900 Subject: [PATCH 1/3] Unwrap CountAttributed for debug info Fix crash caused by

[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/86017 >From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Thu, 21 Mar 2024 06:47:05 +0900 Subject: [PATCH 1/2] Unwrap CountAttributed for debug info Fix crash caused by

[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Yeoul Na via cfe-commits
rapidsna wrote: Fix crash in https://github.com/llvm/llvm-project/pull/78000 https://github.com/llvm/llvm-project/pull/86017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-20 Thread Yeoul Na via cfe-commits
rapidsna wrote: Thanks @nathanchance. Opened PR to fix the crash. https://github.com/llvm/llvm-project/pull/86017 https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna created https://github.com/llvm/llvm-project/pull/86017 Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9 >From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Thu, 21 Mar 2024 06:47:05 +0900 Subject: [PATCH] Unwrap

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-15 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 3d2716ad6088f600c14d6ff724aa90453130a1f7 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/14] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-14 Thread Yeoul Na via cfe-commits
rapidsna wrote: @AaronBallman Thank you! The -fbounds-safety documentation is currently shown https://clang.llvm.org/docs/BoundsSafety.html, but yes, we're planning to add the feature in the release note once we have more functionalities in place.

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-08 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 3d2716ad6088f600c14d6ff724aa90453130a1f7 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/11] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-08 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 3d2716ad6088f600c14d6ff724aa90453130a1f7 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/10] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-07 Thread Yeoul Na via cfe-commits
rapidsna wrote: @Endilll I just rebased it so you can review `Sema.h`. https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-07 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 3d2716ad6088f600c14d6ff724aa90453130a1f7 Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/9] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-07 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/9] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/8] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
rapidsna wrote: @AaronBallman thanks for the review! I addressed your comments. https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
@@ -2000,6 +2001,21 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase { unsigned NumExpansions; }; + class CountAttributedTypeBitfields { +friend class CountAttributedType; + +LLVM_PREFERRED_TYPE(TypeBitfields) +unsigned : NumTypeBits; +

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
@@ -1117,6 +1117,32 @@ class ObjCInterfaceTypeLoc : public ConcreteTypeLoc { +public: + TypeLoc getInnerLoc() const { return this->getInnerTypeLoc(); } + QualType getInnerType() const { return this->getTypePtr()->desugar(); } + void initializeLocal(ASTContext , SourceLocation

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
@@ -4259,7 +4240,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, if (const auto *ME = dyn_cast(Array); ME && ME->isFlexibleArrayMemberLike(getContext(), StrictFlexArraysLevel) && -

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
@@ -13233,6 +13262,32 @@ static QualType getCommonSugarTypeNode(ASTContext , const Type *X, return QualType(); return Ctx.getUsingType(CD, Ctx.getQualifiedType(Underlying)); } + case Type::CountAttributed: { +const auto *DX = cast(X), + *DY =

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
@@ -7239,6 +7239,13 @@ QualType TreeTransform::TransformAttributedType(TypeLocBuilder , }); } +template +QualType TreeTransform::TransformCountAttributedType( +TypeLocBuilder , CountAttributedTypeLoc TL) { + // TODO + llvm_unreachable("Unexpected TreeTransform

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-06 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/7] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-26 Thread Yeoul Na via cfe-commits
rapidsna wrote: Gentle reminder @bwendling @AaronBallman. I'd like to land this patch soon, so we can open source more of -fbounds-safety work. Could you please take a look? https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-26 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/6] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-19 Thread Yeoul Na via cfe-commits
@@ -8463,133 +8463,115 @@ static void handleZeroCallUsedRegsAttr(Sema , Decl *D, const ParsedAttr ) { D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL)); } -static void handleCountedByAttr(Sema , Decl *D, const ParsedAttr ) { - if (!AL.isArgIdent(0)) { -

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-19 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/4] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-19 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/3] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-19 Thread Yeoul Na via cfe-commits
rapidsna wrote: @AaronBallman @erichkeane gentle reminder. Does my reasoning [above](https://github.com/llvm/llvm-project/pull/78000#issuecomment-1932496432) to make a new sugar type make sense? https://github.com/llvm/llvm-project/pull/78000 ___

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-07 Thread Yeoul Na via cfe-commits
rapidsna wrote: Thanks @AaronBallman! > I think AttributedType might be a reasonable way forward. That's how we model > nullability qualifiers, for example: The difference from nullability qualifiers is that they are actually encoded as `AttributeKind`, whereas `__counted_by` has to store

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits
rapidsna wrote: FWIW, in the context of `-fbounds-safety` (https://github.com/llvm/llvm-project/blob/main/clang/docs/BoundsSafety.rst), I think the best is to have the bounds-annotated types to be part of the canonical type system because they affect the semantics and the codegen (again with

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits
rapidsna wrote: > One possibility would be to use a type qualifier? It has basically the kind > of properties you want... the underlying type is > still there, and places > that strip qualifiers will automatically do the right thing in a lot of > cases. It might require a bit more > work to

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits
@@ -2917,6 +2942,133 @@ class PointerType : public Type, public llvm::FoldingSetNode { static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } }; +/// [BoundsSafety] Represents information of declarations referenced by the +/// arguments of the

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna edited https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-06 Thread Yeoul Na via cfe-commits
@@ -8463,133 +8463,110 @@ static void handleZeroCallUsedRegsAttr(Sema , Decl *D, const ParsedAttr ) { D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL)); } -static void handleCountedByAttr(Sema , Decl *D, const ParsedAttr ) { - if (!AL.isArgIdent(0)) { -

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-05 Thread Yeoul Na via cfe-commits
rapidsna wrote: > It's generally not a good idea to use sugar to represent constructs that are > semantically significant: anything that uses the canonical type will throw it > away. We try to avoid throwing away sugar in most cases, but we aren't always > successful. > It's possible there

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
rapidsna wrote: @AaronBallman @bwendling I'd appreciate your feedback! https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/2] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna ready_for_review https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From c39871ed2ec642ab00360f2c3a18fba7c915f82d Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH] [BoundsSafety] Introduce CountAttributedType CountAttributedType is

[clang-tools-extra] [llvm] [clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna converted_to_draft https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[llvm] [clang-tools-extra] [clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/13] [BoundsSafety] Introduce CountAttributedType

[llvm] [clang-tools-extra] [clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/12] [BoundsSafety] Introduce CountAttributedType

[llvm] [clang-tools-extra] [clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/12] [BoundsSafety] Introduce CountAttributedType

[clang-tools-extra] [llvm] [clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/11] [BoundsSafety] Introduce CountAttributedType

[clang-tools-extra] [clang] [llvm] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 01/10] [BoundsSafety] Introduce CountAttributedType

[clang] [clang-tools-extra] [llvm] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-02-01 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna ready_for_review https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] [llvm] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-30 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/9] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-30 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/9] [BoundsSafety] Introduce CountAttributedType

[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-30 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna edited https://github.com/llvm/llvm-project/pull/78000 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [WIP] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-30 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/8] [BoundsSafety] Introduce CountAttributedType

[clang] [WIP] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-22 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/5] [BoundsSafety] Introduce CountAttributedType

[clang] [WIP] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-22 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna updated https://github.com/llvm/llvm-project/pull/78000 >From 1a17c254ddf09cd4faf5217b2f72da3f44622f8a Mon Sep 17 00:00:00 2001 From: Yeoul Na Date: Mon, 18 Dec 2023 10:58:16 +0900 Subject: [PATCH 1/4] [BoundsSafety] Introduce CountAttributedType

[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2024-01-16 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna closed https://github.com/llvm/llvm-project/pull/70749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [WIP] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-01-12 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna created https://github.com/llvm/llvm-project/pull/78000 In `-fbounds-safety`, bounds annotations are considered type attributes rather than declaration attributes. Constructing them as type attributes allows us to extend the attribute to apply nested pointers,

[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2024-01-12 Thread Yeoul Na via cfe-commits
rapidsna wrote: Rebased https://github.com/llvm/llvm-project/pull/70749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [BoundsSafety] Initial documentation for -fbounds-safety (PR #70749)

2024-01-12 Thread Yeoul Na via cfe-commits
rapidsna wrote: > Thank you for the updates; the changes LGTM! @AaronBallman Thanks for your review and insightful feedback! https://github.com/llvm/llvm-project/pull/70749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-10 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna edited https://github.com/llvm/llvm-project/pull/76348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-10 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna approved this pull request. > Do you have anything to add? LGTM https://github.com/llvm/llvm-project/pull/76348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-09 Thread Yeoul Na via cfe-commits
rapidsna wrote: > The return value of -1 means "I don't know how large this is". @kees Oh, I see. I did not know such the convention. Is it documented somewhere? https://github.com/llvm/llvm-project/pull/76348 ___ cfe-commits mailing list

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-09 Thread Yeoul Na via cfe-commits
rapidsna wrote: > This prints a wrapped calculation instead of the expected "0". Shouldn't `getDefaultBuiltinObjectSizeResult` return `-1`? Have you tried `-2` to see if it's returning the negative count value or it happens to be equal to the default value?

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,262 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -818,6 +819,189 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); } +const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( +ASTContext , const RecordDecl *RD,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -818,6 +819,189 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); } +const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( +ASTContext , const RecordDecl *RD,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna commented: I left some comments. Looking good overall but `LocalDeclMap` doesn't seem to serve the purpose for this PR. And I'm not sure the code block using it would be actually necessary. Please see my inlined review.

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,262 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -818,6 +819,189 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); } +const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( +ASTContext , const RecordDecl *RD,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -818,6 +819,189 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); } +const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( +ASTContext , const RecordDecl *RD,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction , return nullptr; } +namespace { + +/// \p StructAccessBase returns the base \p Expr of a field access. It returns +/// either a \p DeclRefExpr, representing the base pointer to the struct,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -818,6 +819,189 @@ CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); } +const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( +ASTContext , const RecordDecl *RD,

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
@@ -1155,15 +1159,14 @@ const FieldDecl *CodeGenFunction::FindCountedByField(const FieldDecl *FD) { return nullptr; auto GetNonAnonStructOrUnion = [](const RecordDecl *RD) { -while (RD && !RD->getDeclName()) - if (const auto *R =

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2024-01-08 Thread Yeoul Na via cfe-commits
https://github.com/rapidsna edited https://github.com/llvm/llvm-project/pull/76348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

  1   2   3   >