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

2024-01-22 Thread Sean McBride via cfe-commits
seanm wrote: @bwendling thanks for your reply. No idea how representative it is of other projects, but 3 of the 6 flexible arrays in [libusb](https://github.com/libusb/libusb) structures have these kinds of non-trivial counts. The GCC folks seem to have [considered](https://gcc.gnu.org/bugzi

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

2024-01-22 Thread Bill Wendling via cfe-commits
bwendling wrote: > @bwendling is there any plan / possibility for simple expressions (with no > side effects)? Like: > > ```c > struct libusb_bos_dev_capability_descriptor { > uint8_t bLength; > uint8_t bDescriptorType; > uint8_t bDevCapabilityType; > uint8_t dev_cap

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

2024-01-19 Thread Sean McBride via cfe-commits
seanm wrote: @bwendling is there any plan / possibility for simple expressions (with no side effects)? Like: ```c struct libusb_bos_dev_capability_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDevCapabilityType; uint8_t dev_capability_data[

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

2024-01-10 Thread Bill Wendling via cfe-commits
bwendling wrote: Resubmitted with fix. Sorry about the failures: ``` To https://github.com/llvm/llvm-project.git e8790027b169..164f85db876e main -> main ``` https://github.com/llvm/llvm-project/pull/76348 ___ cfe-commits mailing list cfe-commits@l

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

2024-01-10 Thread Nico Weber via cfe-commits
nico wrote: Reverted in 2dce77201c0c6b541a53aa7a09ec06e7561e8f74 for now. 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 via cfe-commits
dyung wrote: @bwendling the test you added `CodeGen/attr-counted-by.c` appears to be failing on quite a few bots, can you take a look? Some failing bots: - https://lab.llvm.org/buildbot/#/builders/164/builds/48660 - https://lab.llvm.org/buildbot/#/builders/188/builds/40261 - https://lab.llvm.or

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

2024-01-10 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed 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 Bill Wendling via cfe-commits
bwendling wrote: Thanks everyone for their insightful feedback!! 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 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 https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-comm

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

2024-01-10 Thread Bill Wendling via cfe-commits
bwendling wrote: @rapidsna & @nickdesaulniers: Do you have anything to add? 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 Kees Cook via cfe-commits
https://github.com/kees approved this pull request. I can't speak to the LLVM code changes, but behaviorally, this passes all the torture tests I'd expect it to (kernel-tools/fortify/array-bounds.c and full kernel builds with its hundreds of `counted_by` annotations). https://github.com/llvm/l

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

2024-01-10 Thread Kees Cook via cfe-commits
kees wrote: That's it! Everything works. :) Ship it! 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 Bill Wendling via cfe-commits
bwendling wrote: Never mind. I think I found the issue anyway... 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 Bill Wendling via cfe-commits
bwendling wrote: @kees Could you supply a pre-processed file and command line? (It should have been emitted when you got the backtrace.) https://github.com/llvm/llvm-project/pull/76348 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://li

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

2024-01-10 Thread Kees Cook via cfe-commits
kees wrote: Thanks! It's fixed for me now. I continue to be highly unlucky, though, and keep finding weird stuff. It seems to segfault just parsing libc headers under `-D_FORTIFY_SOURCE=3` (but not `=2` or lower): ``` 0. Program arguments: /srv/built-compilers/llvm/counted_by/install/bin

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

2024-01-09 Thread via cfe-commits
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 061e4f24b24a3b59d73a94dc6f2f0d21a2b7beac 557604301ab98d89b5ddf6d857d85326d7d3da3d --

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

2024-01-09 Thread Bill Wendling via cfe-commits
bwendling wrote: Like I said, I can fix the `mi->ints` issue. It's when we're trying to ask for the size of the whole struct with more than one `__counted_by` attribute that we don't be able to handle. https://github.com/llvm/llvm-project/pull/76348

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

2024-01-09 Thread Kees Cook via cfe-commits
kees wrote: Accessing `mi->ints` is unambiguous (it would use the declared `count_ints`) but I'm fine to wait and fix that later. The flex array union is gloriously rare in the kernel. As for whole object, I say pick smallest from all available under bdos(x, 1) and largest for bdos(x, 0), or j

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

2024-01-09 Thread Bill Wendling via cfe-commits
bwendling wrote: > > @kees, the issue should be fixed with the newest push. > > Nice! This is so extremely close. It fixed all but 1 instance in the torture > testing. The remaining seems to be union order sensitive. O_o This > arrangement still reports non-zero for the `int count_bytes` one,

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

2024-01-09 Thread Kees Cook via cfe-commits
kees wrote: > @kees, the issue should be fixed with the newest push. Nice! This is so extremely close. It fixed all but 1 instance in the torture testing. The remaining seems to be union order sensitive. O_o This arrangement still reports non-zero for the `int count_bytes` one, unless I move i

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

2024-01-09 Thread Bill Wendling via cfe-commits
bwendling wrote: @kees, the issue should be fixed with the newest push. 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-09 Thread Kees Cook via cfe-commits
kees wrote: > > but the value is nonsense, so we must return 0 so that anything checking > > lengths will not write anything to the array. > > @kees Oh, I see. I did not know such the convention but it makes sense. Is it > documented somewhere? This is new territory (having a multiplier for f

[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 cfe-commits

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

2024-01-09 Thread Kees Cook via cfe-commits
kees 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? Well, maybe it's not wrapped,

[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? https://github.com/llvm/llvm-projec

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

2024-01-09 Thread Kees Cook via cfe-commits
kees wrote: Thanks! The update fixes the anon struct issue I hit. I've found one more issue, though this appears to be a miscalculation with a pathological `count` value (i.e. `count` is signed type and contains a negative value): ``` struct annotated { unsigned long flags; int count;

[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 &CGF, 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 &CGF, 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 Bill Wendling 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Bill Wendling via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, 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 Bill Wendling via cfe-commits
bwendling wrote: @kees Should be fixed now. 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-08 Thread Yeoul Na via cfe-commits
@@ -944,22 +951,262 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, 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 &Ctx, const RecordDecl *R

[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 &Ctx, const RecordDecl *R

[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 &CGF, 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 Kees Cook via cfe-commits
kees wrote: Possibly due to bug #72032 , I can get this tree to crash using the latest `array-bounds.c` test from https://github.com/kees/kernel-tools/tree/trunk/fortify Specifically: ``` struct anon_struct { unsigned long flags; long count; int array[] __counted_by(cou

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

2024-01-08 Thread Bill Wendling 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Bill Wendling 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Bill Wendling via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, 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 Bill Wendling via cfe-commits
@@ -944,22 +951,262 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, 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 Bill Wendling via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, 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 Bill Wendling 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Bill Wendling 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Bill Wendling 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 = dyn_cast(RD->getDeclContext()))

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

2024-01-08 Thread Bill Wendling via cfe-commits
@@ -944,22 +951,259 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction &CGF, 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. https://github.com/llvm/llvm-project/pull/7634

[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 &CGF, 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 &CGF, 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 &Ctx, const RecordDecl *R

[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 &Ctx, const RecordDecl *R

[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 &CGF, 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 &CGF, 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 &Ctx, const RecordDecl *R

[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 = dyn_cast(RD->getDeclContext()))

[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

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

2024-01-08 Thread Bill Wendling via cfe-commits
@@ -850,6 +1034,13 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type, } } + if (IsDynamic) { +// Emit special code for a flexible array member with the "counted_by" +// attribute. +if (Value *V = emitFlexibleArrayMemberSize(E, Type, Res

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

2024-01-08 Thread Bill Wendling via cfe-commits
@@ -365,6 +365,10 @@ class DefaultFilterCCC final : public CorrectionCandidateCallback { template class DeclFilterCCC final : public CorrectionCandidateCallback { public: + explicit DeclFilterCCC(const IdentifierInfo *Typo = nullptr, + NestedNameSpeci

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

2024-01-08 Thread Bill Wendling 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Nick Desaulniers via cfe-commits
@@ -850,6 +1034,13 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type, } } + if (IsDynamic) { +// Emit special code for a flexible array member with the "counted_by" +// attribute. +if (Value *V = emitFlexibleArrayMemberSize(E, Type, Res

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

2024-01-08 Thread Nick Desaulniers 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 &Ctx, const RecordDecl *R

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

2024-01-08 Thread Nick Desaulniers via cfe-commits
@@ -365,6 +365,10 @@ class DefaultFilterCCC final : public CorrectionCandidateCallback { template class DeclFilterCCC final : public CorrectionCandidateCallback { public: + explicit DeclFilterCCC(const IdentifierInfo *Typo = nullptr, + NestedNameSpeci

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

2024-01-04 Thread Bill Wendling via cfe-commits
bwendling wrote: Pinging for after-holidays visibility. :-) 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)

2023-12-27 Thread Bill Wendling via cfe-commits
bwendling wrote: Some (hopefully) helpful comments on this admittedly very large patch. General Comment: I pulled back on allowing the `count` to be in a non-anonymous struct that doesn't contain the flexible array. So this is no longer allowed: ``` struct count_not_in_substruct { unsigned

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

2023-12-26 Thread Bill Wendling via cfe-commits
https://github.com/bwendling 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)

2023-12-24 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Bill Wendling (bwendling) Changes The 'counted_by' attribute is used on flexible array members. The argument for the attribute is the name of the field member holding the count of elements in the flexible array. This information is used to