[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] 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] 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 into

[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 https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-c

[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][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] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2024-08-26 Thread Bill Wendling via cfe-commits
bwendling wrote: @rapidsna, what's the status of this PR? If it's bit-rotted, I can try to take over. https://github.com/llvm/llvm-project/pull/70480 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listin

[clang] [Driver][BoundsSafety] Add -fexperimental-bounds-safety flag (PR #70480)

2024-08-26 Thread Bill Wendling via cfe-commits
bwendling wrote: Also, I think there was a PR that added delayed parsing of attributes? Is that correct, or a false memory? :-) https://github.com/llvm/llvm-project/pull/70480 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.

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

2024-07-09 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 01/11] [Clang][objectsize] Generate object size calculation for

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

2024-07-09 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 01/12] [Clang][objectsize] Generate object size calculation for

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

2024-07-09 Thread Bill Wendling via cfe-commits
bwendling wrote: I believe this is ready for another review. 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] [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 https://lists.l

[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 bwendl

[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< + "'count

[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 false

[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 &S, FieldDecl *FD, Expr *E, - llvm::SmallVectorImpl &Decls) { +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
@@ -3282,6 +3282,19 @@ void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, } } +void Parser::DistributeCLateParsedAttrs(Decl *Dcl, +LateParsedAttrList *LateAttrs) { + assert(Dcl); bwendling wrote: Could yo

[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
@@ -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 bwendl

[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< + "'count

[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 false

[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< + "'count

[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 bwendl

[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-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] [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 dis

[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 p

[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 ma

[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-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: https://paste.debian.net/plainh/b192bcd1

[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 s

[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/6] [Clang][objectsize] Generate object size calculation for s

[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 cfe-commits@lists.

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

[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] [Clang] Improve generation of GEP and RecordDecl loop (PR #101434)

2024-07-31 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/101434 As with other loops, we need only look at a RecordDecl's FieldDecls. Convert to using them. In the meantime, we can improve the generation of the 'counted_by' FieldDecl's GEP: create one GEP instead of a seri

[clang] [Clang] Improve generation of GEP and RecordDecl loop (PR #101434)

2024-08-01 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/101434 >From 580fb57202daa5fcfba3e0fdcc50bb3786dc9798 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 31 Jul 2024 16:53:21 -0700 Subject: [PATCH 1/2] [Clang] Improve generation of GEP and RecordDecl loop As

[clang] [Clang] Improve generation of GEP and RecordDecl loop (PR #101434)

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

[clang] c4582a6 - [Analysis] Ignore casts and unary ops for uninitialized values

2021-12-07 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2021-12-07T11:49:18-08:00 New Revision: c4582a689c2c74e0635309979176c7ada086f066 URL: https://github.com/llvm/llvm-project/commit/c4582a689c2c74e0635309979176c7ada086f066 DIFF: https://github.com/llvm/llvm-project/commit/c4582a689c2c74e0635309979176c7ada086f066.diff

[clang] [Clang] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-20 Thread Bill Wendling via cfe-commits
@@ -119,6 +119,10 @@ static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors); +static int parseOverflowPatternExclusionValues

[clang] [Clang] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-20 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/104889 ___ 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-06-24 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/7] [Clang][objectsize] Generate object size calculation for s

[clang] Add documentation for `__builtin_object_size`. (PR #96573)

2024-06-25 Thread Bill Wendling via cfe-commits
bwendling wrote: This LGTM as well. I have a question about the "sub-object" part. Do we attempt to discover the sub-object past any casting? A motivating example: ```c char mux[10][10][10]; printf("%ld\n", __builtin_dynamic_object_size(&((char *)&mux[1][1])[var], 1)); ``` GCC prints `89` (wh

[clang] [Clang] Fix __builtin_dynamic_object_size off by 4 (PR #111015)

2024-10-07 Thread Bill Wendling via cfe-commits
bwendling wrote: > After looking at the assembly produced by gcc more, it actually looks like > it's using the allocation size if it's known in the current context (for > example if the struct was just malloced in the same function) and otherwise > returns INT_MAX for the __bdos of a struct co

[clang] [Clang] Fix __builtin_dynamic_object_size off by 4 (PR #111015)

2024-10-07 Thread Bill Wendling via cfe-commits
bwendling wrote: > So, we would actually get gcc's behavior with this patch: > > ``` > diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp > index c864714182e0..21ffe7b46a6e 100644 > --- a/clang/lib/CodeGen/CGBuiltin.cpp > +++ b/clang/lib/CodeGen/CGBuiltin.cpp > @@ -10

[clang] [Clang][CodeGen] Emit load of value (PR #110487)

2024-09-30 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/110487 We were missing a load of the value after emitting the MemberExpr. This was causing __builtin_dynamic_object_size to return 0 incorrectly. >From 375a71d114fffb94c16455f476364a7de9e08191 Mon Sep 17 00:00:00 20

[clang] [Clang][CodeGen] Emit load of value (PR #110487)

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

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110437)

2024-09-30 Thread Bill Wendling via cfe-commits
bwendling wrote: Thanks for this, but I think the issue is more basic. We should be issuing a "load" instruction after the `EmitMemberExpr` call. (That's what happens outside of using this in `__builtin_dynamic_object_size`.) https://github.com/llvm/llvm-project/pull/110437 ___

[clang] [Clang][CodeGen] Emit load of value (PR #110487)

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

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

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

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-10-01 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/110487 >From 375a71d114fffb94c16455f476364a7de9e08191 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 30 Sep 2024 03:41:15 -0700 Subject: [PATCH 1/3] [Clang][CodeGen] Emit load of value We were missing a loa

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-10-01 Thread Bill Wendling via cfe-commits
bwendling wrote: > @bwendling I think you accidentally compiled the wrong branch. Looks like > that is in `builtin_get_counted_by`, but this PR is in > `bdos-member-expr-error` Yeah, sorry about that. https://github.com/llvm/llvm-project/pull/110487 ___

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110497)

2024-10-07 Thread Bill Wendling via cfe-commits
@@ -1095,6 +1095,8 @@ class StructAccessBase return Visit(E->getBase()); } const Expr *VisitCastExpr(const CastExpr *E) { +if (E->getCastKind() == CK_LValueToRValue) + return E; bwendling wrote: It might be a good sanity check, though I think

[clang] [Clang] Check that we have the correct RecordDecl (PR #111448)

2024-10-07 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/111448 Ensure we have the correct RecordDecl before returning the Expr we're looking for. >From 1936cd507a38d3085fa13016fb40a9a7df35a821 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 7 Oct 2024 15:25:47 -

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110497)

2024-10-07 Thread Bill Wendling via cfe-commits
@@ -1095,6 +1095,8 @@ class StructAccessBase return Visit(E->getBase()); } const Expr *VisitCastExpr(const CastExpr *E) { +if (E->getCastKind() == CK_LValueToRValue) + return E; bwendling wrote: See https://github.com/llvm/llvm-project/pull/11

[clang] [Clang] Check that we have the correct RecordDecl (PR #111448)

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

[clang] [Clang] Fix __builtin_dynamic_object_size off by 4 (PR #111015)

2024-10-07 Thread Bill Wendling via cfe-commits
bwendling wrote: > > This is why I believe the gcc behavior is correct. When it knows the size > > given to `malloc` it uses that. When it doesn't know that it simply returns > > INT_MAX. When you ask gcc for the `__bdos` of the FAM it will use the > > `count` to calculate the size. > > (nit:

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

2024-10-16 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/112636 The whole struct is specificed in the __bdos. The calculation of the whole size of the structure can be done in two ways: 1) sizeof(struct S) + count * sizeof(typeof(fam)) 2) offsetof(struct S, fam) +

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

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

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

2024-10-17 Thread Bill Wendling via cfe-commits
@@ -1013,6 +1013,24 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, // Can't find the field referenced by the "counted_by" attribute. return nullptr; + if (isa(Base)) bwendling wrote: It's possibly a bug, but we current

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

2024-10-17 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/112636 >From d3c689f5b0ece80eba784afe67e3412e2dc6d595 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 16 Oct 2024 17:03:23 -0700 Subject: [PATCH 1/2] [Clang] Disable use of the counted_by attribute for whole

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

2024-10-17 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/112636 >From d3c689f5b0ece80eba784afe67e3412e2dc6d595 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 16 Oct 2024 17:03:23 -0700 Subject: [PATCH 1/2] [Clang] Disable use of the counted_by attribute for whole

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

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

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-10-01 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/110487 >From 375a71d114fffb94c16455f476364a7de9e08191 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 30 Sep 2024 03:41:15 -0700 Subject: [PATCH 1/2] [Clang][CodeGen] Emit load of value We were missing a loa

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-10-01 Thread Bill Wendling via cfe-commits
bwendling wrote: I reverted my last commit. This leaves the original patch, which seems to work. @efriedma-quic, would you be okay with this patch while I work to improve the code in follow-up? https://github.com/llvm/llvm-project/pull/110487 ___ cfe

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-10-01 Thread Bill Wendling via cfe-commits
bwendling wrote: > > I reverted my last commit. This leaves the original patch, which seems to > > work. @efriedma-quic, would you be okay with this patch while I work to > > improve the code in follow-up? > > The original (and current) patch in this PR still introduces a regression. So > it

[clang] [Clang] Fix __builtin_dynamic_object_size off by 4 (PR #111015)

2024-10-03 Thread Bill Wendling via cfe-commits
bwendling wrote: I wrote a similar conclusion to @efriedma-quic in the email thread. The problem with your example is that, in the absence of the `counted_by` attribute, the `__builtin_dynamic_object_size` uses the `alloc_size` attribute that's implicit on the `malloc` call. https://github.co

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-04 Thread Bill Wendling via cfe-commits
@@ -13,7 +13,10 @@ void init(void * __attribute__((pass_dynamic_object_size(0; // CHECK-LABEL: define dso_local void @_ZN3foo3barC1Ev( // CHECK-SAME: ptr noundef nonnull align 4 dereferenceable(1) [[THIS:%.*]]) unnamed_addr #[[ATTR0:[0-9]+]] align 2 { // CHECK-NEXT: entr

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-04 Thread Bill Wendling via cfe-commits
bwendling wrote: -ast-print testcase added. https://github.com/llvm/llvm-project/pull/114495 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-04 Thread Bill Wendling via cfe-commits
@@ -4914,3 +4914,9 @@ def ArithmeticFence : LangBuiltin<"ALL_LANGUAGES"> { let Attributes = [CustomTypeChecking, Constexpr]; let Prototype = "void(...)"; } + +def CountedByRef : Builtin { + let Spellings = ["__builtin_counted_by_ref"]; + let Attributes = [NoThrow, CustomT

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-04 Thread Bill Wendling via cfe-commits
@@ -16,6 +16,8 @@ void test1(struct fam_struct *ptr, int size, int idx) { *__builtin_counted_by_ref(ptr->array) = size; // ok *__builtin_counted_by_ref(&ptr->array[idx]) = size; // ok + *__builtin_counted_by_ref(&ptr->array) = size;// ok

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-04 Thread Bill Wendling via cfe-commits
@@ -0,0 +1,182 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86_64 +// RUN: %clang_cc1 -triple i386-unknown-unknown

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-04 Thread Bill Wendling via cfe-commits
@@ -16,6 +16,8 @@ void test1(struct fam_struct *ptr, int size, int idx) { *__builtin_counted_by_ref(ptr->array) = size; // ok *__builtin_counted_by_ref(&ptr->array[idx]) = size; // ok + *__builtin_counted_by_ref(&ptr->array) = size;// ok

[clang] [Clang] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-10-30 Thread Bill Wendling via cfe-commits
@@ -197,6 +197,18 @@ static bool CanElideOverflowCheck(const ASTContext &Ctx, const BinOpInfo &Op) { if (!Op.mayHaveIntegerOverflow()) return true; + if (Op.Ty->isSignedIntegerType() && bwendling wrote: Does this (and the following if-then) need a com

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-11-01 Thread Bill Wendling via cfe-commits
bwendling wrote: @AaronBallman @rapidsna -- I think I covered all of the comments you made on the other PR (stupid git!). PTAL. https://github.com/llvm/llvm-project/pull/114495 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm

[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

2024-10-31 Thread Bill Wendling via cfe-commits
bwendling wrote: This is a new PR, because GitHub messed up. Here's the original: https://github.com/llvm/llvm-project/pull/102549 https://github.com/llvm/llvm-project/pull/114495 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.l

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-09-30 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/110487 >From 375a71d114fffb94c16455f476364a7de9e08191 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 30 Sep 2024 03:41:15 -0700 Subject: [PATCH 1/2] [Clang][CodeGen] Emit load of value We were missing a loa

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-09-30 Thread Bill Wendling via cfe-commits
bwendling wrote: > > If I return the LValueToRValue cast and run EmitLValue on it > > I'm surprised EmitLValue didn't error out on that. The result of an > LValueToRValue cast is an rvalue. Calling EmitPointerWithAlignment on it > should work, I think. > > > I understand, but there are ~30 di

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

2024-09-30 Thread Bill Wendling via cfe-commits
bwendling wrote: > This is sort of the same comment I've made on other related patches... but I > think the fundamental issue here is that StructAccessBase is skipping over > CK_LValueToRValue casts. Once you jump over such a cast, you're looking at > expressions which are at a different level

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110497)

2024-10-02 Thread Bill Wendling via cfe-commits
bwendling wrote: The problem we're faced with here is that the `Base` pointer could point to anywhere within the structure. We already jump through several hoops to get the flexible array member's `Decl` and the counter's `Decl`. So because `Base` could be a pointer to anywhere in the struct,

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110497)

2024-10-02 Thread Bill Wendling via cfe-commits
@@ -10,6 +10,7 @@ // //===--===// +#include bwendling wrote: Please don't include this (I know it's left from debugging). If you want to debug things, you can use: ```c++ llvm::errs() <<

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110497)

2024-10-02 Thread Bill Wendling via cfe-commits
https://github.com/bwendling approved this pull request. Thanks for the patch! https://github.com/llvm/llvm-project/pull/110497 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Fix 'counted_by' for nested struct pointers (PR #110497)

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

[clang] [Clang][CodeGen] Emit load of GEP after EmitMemberExpr (PR #110487)

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

[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

2024-10-25 Thread Bill Wendling via cfe-commits
bwendling wrote: I think the calculation in https://github.com/llvm/llvm-project/pull/112636#issuecomment-2436559387 is correct. It's probably worthwhile to perform some analysis to see if using that to calculate the new size results in allocation size changes in the kernel. If not, then perh

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

2024-10-15 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed 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] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-27 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/116719 >From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 15 Nov 2024 15:41:48 -0800 Subject: [PATCH 1/9] [Clang] Improve Sema diagnostic performance for __builtin

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

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

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

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

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-18 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/116719 Implement the sema checks with a placeholder. We then check for that placeholder in all of the places we care to emit a diagnostic. Fixes: #115520 >From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 0

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via cfe-commits
bwendling wrote: > The main thing I’m concerned about here is that I feel like there ought to be > a better way of doing this than checking for and disallowing it in every > place where we can have a subexpression in C. Yeah, but we don't have such a method, partially due to the languages Clan

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via cfe-commits
bwendling wrote: > > Could you point to a place in the code where it creates a placeholder? > > I mean, e.g. `CheckPointerToMemberOperands()` can return `BoundMemberTy` as > the type of a `.*` expression, and `CreateBuiltinMatrixSubscriptExpr()` > creates a `MatrixSubscriptExpr` with type `Inc

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/116719 >From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 15 Nov 2024 15:41:48 -0800 Subject: [PATCH 1/7] [Clang] Improve Sema diagnostic performance for __builtin

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/116719 >From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 15 Nov 2024 15:41:48 -0800 Subject: [PATCH 1/6] [Clang] Improve Sema diagnostic performance for __builtin

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/116719 >From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 15 Nov 2024 15:41:48 -0800 Subject: [PATCH 1/5] [Clang] Improve Sema diagnostic performance for __builtin

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/116719 >From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 15 Nov 2024 15:41:48 -0800 Subject: [PATCH 1/4] [Clang] Improve Sema diagnostic performance for __builtin

[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-19 Thread Bill Wendling via cfe-commits
bwendling wrote: > Hmm, I don’t think this is the right way of going about it—copy-pasting the > check across 6 or so different places seems like it’s missing the point of > using a placeholder in the first place. Could you point to a place in the code where it creates a placeholder? I'm unab

<    1   2   3   4   5   6   7   8   >