llvm-project/clang/test/Analysis/padding_no_unique_address.cpp
Georgy Komarov c558b1fca7
[analyzer] Fix calculating offset for fields with an empty type
Fix offset calculation routines in padding checker to avoid assertion
errors described in bugzilla issue 50426. The fields that are subojbects
of zero size, marked with [[no_unique_address]] or empty bitfields will
be excluded from padding calculation routines.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D104097
2021-07-04 06:57:11 +03:00

31 lines
766 B
C++

// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-linux-gnu -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=2 -verify %s
class Empty {}; // no-warning
// expected-warning@+1{{Excessive padding in 'struct NoUniqueAddressWarn1' (6 padding}}
struct NoUniqueAddressWarn1 {
char c1;
[[no_unique_address]] Empty empty;
int i;
char c2;
};
// expected-warning@+1{{Excessive padding in 'struct NoUniqueAddressWarn2' (6 padding}}
struct NoUniqueAddressWarn2 {
char c1;
[[no_unique_address]] Empty e1, e2;
int i;
char c2;
};
struct NoUniqueAddressNoWarn1 {
char c1;
[[no_unique_address]] Empty empty;
char c2;
};
struct NoUniqueAddressNoWarn2 {
char c1;
[[no_unique_address]] Empty e1, e2;
};