CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
119 lines
5.3 KiB
C++
119 lines
5.3 KiB
C++
// RUN: %check_clang_tidy %s altera-struct-pack-align %t -- -header-filter=.*
|
|
|
|
// Struct needs both alignment and packing
|
|
struct error {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
};
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'error' is inefficient due to padding; only needs 10 bytes but is using 24 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((packed))" to reduce the amount of padding applied to struct 'error'
|
|
// CHECK-MESSAGES: :[[@LINE-7]]:8: warning: accessing fields in struct 'error' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-8]]:8: note: use "__attribute__((aligned(16)))" to align struct 'error' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16)));
|
|
|
|
// Struct is explicitly packed, but needs alignment
|
|
struct error_packed {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
} __attribute__((packed));
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'error_packed' is inefficient due to poor alignment; currently aligned to 1 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'error_packed' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((aligned(16))) __attribute__((packed));
|
|
|
|
// Struct is properly packed, but needs alignment
|
|
struct align_only {
|
|
char a;
|
|
char b;
|
|
char c;
|
|
char d;
|
|
int e;
|
|
double f;
|
|
};
|
|
// CHECK-MESSAGES: :[[@LINE-8]]:8: warning: accessing fields in struct 'align_only' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-9]]:8: note: use "__attribute__((aligned(16)))" to align struct 'align_only' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((aligned(16)));
|
|
|
|
// Struct is perfectly packed but wrongly aligned
|
|
struct bad_align {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
} __attribute__((packed)) __attribute__((aligned(8)));
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16)));
|
|
|
|
struct bad_align2 {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
} __attribute__((packed)) __attribute__((aligned(32)));
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align2' is inefficient due to poor alignment; currently aligned to 32 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align2' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16)));
|
|
|
|
struct bad_align3 {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
} __attribute__((packed)) __attribute__((aligned(4)));
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align3' is inefficient due to poor alignment; currently aligned to 4 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align3' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16)));
|
|
|
|
// Struct is both perfectly packed and aligned
|
|
struct success {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
} __attribute__((packed)) __attribute__((aligned(16)));
|
|
//Should take 10 bytes and be aligned to 16 bytes
|
|
|
|
// Struct is properly packed, and explicitly aligned
|
|
struct success2 {
|
|
int a;
|
|
int b;
|
|
int c;
|
|
} __attribute__((aligned(16)));
|
|
|
|
// If struct is properly aligned, packing not needed
|
|
struct success3 {
|
|
char a;
|
|
double b;
|
|
char c;
|
|
} __attribute__((aligned(16)));
|
|
|
|
// If struct is templated, warnings should not be triggered
|
|
template <typename A, typename B>
|
|
struct success4 {
|
|
A a;
|
|
B b;
|
|
int c;
|
|
};
|
|
|
|
// Warnings should not trigger on struct instantiations
|
|
void no_trigger_on_instantiation() {
|
|
struct bad_align3 instantiated { 'a', 0.001, 'b' };
|
|
}
|
|
|
|
// Make sure that we don't recommend aligning an empty struct to zero bytes (PR#51620)
|
|
struct StructWithNoFields {};
|
|
|
|
struct ContainsStructWithNoFields {
|
|
StructWithNoFields s;
|
|
};
|
|
|
|
// Make sure that an empty struct is treated like "char" for padding and alignment purposes
|
|
struct ContainsStructWithNoFields2 {
|
|
StructWithNoFields s;
|
|
double d;
|
|
StructWithNoFields t;
|
|
};
|
|
// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'ContainsStructWithNoFields2' is inefficient due to padding; only needs 10 bytes but is using 24 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((packed))" to reduce the amount of padding applied to struct 'ContainsStructWithNoFields2'
|
|
// CHECK-MESSAGES: :[[@LINE-7]]:8: warning: accessing fields in struct 'ContainsStructWithNoFields2' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align]
|
|
// CHECK-MESSAGES: :[[@LINE-8]]:8: note: use "__attribute__((aligned(16)))" to align struct 'ContainsStructWithNoFields2' to 16 bytes
|
|
// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16)));
|