mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-24 21:56:04 +00:00

'#pragma pack (pop)' and suspicious uses of '#pragma pack' in included files The second recommit (r309106) was reverted because the "non-default #pragma pack value chages the alignment of struct or union members in the included file" warning proved to be too aggressive for external projects like Chromium (https://bugs.chromium.org/p/chromium/issues/detail?id=749197). This recommit makes the problematic warning a non-default one, and gives it the -Wpragma-pack-suspicious-include warning option. The first recommit (r308441) caused a "non-default #pragma pack value might change the alignment of struct or union members in the included file" warning in LLVM itself. This recommit tweaks the added warning to avoid warnings for #includes that don't have any records that are affected by the non-default alignment. This tweak avoids the previously emitted warning in LLVM. Original message: This commit adds a new -Wpragma-pack warning. It warns in the following cases: - When a translation unit is missing terminating #pragma pack (pop) directives. - When entering an included file if the current alignment value as determined by '#pragma pack' directives is different from the default alignment value. - When leaving an included file that changed the state of the current alignment value. rdar://10184173 Differential Revision: https://reviews.llvm.org/D35484 llvm-svn: 309386
91 lines
3.5 KiB
C
91 lines
3.5 KiB
C
// Test this without pch.
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DSET
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DRESET
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DPUSH
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DPUSH_POP
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -include %s -verify -fsyntax-only -Wno-pragma-pack -DPUSH_POP_LABEL
|
|
|
|
// Test with pch.
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DSET -emit-pch -o %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DSET -verify -include-pch %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DRESET -emit-pch -o %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DRESET -verify -include-pch %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH -emit-pch -o %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH -verify -include-pch %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP -emit-pch -o %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP -verify -include-pch %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP_LABEL -emit-pch -o %t
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -Wno-pragma-pack -DPUSH_POP_LABEL -verify -include-pch %t
|
|
|
|
#ifndef HEADER
|
|
#define HEADER
|
|
|
|
#ifdef SET
|
|
#pragma pack(1)
|
|
#endif
|
|
|
|
#ifdef RESET
|
|
#pragma pack(2)
|
|
#pragma pack ()
|
|
#endif
|
|
|
|
#ifdef PUSH
|
|
#pragma pack(1)
|
|
#pragma pack (push, 2)
|
|
#endif
|
|
|
|
#ifdef PUSH_POP
|
|
#pragma pack (push, 4)
|
|
#pragma pack (push, 2)
|
|
#pragma pack (pop)
|
|
#endif
|
|
|
|
#ifdef PUSH_POP_LABEL
|
|
#pragma pack (push, a, 4)
|
|
#pragma pack (push, b, 1)
|
|
#pragma pack (push, c, 2)
|
|
#pragma pack (pop, b)
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifdef SET
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 1}}
|
|
#pragma pack(pop) // expected-warning {{#pragma pack(pop, ...) failed: stack empty}}
|
|
#endif
|
|
|
|
#ifdef RESET
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
|
|
#pragma ()
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
|
|
#endif
|
|
|
|
#ifdef PUSH
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 2}}
|
|
#pragma pack(pop)
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 1}}
|
|
#pragma pack ()
|
|
#pragma pack (show) // expected-warning {{value of #pragma pack(show) == 8}}
|
|
#pragma pack(pop) // expected-warning {{#pragma pack(pop, ...) failed: stack empty}}
|
|
#endif
|
|
|
|
#ifdef PUSH_POP
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
|
|
#pragma pack(pop)
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
|
|
#pragma pack(pop) // expected-warning {{#pragma pack(pop, ...) failed: stack empty}}
|
|
#endif
|
|
|
|
#ifdef PUSH_POP_LABEL
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
|
|
#pragma pack(pop, c)
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 4}}
|
|
#pragma pack(pop, a)
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
|
|
#pragma pack(pop) // expected-warning {{#pragma pack(pop, ...) failed: stack empty}}
|
|
#pragma pack(pop, b) // expected-warning {{#pragma pack(pop, ...) failed: stack empty}}
|
|
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
|
|
#endif
|
|
|
|
#endif
|