11 Commits

Author SHA1 Message Date
Vladimir Vuksanovic
a17b5bce8c
[clang-reorder-fields] Prevent rewriting unsupported cases (#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 created from a single macro expansion
- Preprocessor directives are present in the struct
2025-06-22 19:00:11 -07:00
Vladimir Vuksanovic
34c85ed2bc
[clang-reorder-fields] Use expanded location for macros (#142147)
Fixes macros being replaced instead of their expansion.

Closes #52632
2025-06-15 18:07:51 -04:00
Clement Courbet
fbd86d05fe
[clang-reorder-fields] Reorder leading comments (#123740)
Similarly to https://github.com/llvm/llvm-project/pull/122918, leading
comments are currently not being moved.

```
struct Foo {
  // This one is the cool field.
  int a;
  int b;
};
```

becomes:

```
struct Foo {
  // This one is the cool field.
  int b;
  int a;
};
```

but should be:

```
struct Foo {
  int b;
  // This one is the cool field.
  int a;
};
```
2025-01-22 13:42:00 +01:00
Clement Courbet
6affc18375
[clang-reorder-fields] Move trailing comments. (#122918)
Currently, trailing comments get mixed up:

```
struct Foo {
  int a; // This one is the cool field
         // within the struct.
  int b;
};
```

becomes:

```
struct Foo {
  int b; // This one is the cool field
         // within the struct.
  int a;
};
```

This should be:

```
struct Foo {
  int b;
  int a; // This one is the cool field
         // within the struct.
};
```
2025-01-15 13:07:42 +01:00
Clement Courbet
91285e26bf
[clang-reorder-fields] Handle macros fields declarations. (#118005)
Right now fields with macro declarations break the tool:

```

struct Foo {
  Mutex mu;
  int x GUARDED_BY(mu);
  int y;
};
```

reordered by mu,y,x yields:

```
struct Foo {
  Mutex mu;
  int y GUARDED_BY(mu);
  int x;
};
```
2024-11-29 08:36:22 +01:00
Aaron Ballman
27d39e4da0 Use function prototypes when appropriate; NFC
This prepares the clang-tools-extra project for -Wstrict-prototypes
being enabled by default.
2022-02-25 09:08:27 -05:00
Alexander Shaposhnikov
b687fdda29 [clang-reorder-fields] Emit warning when reordering breaks member init list dependencies
This diff adds a warning emitted by clang-reorder-fields 
when reordering breaks dependencies in the initializer list.

Patch by Sam Conrad!

Differential revision: https://reviews.llvm.org/D35972

llvm-svn: 309505
2017-07-30 06:43:03 +00:00
Alexander Shaposhnikov
eaf833ca2b [clang-tools-extra] Add support for plain C structs in clang-reorder-fields
This diff updates the tool clang-reorder-fields
to enable reordering of fields of plain C structs.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D35329

llvm-svn: 308678
2017-07-20 21:41:20 +00:00
Alexander Shaposhnikov
bf3c84cff7 Add clang-reorder-fields to clang-tools-extra
This diff adds v0 of clang-reorder-fields tool to clang/tools/extra.
The main idea behind this tool is to simplify and make less error-prone refactoring of large codebases when
someone needs to change the order fields of a struct/class (for example to remove excessive padding).

Differential revision: https://reviews.llvm.org/D23279

llvm-svn: 280456
2016-09-02 02:56:07 +00:00
Alexander Shaposhnikov
3efddd22b9 Revert https://reviews.llvm.org/D23279 because the tests have failed on several platforms
llvm-svn: 280438
2016-09-02 00:24:06 +00:00
Alexander Shaposhnikov
ae4ff453a4 Add clang-reorder-fields to clang-tools-extra
This diff adds v0 of clang-reorder-fields tool to clang/tools/extra.
The main idea behind this tool is to simplify and make less error-prone refactoring of large codebases when
someone needs to change the order fields of a struct/class (for example to remove excess padding).

Differential revision: https://reviews.llvm.org/D23279

llvm-svn: 280431
2016-09-01 23:49:48 +00:00