This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] PR50525 doesn't handle AlignConsecutiveAssignments correctly in some situations
ClosedPublic

Authored by MyDeveloperDay on Jun 25 2021, 2:21 AM.

Details

Summary

https://bugs.llvm.org/show_bug.cgi?id=50525

AlignConsecutiveAssignments/Declarations cause incorrect alignment in the presence of a DesignatedInitializerPeriod (https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html)

static NTSTATUS stg(PLW_STREAM Stream, int identity)
{
     NTSTATUS             status;
     BYTE                 payload[256] = {'l', 'h', 'o', 't', 's', 'e'};
     struct dm_rpc_header header       = {.drh_magic        = DRH_MAGIC,
                                    .drh_op_code      = RPC_OP_ECHO,
                                    .drh_payload_size = sizeof(payload),
                                    .drh_body_size    = sizeof(payload),
                                    .drh_request_id   = 1};
     header.drh_version                = identity;

This fix addresses that by ensuring the period isn't ignored

Diff Detail

Event Timeline

MyDeveloperDay requested review of this revision.Jun 25 2021, 2:21 AM
MyDeveloperDay created this revision.
This revision is now accepted and ready to land.Jun 26 2021, 2:07 AM
This revision was landed with ongoing or failed builds.Jun 26 2021, 5:31 AM
This revision was automatically updated to reflect the committed changes.
darwin added a comment.EditedJun 26 2021, 9:11 AM

Sorry I haven't had a chance to look at this bug before it has closed. But I do have a question:

I observed that this code are formatted incorrectly by the same config:

llvm::Optional<std::string> CurrentCode = None;
auto                        Env = std::make_unique<Environment>(Code,
                                         FileName,
                                         Ranges,
                                         FirstStartColumn,
                                         NextStartColumn,
                                         LastStartColumn);

Can this solution solve this issue? I am afraid not.

If no, should I open a new bug for it?

Sorry I haven't had a chance to look at this bug before it has closed. But I do have a question:

I observed that this code are formatted incorrectly by the same config:

llvm::Optional<std::string> CurrentCode = None;
auto                        Env = std::make_unique<Environment>(Code,
                                         FileName,
                                         Ranges,
                                         FirstStartColumn,
                                         NextStartColumn,
                                         LastStartColumn);

Can this solution solve this issue? I am afraid not.

If no, should I open a new bug for it?

No it doesn't, this change is only about designated initializers.

Sorry I haven't had a chance to look at this bug before it has closed. But I do have a question:

I observed that this code are formatted incorrectly by the same config:

llvm::Optional<std::string> CurrentCode = None;
auto                        Env = std::make_unique<Environment>(Code,
                                         FileName,
                                         Ranges,
                                         FirstStartColumn,
                                         NextStartColumn,
                                         LastStartColumn);

Can this solution solve this issue? I am afraid not.

If no, should I open a new bug for it?

If this is indeed a bug you need to log its, I think it highly unlikey that its related, make sure you include your .clang-format file (and remove non impacting options)

I tested this example and it looked to work correctly (but it depends on your options I suspect):

Language: Cpp
BasedOnStyle: LLVM
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
ColumnLimit: 80
llvm::Optional<std::string> CurrentCode = None;
auto                        Env         = std::make_unique<Environment>(
    Code, FileName, Ranges, FirstStartColumn, NextStartColumn, LastStartColumn);