vvuksanovic wrote:
Added `InitializerListExcessElements.c` and `IdiomaticZeroInitializer.c` tests.
I can't find test cases for non constant-sized arrays in structs. I would
change those checks for asserts, but there might be some way to trigger that,
that I d
vvuksanovic wrote:
There have been a couple of issues raised about the `-Walloc-size` diagnostic
being emitted for allocations of size zero:
- https://github.com/llvm/llvm-project/pull/150028#issuecomment-3228599602
- https://github.com/llvm/llvm-project/issues/155633
I think it makes sense to
https://github.com/vvuksanovic created
https://github.com/llvm/llvm-project/pull/155793
Allocations of size zero are usually done intentionally and then reallocated
before use.
>From cbfe5c017190ea3f7cbcc458845656ba4eef8d54 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Thu, 28 Aug
vvuksanovic wrote:
I think I will add an exception for zero size allocations. That is likely done
on purpose and that change should eliminate a lot of the noise.
For the `pykdtree` case, that code is a bit questionable as it relies on not
using a part of a structure. I think that emitting a wa
vvuksanovic wrote:
Updated to fix test on windows. Can you merge? CI failure seems to be unrelated
to this PR.
https://github.com/llvm/llvm-project/pull/150028
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mail
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150028
>From 1f03a09bac08c70183d2a04fcbced83179cad414 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Mon, 7 Jul 2025 06:17:19 -0700
Subject: [PATCH 1/6] [clang] Implement -Walloc-size diagnostic option
W
vvuksanovic wrote:
Thanks for the review. Can someone merge this for me when the CI finishes? The
formatting error is due to the indentation of existing code in `Expr.h`.
https://github.com/llvm/llvm-project/pull/150028
___
cfe-commits mailing list
cf
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150028
>From 1f03a09bac08c70183d2a04fcbced83179cad414 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Mon, 7 Jul 2025 06:17:19 -0700
Subject: [PATCH 1/5] [clang] Implement -Walloc-size diagnostic option
W
@@ -3542,6 +3542,56 @@ bool CallExpr::isBuiltinAssumeFalse(const ASTContext
&Ctx) const {
Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && !ArgVal;
}
+const AllocSizeAttr *CallExpr::getCalleeAllocSizeAttr() const {
+ if (const FunctionDecl *DirectCallee = getDirectCa
vvuksanovic wrote:
Thank you for the suggestions, the code looks cleaner now. I don't see any new
comments?
https://github.com/llvm/llvm-project/pull/142150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142150
>From 69381c74c9c3adf97770cdd2e72f0bd8d862e33c Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Tue, 22 Jul 2025 02:50:02 -0700
Subject: [PATCH 1/3] [clang-reorder-fields] Refactor the new order info
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150028
>From 1f03a09bac08c70183d2a04fcbced83179cad414 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Mon, 7 Jul 2025 06:17:19 -0700
Subject: [PATCH 1/5] [clang] Implement -Walloc-size diagnostic option
W
vvuksanovic wrote:
Ping
https://github.com/llvm/llvm-project/pull/142150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
vvuksanovic wrote:
Had to update to fix conflicts. Can you merge?
https://github.com/llvm/llvm-project/pull/150025
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150025
>From 118f0c1aff19b7e9db01da349e3089846afd015d Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 11 Jul 2025 04:14:43 -0700
Subject: [PATCH 1/4] [Sema] Fix false positive warnings for misaligned
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150025
>From 118f0c1aff19b7e9db01da349e3089846afd015d Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 11 Jul 2025 04:14:43 -0700
Subject: [PATCH 1/2] [Sema] Fix false positive warnings for misaligned
@@ -6765,6 +6762,10 @@ class Sema final : public SemaBase {
/// InLifetimeExtendingContext is true.
SmallVector ForRangeLifetimeExtendTemps;
+/// Small set of gathered accesses to potentially misaligned members
+/// due to the packed attribute.
+SmallVector
@@ -15529,11 +15528,13 @@ void Sema::CheckArgumentWithTypeTag(const
ArgumentWithTypeTagAttr *Attr,
void Sema::AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl
*MD,
CharUnits Alignment) {
- MisalignedMembers.emplace_ba
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150025
>From 118f0c1aff19b7e9db01da349e3089846afd015d Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 11 Jul 2025 04:14:43 -0700
Subject: [PATCH] [Sema] Fix false positive warnings for misaligned memb
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Walloc-size %s
+struct Foo { int x[10]; };
+
+typedef __typeof__(sizeof(int)) size_t;
+void *my_malloc(size_t) __attribute__((alloc_size(1)));
+void *my_calloc(size_t, size_t) __attribute__((alloc_size(2, 1)));
+
+void fo
@@ -7818,6 +7819,35 @@ ExprResult Sema::CheckExtVectorCast(SourceRange R,
QualType DestTy,
return prepareVectorSplat(DestTy, CastExpr);
}
+/// Check that a call to alloc_size function specifies sufficient space for the
+/// destination type.
+static void CheckSufficientAllo
@@ -932,6 +932,20 @@ An example of how to use ``alloc_size``
assert(__builtin_object_size(a, 0) == 100);
}
+When ``-Walloc-size`` is enabled, this attribute allows the compiler to
+diagnose cases when the allocated memory is insufficient for the size of the
+type the ret
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150028
>From 1f03a09bac08c70183d2a04fcbced83179cad414 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Mon, 7 Jul 2025 06:17:19 -0700
Subject: [PATCH 1/4] [clang] Implement -Walloc-size diagnostic option
W
@@ -3256,6 +3257,14 @@ class CallExpr : public Expr {
setDependence(getDependence() | ExprDependence::TypeValueInstantiation);
}
+ /// Try to get the alloc_size attribute of the callee. May return null.
+ const AllocSizeAttr *getAllocSizeAttr() const;
@@ -3256,6 +3257,14 @@ class CallExpr : public Expr {
setDependence(getDependence() | ExprDependence::TypeValueInstantiation);
}
+ /// Try to get the alloc_size attribute of the callee. May return null.
+ const AllocSizeAttr *getAllocSizeAttr() const;
+
+ /// Get the
@@ -717,6 +717,10 @@ Improvements to Clang's diagnostics
Added a new warning in this group for the case where the attribute is
missing/implicit on
an override of a virtual method.
+- A new warning ``-Walloc-size`` has been added to detect calls to functions
+ decorated w
@@ -717,6 +717,10 @@ Improvements to Clang's diagnostics
Added a new warning in this group for the case where the attribute is
missing/implicit on
an override of a virtual method.
+- A new warning ``-Walloc-size`` has been added to detect calls to functions
--
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/150028
>From 1f03a09bac08c70183d2a04fcbced83179cad414 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Mon, 7 Jul 2025 06:17:19 -0700
Subject: [PATCH 1/3] [clang] Implement -Walloc-size diagnostic option
W
@@ -15534,17 +15534,28 @@ void Sema::AddPotentialMisalignedMembers(Expr *E,
RecordDecl *RD, ValueDecl *MD,
MisalignedMembers.emplace_back(E, RD, MD, Alignment);
}
-void Sema::DiagnoseMisalignedMembers() {
- for (MisalignedMember &m : MisalignedMembers) {
-const NamedDe
@@ -81,18 +83,52 @@ getNewFieldsOrder(const RecordDecl *Definition,
return NewFieldsOrder;
}
+struct ReorderedStruct {
vvuksanovic wrote:
Okay, I separated the commits.
https://github.com/llvm/llvm-project/pull/142150
__
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142150
>From 69381c74c9c3adf97770cdd2e72f0bd8d862e33c Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Tue, 22 Jul 2025 02:50:02 -0700
Subject: [PATCH 1/2] [clang-reorder-fields] Refactor the new order info
@@ -3684,6 +3684,12 @@ def warn_alloca_align_alignof : Warning<
"second argument to __builtin_alloca_with_align is supposed to be in bits">,
InGroup>;
+def warn_alloc_size
+: Warning<
+ "allocation of insufficient size '%0' for type %1 with size '%2'">,
+
https://github.com/vvuksanovic created
https://github.com/llvm/llvm-project/pull/150028
Warns about calls to functions decorated with attribute `alloc_size` that
specify insufficient size for the type they are cast to. Matches the behavior
of the GCC option of the same name.
Closes #138973
https://github.com/vvuksanovic created
https://github.com/llvm/llvm-project/pull/150025
These warnings are reported on a per expression basis, however some potential
misaligned accesses are discarded before that happens. The problem is when a
new expression starts while processing another expr
vvuksanovic wrote:
ping @legrosbuffle
https://github.com/llvm/llvm-project/pull/142150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -81,18 +83,52 @@ getNewFieldsOrder(const RecordDecl *Definition,
return NewFieldsOrder;
}
+struct ReorderedStruct {
vvuksanovic wrote:
Can you clarify what should I pull to a separate commit? I can create a new
commit for the `ReorderedStruct` changes,
@@ -0,0 +1,256 @@
+//===-- tools/extra/clang-reorder-fields/utils/Designator.cpp ---*- C++
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Ap
@@ -0,0 +1,256 @@
+//===-- tools/extra/clang-reorder-fields/utils/Designator.cpp ---*- C++
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Ap
@@ -289,35 +321,213 @@ static void reorderFieldsInConstructor(
Replacements);
}
+/// Replacement for broken InitListExpr::isExplicit function.
+/// TODO: Remove when InitListExpr::isExplicit is fixed.
vvuksanovic wrote:
Replaced. I can't
@@ -289,35 +321,213 @@ static void reorderFieldsInConstructor(
Replacements);
}
+/// Replacement for broken InitListExpr::isExplicit function.
+/// TODO: Remove when InitListExpr::isExplicit is fixed.
+static bool isImplicitILE(const InitListExpr *ILE, con
vvuksanovic wrote:
Moved to parent directory.
https://github.com/llvm/llvm-project/pull/142150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142150
>From df2e394f94397bf5d371586703a70b8e9bec1aaa Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:37:06 -0700
Subject: [PATCH 1/3] [clang-reorder-fields] Support designated initiali
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142150
>From df2e394f94397bf5d371586703a70b8e9bec1aaa Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:37:06 -0700
Subject: [PATCH 1/2] [clang-reorder-fields] Support designated initiali
vvuksanovic wrote:
@alexander-shaposhnikov
https://github.com/llvm/llvm-project/pull/142150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142149
>From b8481a36b33e71248170c8cc195b45fa9de4f777 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:42:55 -0700
Subject: [PATCH 1/3] [clang-reorder-fields] Prevent rewriting unsupport
@@ -0,0 +1,15 @@
+// RUN: clang-reorder-fields -record-name ::bar::Foo -fields-order y,x %s -- |
FileCheck %s
+
+namespace bar {
+
+#define DEFINE_FIELDS
+
+// This is okay to reorder.
+struct Foo {
+#ifdef DEFINE_FIELDS // CHECK: {{^#ifdef DEFINE_FIELDS}}
+ int y;
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142149
>From b8481a36b33e71248170c8cc195b45fa9de4f777 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:42:55 -0700
Subject: [PATCH 1/2] [clang-reorder-fields] Prevent rewriting unsupport
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142150
>From df2e394f94397bf5d371586703a70b8e9bec1aaa Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:37:06 -0700
Subject: [PATCH] [clang-reorder-fields] Support designated initializers
vvuksanovic wrote:
Thanks for the reviews. Can someone merge this? I don't have commit access.
https://github.com/llvm/llvm-project/pull/142147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-
vvuksanovic wrote:
@legrosbuffle
https://github.com/llvm/llvm-project/pull/142150
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -50,6 +50,55 @@ static const RecordDecl *findDefinition(StringRef RecordName,
return selectFirst("recordDecl", Results);
}
+static bool isSafeToRewrite(const RecordDecl *Decl, const ASTContext &Context)
{
+ // Don't attempt to rewrite if there is a declaration like 'int
@@ -0,0 +1,16 @@
+// RUN: clang-reorder-fields -record-name ::bar::Foo -fields-order z,y,x %s --
| FileCheck %s
vvuksanovic wrote:
Done.
https://github.com/llvm/llvm-project/pull/142149
___
cfe-commits mailing list
cf
https://github.com/vvuksanovic updated
https://github.com/llvm/llvm-project/pull/142149
>From b8481a36b33e71248170c8cc195b45fa9de4f777 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:42:55 -0700
Subject: [PATCH] [clang-reorder-fields] Prevent rewriting unsupported c
vvuksanovic wrote:
@alexander-shaposhnikov
https://github.com/llvm/llvm-project/pull/142147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
vvuksanovic wrote:
@alexander-shaposhnikov
https://github.com/llvm/llvm-project/pull/142149
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/vvuksanovic created
https://github.com/llvm/llvm-project/pull/142147
Fixes macros being replaced instead of their expansion.
Closes #52632
>From 82f35e120d075eb0f55d02ff2a4d750e6e352475 Mon Sep 17 00:00:00 2001
From: Vladimir Vuksanovic
Date: Fri, 30 May 2025 05:41:09 -0700
https://github.com/vvuksanovic created
https://github.com/llvm/llvm-project/pull/142149
Add checks to prevent rewriting when doing so might result in incorrect code.
The following cases are checked:
- There are multiple field declarations in one statement like `int a, b`
- Multiple fields are c
https://github.com/vvuksanovic created
https://github.com/llvm/llvm-project/pull/142150
Initializer lists with designators, missing elements or omitted braces can now
be rewritten. Any missing designators are added and they get sorted according
to the new order.
```
struct Foo {
int a;
in
58 matches
Mail list logo