Skip to content

-Wpadded may be split in two options #22816

@llvmbot

Description

@llvmbot
Bugzilla Link 22442
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @davidstone,@rnk,@seanm,@Trass3r

Extended Description

Hello.

-Wpadded warns about two issues, padding a struct field and padding at the end (i.e: the whole struct). See the example:

struct Bidule
{
	char b;
	int a;
	char c;
};
test.cpp:4:6: warning: padding struct 'Bidule' with 3 bytes to align 'a' [-Wpadded]
        int a;
            ^
test.cpp:1:8: warning: padding size of 'Bidule' with 3 bytes to alignment boundary [-Wpadded]
struct Bidule

Usually padding in the middle is a bad thing because the struct can be "easily" organized differently to reduce the memory footprint. On the other hand, padding at the end of a structure is common and there is usually no trivial fix.

As an example, I ran -Wpadded on a large code base, I found 3 padding of field which I fixed, and more than one thousand warning messages about padding of struct for which I cannot do something without complex code refactoring.

It may be possible to split -Wpadding in two options, one which warns about padding fields (which I found really useful 100% of the time) and the other which warns about padding the whole struct, which IMHO only need to be activated when needed.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions