Skip to content

Commit 4c26a1e

Browse files
authored
[SystemZ][z/OS] Use the XL pragma pack semantics on z/OS (#111053)
- set the default on z/OS to use the XL pragma semantics - add in additional pragma pack values such as twobyte & reset supported by XL on z/OS
1 parent 3a47bf6 commit 4c26a1e

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

clang/lib/Driver/ToolChains/ZOS.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void ZOS::addClangTargetOptions(const ArgList &DriverArgs,
3737
options::OPT_fno_aligned_allocation))
3838
CC1Args.push_back("-faligned-alloc-unavailable");
3939

40+
if (DriverArgs.hasFlag(options::OPT_fxl_pragma_pack,
41+
options::OPT_fno_xl_pragma_pack, true))
42+
CC1Args.push_back("-fxl-pragma-pack");
43+
4044
// Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
4145
// or disabled sized deallocations.
4246
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,

clang/lib/Parse/ParsePragma.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,7 @@ void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP,
21262126
// pack '(' [integer] ')'
21272127
// pack '(' 'show' ')'
21282128
// pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
2129+
// pack '(' 'packed' | 'full' | 'twobyte' | 'reset' ')' with -fzos-extensions
21292130
void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21302131
PragmaIntroducer Introducer,
21312132
Token &PackTok) {
@@ -2155,10 +2156,35 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
21552156
? Sema::PSK_Push_Set
21562157
: Sema::PSK_Set;
21572158
} else if (Tok.is(tok::identifier)) {
2159+
// Map pragma pack options to pack (integer).
2160+
auto MapPack = [&](const char *Literal) {
2161+
Action = Sema::PSK_Push_Set;
2162+
Alignment = Tok;
2163+
Alignment.setKind(tok::numeric_constant);
2164+
Alignment.setLiteralData(Literal);
2165+
Alignment.setLength(1);
2166+
};
2167+
21582168
const IdentifierInfo *II = Tok.getIdentifierInfo();
21592169
if (II->isStr("show")) {
21602170
Action = Sema::PSK_Show;
21612171
PP.Lex(Tok);
2172+
} else if (II->isStr("packed") && PP.getLangOpts().ZOSExt) {
2173+
// #pragma pack(packed) is the same as #pragma pack(1)
2174+
MapPack("1");
2175+
PP.Lex(Tok);
2176+
} else if (II->isStr("full") && PP.getLangOpts().ZOSExt) {
2177+
// #pragma pack(full) is the same as #pragma pack(4)
2178+
MapPack("4");
2179+
PP.Lex(Tok);
2180+
} else if (II->isStr("twobyte") && PP.getLangOpts().ZOSExt) {
2181+
// #pragma pack(twobyte) is the same as #pragma pack(2)
2182+
MapPack("2");
2183+
PP.Lex(Tok);
2184+
} else if (II->isStr("reset") && PP.getLangOpts().ZOSExt) {
2185+
// #pragma pack(reset) is the same as #pragma pack(pop) on XL
2186+
Action = Sema::PSK_Pop;
2187+
PP.Lex(Tok);
21622188
} else {
21632189
if (II->isStr("push")) {
21642190
Action = Sema::PSK_Push;

clang/test/Driver/zos-pragma-pack.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// REQUIRES: systemz-registered-target
2+
3+
// RUN: %clang -### -target s390x-ibm-zos -c %s -o /dev/null 2>&1 | FileCheck %s
4+
// CHECK: "-fxl-pragma-pack"
5+
6+
// RUN: %clang -### -fno-xl-pragma-pack -target s390x-ibm-zos -c %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=NOOPT
7+
// NOOPT-NOT: "-fxl-pragma-pack"
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple s390x-ibm-zos -fzos-extensions -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -triple s390x-ibm-zos -fzos-extensions -fxl-pragma-pack -fsyntax-only -verify %s
3+
// RUN: %clang -target s390x-ibm-zos -S -emit-llvm -Xclang -verify -fno-xl-pragma-pack %s
4+
5+
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
6+
#pragma pack(twobyte)
7+
#pragma pack(packed)
8+
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 1}}
9+
#pragma pack(reset)
10+
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 2}}
11+
#pragma pack(pop)
12+
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}

0 commit comments

Comments
 (0)