[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-22 Thread Bill Wendling via cfe-commits
bwendling wrote: I think I addressed your concerns. PTAL. https://github.com/llvm/llvm-project/pull/86858 ___ 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 Bill Wendling via cfe-commits
bwendling wrote: Thank you. I wrote to the author. I hope he'll be able to come up with a change on his end. Or at least an explanation that makes sense :-) https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list

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

2024-05-17 Thread Bill Wendling via cfe-commits
bwendling wrote: Ah! I see what you mean. I'll bring this up with the developer. (Actually, that construct makes me nervous about their code in general...) https://github.com/llvm/llvm-project/pull/90786 ___ cfe-commits mailing list

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-17 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/86858 >From 31af119d614ef2108b5404f9c9387ec45aa1bfef Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 21 Mar 2024 15:07:31 -0700 Subject: [PATCH 1/6] [Clang][objectsize] Generate object size calculation for

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-17 Thread Bill Wendling via cfe-commits
@@ -1052,6 +1053,165 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + bool SkipASE; +

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-17 Thread Bill Wendling via cfe-commits
@@ -1052,6 +1053,165 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + bool SkipASE; +

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-17 Thread Bill Wendling via cfe-commits
@@ -1052,6 +1053,165 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + bool SkipASE; +

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-17 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/86858 >From 31af119d614ef2108b5404f9c9387ec45aa1bfef Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 21 Mar 2024 15:07:31 -0700 Subject: [PATCH 1/5] [Clang][objectsize] Generate object size calculation for

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

2024-05-17 Thread Bill Wendling via cfe-commits
bwendling wrote: This seems to have broken the Linux build: https://github.com/llvm/llvm-project/commit/0ec3b972e58bcbcdc1bebe1696ea37f2931287c3 breaks the build for Linux, added by https://git.kernel.org/linus/781d41fed19caf900c8405064676813dc9921d32:

[clang] Fix for merging PR #89456 into llvm 18.X (PR #90118)

2024-05-14 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/90118 ___ 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-13 Thread Bill Wendling via cfe-commits
bwendling wrote: > > It's not a lie, because the contents of a pointer don't contribute to the > > size of the struct containing that pointer. > > Consider this example. It tries to illustrate why putting `__counted_by()` on > a pointer to a structs containing flexible array members doesn't

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

2024-05-10 Thread Bill Wendling via cfe-commits
bwendling wrote: @rapidsna @delcypher @apple-fcloutier @kees: Okay, I think I see what the complication is. Are you trying to prevent the use case of someone writing something like: ```c struct bar; struct foo { size_t count; struct bar *ptr __counted_by(count); }; ``` where `ptr` is a

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

2024-05-10 Thread Bill Wendling via cfe-commits
bwendling wrote: @apple-fcloutier: > think that there's room to allow `__counted_by` on incomplete types so that a > TU where it's complete could use it (and we have use cases where that would > be handy), but our implementation doesn't support it at this time. This can > be added without

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

2024-05-09 Thread Bill Wendling via cfe-commits
bwendling wrote: > Note the attribute is prevented on pointee types where the size isn't known > at compile time. In particular pointee types that are: > > * Incomplete (e.g. `void`) and sizeless types > * Function types (e.g. the pointee of a function pointer) > * Struct types with a flexible

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-06 Thread Bill Wendling via cfe-commits
bwendling wrote: Ping again. https://github.com/llvm/llvm-project/pull/86858 ___ 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-03 Thread Bill Wendling via cfe-commits
@@ -335,6 +336,22 @@ Attribute Changes in Clang - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute is ignored when applied to a local class or a member thereof. +- The ``counted_by`` attribute can now be late parsed in C when

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -6534,6 +6536,15 @@ def err_counted_by_attr_refer_to_union : Error< "'counted_by' argument cannot refer to a union member">; def note_flexible_array_counted_by_attr_field : Note< "field %0 declared here">; +def err_counted_by_attr_pointee_unknown_size : Error< +

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -631,6 +631,18 @@ bool Type::isStructureType() const { return false; } +bool Type::isStructureTypeWithFlexibleArrayMember() const { + const auto *RT = getAs(); + if (!RT) +return false; + const auto *Decl = RT->getDecl(); + if (!Decl->isStruct()) +return

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -6534,6 +6536,15 @@ def err_counted_by_attr_refer_to_union : Error< "'counted_by' argument cannot refer to a union member">; def note_flexible_array_counted_by_attr_field : Note< "field %0 declared here">; +def err_counted_by_attr_pointee_unknown_size : Error< +

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -335,6 +336,22 @@ Attribute Changes in Clang - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute is ignored when applied to a local class or a member thereof. +- The ``counted_by`` attribute can now be late parsed in C when

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

2024-05-03 Thread Bill Wendling via cfe-commits
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/90786 ___ 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-03 Thread Bill Wendling via cfe-commits
@@ -3282,6 +3282,19 @@ void Parser::ParseAlignmentSpecifier(ParsedAttributes , } } +void Parser::DistributeCLateParsedAttrs(Decl *Dcl, +LateParsedAttrList *LateAttrs) { + assert(Dcl); bwendling wrote: Could you add

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -8588,31 +8588,71 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) { return RD; } -static bool -CheckCountExpr(Sema , FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl ) { +enum class CountedByInvalidPointeeTypeKind { +

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -631,6 +631,18 @@ bool Type::isStructureType() const { return false; } +bool Type::isStructureTypeWithFlexibleArrayMember() const { + const auto *RT = getAs(); + if (!RT) +return false; + const auto *Decl = RT->getDecl(); + if (!Decl->isStruct()) +return

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -6534,6 +6536,15 @@ def err_counted_by_attr_refer_to_union : Error< "'counted_by' argument cannot refer to a union member">; def note_flexible_array_counted_by_attr_field : Note< "field %0 declared here">; +def err_counted_by_attr_pointee_unknown_size : Error< +

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

2024-05-03 Thread Bill Wendling via cfe-commits
@@ -335,6 +336,22 @@ Attribute Changes in Clang - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute is ignored when applied to a local class or a member thereof. +- The ``counted_by`` attribute can now be late parsed in C when

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-05-02 Thread Bill Wendling via cfe-commits
bwendling wrote: The code looks fine to me. But you should wait for @efriedma-quic to chime in as he had concerns over the feature. https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-04-29 Thread Bill Wendling via cfe-commits
bwendling wrote: Another ping... https://github.com/llvm/llvm-project/pull/86858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Fix for merging PR #89456 into llvm 18.X (PR #90118)

2024-04-25 Thread Bill Wendling via cfe-commits
bwendling wrote: Does it matter if it's just a cherry-pick? https://github.com/llvm/llvm-project/pull/90118 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-25 Thread Bill Wendling via cfe-commits
bwendling wrote: @tstellar PR https://github.com/llvm/llvm-project/pull/90118 is the fix here. https://github.com/llvm/llvm-project/pull/89126 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] Fix for merging PR #89456 into llvm 18.X (PR #90118)

2024-04-25 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/90118 Fix #89126 for the 18.X branch. >From cb0d1c0b15cea9c6a50a127fed9a6ad49f2c1d8f Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 25 Apr 2024 13:37:07 -0700 Subject: [PATCH] Fix for merging PR #89456

[clang] Fix for merging PR #89456 into llvm 18.X (PR #90118)

2024-04-25 Thread Bill Wendling via cfe-commits
https://github.com/bwendling milestoned https://github.com/llvm/llvm-project/pull/90118 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-24 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/89462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-04-22 Thread Bill Wendling via cfe-commits
bwendling wrote: Friendly ping 2: Electric Boogaloo https://github.com/llvm/llvm-project/pull/86858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr { static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { return HasFPFeatures * sizeof(FPOptionsOverride); } + + /// Do one of the subexpressions have the wraps attribute? bwendling wrote:

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -4249,6 +4270,10 @@ Value *ScalarExprEmitter::EmitFixedPointBinOp(const BinOpInfo ) { Value *ScalarExprEmitter::EmitSub(const BinOpInfo ) { // The LHS is always a pointer if either side is. if (!op.LHS->getType()->isPointerTy()) { +if

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -2831,6 +2840,9 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, } else if (type->isIntegerType()) { QualType promotedType; bool canPerformLossyDemotionCheck = false; +BinOpInfo Ops = (createBinOpInfoFromIncDec(

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -4455,6 +4455,14 @@ void Sema::AddAlignValueAttr(Decl *D, const AttributeCommonInfo , Expr *E) { D->addAttr(::new (Context) AlignValueAttr(Context, CI, E)); } +static void handleWrapsAttr(Sema , Decl *D, const ParsedAttr ) { + S.AddWrapsAttr(D, AL); +} + +void

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -triple x86_64-pc-linux-gnu +// expected-no-diagnostics +typedef int __attribute__((wraps)) wrapping_int; + +void foo(void) { + const wrapping_int A = 1; + int D = 2147483647 + A; bwendling wrote:

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -4093,6 +4109,11 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo ) { op.RHS->getType()->isPointerTy()) return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction); + if ((op.Ty->isSignedIntegerOrEnumerationType() || bwendling

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-22 Thread Bill Wendling via cfe-commits
@@ -156,6 +156,10 @@ struct BinOpInfo { } return false; } + + /// Does the BinaryOperator have the wraps attribute? + /// If so, we can ellide overflow sanitizer checks. bwendling wrote: s/ellide/elide/

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-22 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89462 >From 2a6b3356a977132459bed84fb4e4add631e181cb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 19 Apr 2024 15:06:34 -0700 Subject: [PATCH 1/2] [Clang][NFC] Improve testing for the flexible array

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
@@ -930,12 +931,12 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, // Get the flexible array member Decl. const RecordDecl *OuterRD = nullptr; - std::string FAMName; + const FieldDecl *FAMDecl = nullptr; if (const auto *ME =

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89462 >From 2a6b3356a977132459bed84fb4e4add631e181cb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 19 Apr 2024 15:06:34 -0700 Subject: [PATCH 1/2] [Clang][NFC] Improve testing for the flexible array

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
bwendling wrote: A quick look at `Decl` seems like it would require adding a `PrevInContextAndBits`, which would increase the size by `sizeof(Decl *)`. I might be able to massage a way to make it work, but it's probably not worth it. https://github.com/llvm/llvm-project/pull/89462

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
bwendling wrote: Would changing the `decl_iterator` into a bidirectional iterator be acceptable? That way I could grab the last `FieldDecl` to check if it's a FAM rather than iterating through unnecessary `Decls`... https://github.com/llvm/llvm-project/pull/89462

[clang] [Clang] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/89462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang][NFC] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
bwendling wrote: > Strictly speaking, I don't think this is NFC. Consider, for example: > > ``` > struct S { > struct X { int array[1]; } x; > struct Y { int count; int array[] __attribute__((__counted_by__(count))); } > y; > }; > void f(void* __attribute__((pass_dynamic_object_size(0;

[clang] [Clang][NFC] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
bwendling wrote: > Does this still work for cases where there are multiple flexible arrays? e.g. > > ``` > struct weird_protocol { > unsigned int cmd_type; > unsigned int data_len; > union { > struct cmd_one one[]; > struct cmd_two two[]; > struct cmd_three

[clang] [Clang][NFC] Improve testing for the flexible array member (PR #89462)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/89462 Testing for the name of the flexible array member isn't as robust as testing the FieldDecl pointers. >From 2a6b3356a977132459bed84fb4e4add631e181cb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 19

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
@@ -826,29 +826,32 @@ const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( ASTContext , const RecordDecl *RD, StringRef Name, uint64_t ) { const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel = getLangOpts().getStrictFlexArraysLevel(); -

[clang] [Clang] Loop over FieldDecls instead of all Decls (PR #89453)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/89453 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Loop over FieldDecls instead of all Decls (PR #89453)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/89453 Only FieldDecls are of importance here. A struct defined within another struct has the same semantics as if it were defined outside of the struct. So there's no need to look into RecordDecls that aren't a

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/89126 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89126 >From 36ddb5811f11a1f6968705005713f34713026dbb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Apr 2024 12:23:02 -0700 Subject: [PATCH 1/8] [Clang] Handle structs with inner structs and no fields A

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/89126 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
@@ -0,0 +1,22 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s + +struct foo { + struct bar { +int

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89126 >From 36ddb5811f11a1f6968705005713f34713026dbb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Apr 2024 12:23:02 -0700 Subject: [PATCH 1/8] [Clang] Handle structs with inner structs and no fields A

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-19 Thread Bill Wendling via cfe-commits
@@ -0,0 +1,40 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s + +struct foo { + int x,y,z; + struct bar

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-18 Thread Bill Wendling via cfe-commits
@@ -0,0 +1,22 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s + +struct foo { + struct bar { +int

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-18 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89126 >From 36ddb5811f11a1f6968705005713f34713026dbb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Apr 2024 12:23:02 -0700 Subject: [PATCH 1/4] [Clang] Handle structs with inner structs and no fields A

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-18 Thread Bill Wendling via cfe-commits
bwendling wrote: > We should probably apply the same fix to CountCountedByAttrs. > > Along those lines, we should be able to handle: > > ``` > struct bar { > int count; > int array[] __attribute__((counted_by(count))); > }; > struct foo { struct bar x; }; > void init(void *

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-18 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89126 >From 36ddb5811f11a1f6968705005713f34713026dbb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Apr 2024 12:23:02 -0700 Subject: [PATCH 1/3] [Clang] Handle structs with inner structs and no fields A

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-18 Thread Bill Wendling via cfe-commits
@@ -844,7 +847,18 @@ const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( if (const FieldDecl *Field = bwendling wrote: I did several tests, and it looks like if there's an inner struct that's not accessible, that doesn't affect the offsets

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-18 Thread Bill Wendling via cfe-commits
@@ -844,7 +847,18 @@ const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField( if (const FieldDecl *Field = bwendling wrote: > FieldNo and Layout are referring to fields of "RD"; the "Field" found in the > recursive visit is a member of Record (or

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-17 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/89126 >From 36ddb5811f11a1f6968705005713f34713026dbb Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 17 Apr 2024 12:23:02 -0700 Subject: [PATCH 1/2] [Clang] Handle structs with inner structs and no fields A

[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

2024-04-17 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/89126 A struct that declares an inner struct, but no fields, won't have a field count. So getting the offset of the inner struct fails. This happens in both C and C++: struct foo { struct bar { int

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

2024-04-15 Thread Bill Wendling via cfe-commits
@@ -1822,28 +1822,101 @@ void WriteSemanticSpellingSwitch(const std::string , OS << " }\n"; } +enum class LateAttrParseKind { Never = 0, Always = 1, ExperimentalOnly = 2 }; + +static LateAttrParseKind getLateAttrParseKind(const Record *Attr) { + // This function

[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 Bill Wendling 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] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

2024-04-12 Thread Bill Wendling via cfe-commits
bwendling wrote: FYI: I'm planning on having a separate `test/Sema/attr-counted-by-for-pointers.c` test file for pointers and rename the current file something like `test/Sema/attr-counted-by-for-flexible-array-members.c`.

[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 Bill Wendling via cfe-commits
@@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#define __counted_by(f) __attribute__((counted_by(f))) + +struct size_unknown; + +struct at_pointer { + int count; + struct size_unknown *__counted_by(count) buf; // expected-error{{'counted_by' cannot be

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-11 Thread Bill Wendling via cfe-commits
bwendling wrote: > Forbidding usage in C++ probably avoids the worst of the canonical-type > issues, but there's still some potential for weird results. Particularly with > type merging; for example, if you write `a ? (wrap_int)x : 1`, is the result > a wrapping type? I had a similar

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-11 Thread Bill Wendling via cfe-commits
bwendling wrote: > Hi, I've made some changes and am looking for some more review on this PR: > > * This attribute no longer supports C++ as there are other solutions for that > language [1](https://godbolt.org/z/7qPve6cWq) that allow for the same > fine-grained wrapping control without

[clang] [lldb] [NFC][Clang] Improve const correctness for IdentifierInfo (PR #79365)

2024-04-10 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/79365 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-04-10 Thread Bill Wendling via cfe-commits
bwendling wrote: Friendly ping. https://github.com/llvm/llvm-project/pull/86858 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-03-27 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/86858 The second argument of __builtin_dynamic_object_size controls whether it returns the size of the whole object or the closest surrounding object. For this struct: struct s { int foo; char bar[2][40];

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-03-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/80256 >From d08abc7a9454557ffa43fc14611177f2c4e7fba4 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 31 Jan 2024 13:07:53 -0800 Subject: [PATCH] [Clang] Convert __builtin_dynamic_object_size into a

[clang] [NFC][IdentifierInfo] Use llvm::Bitfield for the bitfield (PR #79366)

2024-03-19 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/79366 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-12 Thread Bill Wendling via cfe-commits
@@ -26996,18 +26996,38 @@ class, structure, array, or other object. Arguments: "" -The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a -pointer to or into the ``object``. The second argument determines whether -``llvm.objectsize`` returns 0

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-12 Thread Bill Wendling via cfe-commits
@@ -26996,18 +26996,38 @@ class, structure, array, or other object. Arguments: "" -The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a -pointer to or into the ``object``. The second argument determines whether -``llvm.objectsize`` returns 0

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-12 Thread Bill Wendling via cfe-commits
@@ -26996,18 +26996,38 @@ class, structure, array, or other object. Arguments: "" -The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a -pointer to or into the ``object``. The second argument determines whether -``llvm.objectsize`` returns 0

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-11 Thread Bill Wendling via cfe-commits
@@ -1052,11 +1053,143 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +/// SubobjectFinder - A simple visitor to find the "sub-object" pointed to

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-11 Thread Bill Wendling via cfe-commits
@@ -26996,18 +26996,38 @@ class, structure, array, or other object. Arguments: "" -The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a -pointer to or into the ``object``. The second argument determines whether -``llvm.objectsize`` returns 0

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-11 Thread Bill Wendling via cfe-commits
@@ -26996,18 +26996,38 @@ class, structure, array, or other object. Arguments: "" -The ``llvm.objectsize`` intrinsic takes four arguments. The first argument is a -pointer to or into the ``object``. The second argument determines whether -``llvm.objectsize`` returns 0

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-11 Thread Bill Wendling via cfe-commits
bwendling wrote: Another ping. https://github.com/llvm/llvm-project/pull/83204 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-05 Thread Bill Wendling via cfe-commits
bwendling wrote: Friendly ping. https://github.com/llvm/llvm-project/pull/83204 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-02-27 Thread Bill Wendling via cfe-commits
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/83204 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-02-27 Thread Bill Wendling via cfe-commits
bwendling wrote: The first PR attempt was here: https://github.com/llvm/llvm-project/pull/78526 It was NACK'ed because it used the LLVM IR representation of the structure, which wasn't appropriate. To solve that issue, I chose to expand the `llvm.objectsize()` builtin to contain the size and

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-21 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/82432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-21 Thread Bill Wendling via cfe-commits
https://github.com/bwendling approved this pull request. https://github.com/llvm/llvm-project/pull/82432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] 7fa8585 - [NFC][clang] Remove trailing whitespaces

2024-02-21 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2024-02-21T12:21:35-08:00 New Revision: 7fa8585fdefd98dd73940c74165aa55da1175f02 URL: https://github.com/llvm/llvm-project/commit/7fa8585fdefd98dd73940c74165aa55da1175f02 DIFF: https://github.com/llvm/llvm-project/commit/7fa8585fdefd98dd73940c74165aa55da1175f02.diff

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-02-05 Thread Bill Wendling via cfe-commits
@@ -1051,6 +1052,145 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +/// \p StructBaseExpr returns the base \p Expr with a structure or union

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-02-05 Thread Bill Wendling via cfe-commits
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/80256 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-02-05 Thread Bill Wendling via cfe-commits
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/80256 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-02-05 Thread Bill Wendling via cfe-commits
@@ -1051,6 +1052,145 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +/// \p StructBaseExpr returns the base \p Expr with a structure or union

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-01-31 Thread Bill Wendling via cfe-commits
bwendling wrote: This is a first step in improving our `__bdos` implementation. It doesn't address the "sub-object" discussion from the previous PR (https://github.com/llvm/llvm-project/pull/78526), that will come later on. This patch takes care of a common use of `__bdos` that can't be

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-01-31 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/80256 If we're able to, we convert a call to __builtin_dynamic_object_size into a calculation. This is a cleaner implementation, and has the potential to improve optimizations and, especially, inlining, because

[llvm] [clang] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #78526)

2024-01-31 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/78526 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #78526)

2024-01-25 Thread Bill Wendling via cfe-commits
bwendling wrote: > > ```c > > struct x { > > int a; > > char foo[2][40]; > > int b; > > int c; > > }; > > > > size_t f(struct x *p, int idx) { > > return __builtin_dynamic_object_size(>foo[idx], 1); > > } > > ``` > > If I'm following correctly, the return here is 0, 40, or

[clang] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #78526)

2024-01-24 Thread Bill Wendling via cfe-commits
bwendling wrote: > > maybe we could add the subtype as part of the llvm.objectsize intrinsic and > > use that instead of grappling with the whole object's type > > I'm not sure I follow; if you know the object's type, doesn't that mean you > also know its size? Not necessarily. If you have

  1   2   3   4   5   >