[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Bill Wendling via cfe-commits
@@ -293,6 +293,40 @@ To silence reports from unsigned integer overflow, you can set ``-fsanitize-recover=unsigned-integer-overflow``, is particularly useful for providing fuzzing signal without blowing up logs. +Disabling instrumentation for common overflow patterns +

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-08 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/102549 The __builtin_get_counted_by builtin is used on a flexible array pointer and returns a pointer to the "counted_by" attribute's COUNT argument, which is a field in the same non-anonymous struct as the flexible a

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

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

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-08 Thread Bill Wendling via cfe-commits
bwendling wrote: There's still some cleanup to do. Firstly, the code to get the `MemberExpr` for the flexible array member. It's sloppy. https://github.com/llvm/llvm-project/pull/102549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://l

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-08 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/102549 >From 7ba43ae2b737fbd868848a23b58b3965f8d36ce1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 6 Aug 2024 17:49:01 -0700 Subject: [PATCH 1/8] [WIP][Clang] Add __builtin_get_counted_by builtin The __bu

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-08 Thread Bill Wendling via cfe-commits
bwendling wrote: > I'd expect some kind of diagnostic when the specified field doesn't have a > corresponding counted_by field. So there's a complication with that. The use case for this builtin is to automatically set the `count` field during allocation in the Linux kernel. (It could be used

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-08 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/102549 >From 7ba43ae2b737fbd868848a23b58b3965f8d36ce1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 6 Aug 2024 17:49:01 -0700 Subject: [PATCH 1/9] [WIP][Clang] Add __builtin_get_counted_by builtin The __bu

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-09 Thread Bill Wendling via cfe-commits
bwendling wrote: > So the idea here is that if the struct in question uses counted_by, you > automatically set the count... and if, for whatever reason, the compiler > can't find the corresponding field, you just throw away the count? That seems > like an terrifying API; it's impossible to pre

[clang] [WIP][Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-09 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/102549 >From 7ba43ae2b737fbd868848a23b58b3965f8d36ce1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 6 Aug 2024 17:49:01 -0700 Subject: [PATCH 01/10] [WIP][Clang] Add __builtin_get_counted_by builtin The __

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-09 Thread Bill Wendling via cfe-commits
@@ -4759,6 +4759,55 @@ ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx, return new (Mem) ParenListExpr(EmptyShell(), NumExprs); } +namespace { bwendling wrote: You don't need both an anonymous namespace and marking the function 'static'. I

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

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

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

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

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

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

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-12 Thread Bill Wendling via cfe-commits
bwendling wrote: I removed the WIP and updated the description. I'll look into adding some more diagnostics. https://github.com/llvm/llvm-project/pull/102549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailma

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-12 Thread Bill Wendling via cfe-commits
@@ -649,6 +649,8 @@ class alignas(void *) Stmt { /// It is 0 otherwise. LLVM_PREFERRED_TYPE(bool) unsigned HasFPFeatures : 1; +LLVM_PREFERRED_TYPE(bool) bwendling wrote: Nit: Newline and maybe a comment? https://github.com/llvm/llvm-project/pu

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-13 Thread Bill Wendling via cfe-commits
bwendling wrote: > Hmm, I could see how this could be useful, but it seems like a rather niche > use case. > > @AaronBallman Should this go through the ususal process of someone writing an > RFC for it seeing as it is a language extension? I'll be happy to open this up to the larger community

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-13 Thread Bill Wendling via cfe-commits
@@ -537,15 +537,21 @@ class Expr : public ValueStmt { /// semantically correspond to a bool. bool isKnownToHaveBooleanValue(bool Semantic = true) const; - /// Check whether this array fits the idiom of a flexible array member, - /// depending on the value of -fstrict-fle

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

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

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-13 Thread Bill Wendling via cfe-commits
@@ -4774,3 +4774,9 @@ def ArithmeticFence : LangBuiltin<"ALL_LANGUAGES"> { let Attributes = [CustomTypeChecking, Constexpr]; let Prototype = "void(...)"; } + +def GetCountedBy : Builtin { + let Spellings = ["__builtin_get_counted_by"]; + let Attributes = [NoThrow]; + let

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-13 Thread Bill Wendling via cfe-commits
bwendling wrote: Thanks! @efriedma-quic anymore comments? https://github.com/llvm/llvm-project/pull/100272 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang][NFC] Move FindCountedByField into FieldDecl (PR #104235)

2024-08-14 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/104235 FindCountedByField can be used in more places than CodeGen. Move it into FieldDecl to avoid layering issues. >From a87bc65687b687073e8ff37606ca9e783f1edcf9 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date:

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-14 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/102549 >From 7ba43ae2b737fbd868848a23b58b3965f8d36ce1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Tue, 6 Aug 2024 17:49:01 -0700 Subject: [PATCH 01/11] [WIP][Clang] Add __builtin_get_counted_by builtin The __

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-14 Thread Bill Wendling via cfe-commits
@@ -222,6 +222,49 @@ bool Expr::isFlexibleArrayMemberLike( IgnoreTemplateOrMacroSubstitution); } +namespace { + +/// MemberExprVisitor - Find the MemberExpr through all of the casts, array +/// subscripts, and unary ops. This intentiona

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-14 Thread Bill Wendling via cfe-commits
@@ -4678,6 +4678,19 @@ void FieldDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const { DeclaratorDecl::printName(OS, Policy); } +const FieldDecl *FieldDecl::FindCountedByField() const { + const auto *CAT = getType()->getAs(); + if (!CAT) +return nullp

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-14 Thread Bill Wendling via cfe-commits
@@ -6590,8 +6590,34 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc, return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy, VK_PRValue, RParenLoc, CurFPFeatureOverrides()); } - return BuildResol

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

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

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-14 Thread Bill Wendling via cfe-commits
@@ -222,6 +222,49 @@ bool Expr::isFlexibleArrayMemberLike( IgnoreTemplateOrMacroSubstitution); } +namespace { + +/// MemberExprVisitor - Find the MemberExpr through all of the casts, array +/// subscripts, and unary ops. This intentiona

[clang] [Clang] Add __builtin_get_counted_by builtin (PR #102549)

2024-08-14 Thread Bill Wendling via cfe-commits
https://github.com/bwendling commented: I made changes to use the CustomTypeChecking for the builtin. PTAL https://github.com/llvm/llvm-project/pull/102549 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/l

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Bill Wendling via cfe-commits
bwendling wrote: > @efriedma-quic > > > I think serialization is missing for the new bit on BinaryOperator. > > How do I add this? > > > I'm not sure why we're storing it in the first place, though; it's queried > > in exactly one place, so there isn't really any benefit to precomputing it. >

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

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

[clang] 7275919 - Use clang_cc1 and specify the target explicitly.

2024-08-14 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2024-08-14T17:46:30-07:00 New Revision: 7275919cd5fc89c42a52168c9f4411b4e5421c95 URL: https://github.com/llvm/llvm-project/commit/7275919cd5fc89c42a52168c9f4411b4e5421c95 DIFF: https://github.com/llvm/llvm-project/commit/7275919cd5fc89c42a52168c9f4411b4e5421c95.diff

[clang] 5873aa8 - Remove '-emit-llvm' and use '-triple'

2024-08-14 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2024-08-14T17:49:34-07:00 New Revision: 5873aa83b871393b5ada4c2033445d5fd52d7461 URL: https://github.com/llvm/llvm-project/commit/5873aa83b871393b5ada4c2033445d5fd52d7461 DIFF: https://github.com/llvm/llvm-project/commit/5873aa83b871393b5ada4c2033445d5fd52d7461.diff

[clang] 6e2d9df - Fix testcases. Use -emit-llvm and not -S. Use LABEL checking.

2024-08-14 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2024-08-14T22:14:29-07:00 New Revision: 6e2d9df02502e16659e4a9397260baf9df224f17 URL: https://github.com/llvm/llvm-project/commit/6e2d9df02502e16659e4a9397260baf9df224f17 DIFF: https://github.com/llvm/llvm-project/commit/6e2d9df02502e16659e4a9397260baf9df224f17.diff

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Bill Wendling via cfe-commits
bwendling wrote: Hopefully 6e2d9df02502 fixes the buildbots. I think we should using update_cc_test_checks.py to generate these testcases though. https://github.com/llvm/llvm-project/pull/100272 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Clang][NFC] Move FindCountedByField into FieldDecl (PR #104235)

2024-08-14 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/104235 >From a87bc65687b687073e8ff37606ca9e783f1edcf9 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 14 Aug 2024 13:44:56 -0700 Subject: [PATCH 1/2] [Clang][NFC] Move FindCountedByField into FieldDecl FindC

[clang] [Clang][NFC] Move FindCountedByField into FieldDecl (PR #104235)

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

[clang] 07a8cba - Remove failing test until it can be fixed properly.

2024-08-14 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2024-08-14T22:51:26-07:00 New Revision: 07a8cbaf8dc16bebf6e875173d20299d9cc47cc5 URL: https://github.com/llvm/llvm-project/commit/07a8cbaf8dc16bebf6e875173d20299d9cc47cc5 DIFF: https://github.com/llvm/llvm-project/commit/07a8cbaf8dc16bebf6e875173d20299d9cc47cc5.diff

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Bill Wendling via cfe-commits
bwendling wrote: I removed it temporarily. https://github.com/llvm/llvm-project/pull/100272 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] a2830d6 - Revert "Remove empty line."

2024-08-15 Thread Bill Wendling via cfe-commits
Author: Bill Wendling Date: 2024-08-15T02:34:04-07:00 New Revision: a2830d6aa2e8ad0da0e58f1642ed09723602e838 URL: https://github.com/llvm/llvm-project/commit/a2830d6aa2e8ad0da0e58f1642ed09723602e838 DIFF: https://github.com/llvm/llvm-project/commit/a2830d6aa2e8ad0da0e58f1642ed09723602e838.diff

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-15 Thread Bill Wendling via cfe-commits
bwendling wrote: @vitalybuka Are they still broken? Which ones? https://github.com/llvm/llvm-project/pull/100272 ___ 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] [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] 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 changi

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

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

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

[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, &LateFieldAttrs); + + as

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

2024-05-29 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-29 Thread Bill Wendling via cfe-commits
@@ -1062,6 +1063,159 @@ 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-29 Thread Bill Wendling via cfe-commits
@@ -1062,6 +1063,159 @@ 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-29 Thread Bill Wendling via cfe-commits
@@ -1062,6 +1063,159 @@ 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-29 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] [Clang][objectsize] Generate object size calculation for sub-objects (PR #86858)

2024-05-29 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-29 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-29 Thread Bill Wendling via cfe-commits
@@ -1062,6 +1063,159 @@ 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-31 Thread Bill Wendling via cfe-commits
@@ -1062,6 +1063,160 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned)); } +namespace { + +class ObjectSizeVisitor +: public ConstStmtVisitor { + ASTContext &Ctx;

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

2024-05-31 Thread Bill Wendling via cfe-commits
@@ -1062,6 +1063,159 @@ 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] [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 &VarName, OS << " }\n"; } +enum class LateAttrParseKind { Never = 0, Always = 1, ExperimentalOnly = 2 }; + +static LateAttrParseKind getLateAttrParseKind(const Record *Attr) { + // This function b

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

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

[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
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 * __attribute__((p

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

[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-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,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 cou

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

[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] 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 &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) { const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel = getLangOpts().getStrictFlexArraysLe

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

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

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

[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 = dyn_cast(Bas

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

[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/ https://github.com/llvm/llvm-project/pull/86

[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) { op.RHS->getType()->isPointerTy()) return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction); + if ((op.Ty->isSignedIntegerOrEnumerationType() || bwendling w

[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: How

[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 &CI, Expr *E) { D->addAttr(::new (Context) AlignValueAttr(Context, CI, E)); } +static void handleWrapsAttr(Sema &S, Decl *D, const ParsedAttr &AL) { + S.AddWrapsAttr(D, AL); +} + +void S

[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
@@ -4249,6 +4270,10 @@ Value *ScalarExprEmitter::EmitFixedPointBinOp(const BinOpInfo &op) { Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) { // The LHS is always a pointer if either side is. if (!op.LHS->getType()->isPointerTy()) { +if ((op.Ty->isSignedIntegerO

[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][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] Ignore empty FieldDecls when asking for the field number (PR #100040)

2024-07-23 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/100040 ___ 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-07-25 Thread Bill Wendling via cfe-commits
bwendling wrote: > As a matter of ensuring the behavior is predictable, I don't like > IgnoreParenImpCasts(), and more generally looking through casts without > checking the CastKind; it very easily leads to bugs because some casts have > important semantics. Particularly lvalue-to-rvalue cast

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

2024-07-18 Thread Bill Wendling via cfe-commits
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/99574 Only FieldDecls are important when determining GEP indices. 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 RecordDecl

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

2024-07-18 Thread Bill Wendling via cfe-commits
https://github.com/bwendling updated https://github.com/llvm/llvm-project/pull/99574 >From f907be4ed6189729dd2546d597dd003a5edb1006 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 18 Jul 2024 14:32:41 -0700 Subject: [PATCH 1/2] [Clang] Loop over FieldDecls instead of all Decls Only Fie

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

2024-07-18 Thread Bill Wendling via cfe-commits
https://github.com/bwendling closed https://github.com/llvm/llvm-project/pull/99574 ___ 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 #99574)

2024-07-22 Thread Bill Wendling via cfe-commits
bwendling wrote: Okay. I'll look into it. On Sun, Jul 21, 2024 at 4:35 PM Nathan Chancellor ***@***.***> wrote: > I see a crash in drivers/thermal/thermal_core.c in Linux kernels without > commit daeeb032f42d > > ("thermal:

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

2024-07-22 Thread Bill Wendling via cfe-commits
bwendling wrote: +Eli Friedman ***@***.***> I'm confused by what's going on. Here's a shorter testcase: struct a {}; struct c { int done; struct a x; }; struct b { struct a y; int s; int x[] __attribute__((counted_by(s))); }; int foo(struct b *p, int idx) { return __builtin_dynam

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

2024-07-22 Thread Bill Wendling via cfe-commits
bwendling wrote: So is it enough to test if the FieldDecl exists in the CGRecordLayout before asking for the FieldNo? When I do that, there are some other subtle changes that occur, though maybe those are from other changes... https://github.com/llvm/llvm-project/pull/99574 ___

<    1   2   3   4   5   6   7   >