Skip to content

[SystemZ][z/OS] Use the XL pragma pack semantics on z/OS #111053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/ZOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void ZOS::addClangTargetOptions(const ArgList &DriverArgs,
options::OPT_fno_aligned_allocation))
CC1Args.push_back("-faligned-alloc-unavailable");

if (DriverArgs.hasFlag(options::OPT_fxl_pragma_pack,
options::OPT_fno_xl_pragma_pack, true))
CC1Args.push_back("-fxl-pragma-pack");

// Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
// or disabled sized deallocations.
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
Expand Down
26 changes: 26 additions & 0 deletions clang/lib/Parse/ParsePragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,7 @@ void PragmaGCCVisibilityHandler::HandlePragma(Preprocessor &PP,
// pack '(' [integer] ')'
// pack '(' 'show' ')'
// pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
// pack '(' 'packed' | 'full' | 'twobyte' | 'reset' ')' with -fzos-extensions
void PragmaPackHandler::HandlePragma(Preprocessor &PP,
PragmaIntroducer Introducer,
Token &PackTok) {
Expand Down Expand Up @@ -2155,10 +2156,35 @@ void PragmaPackHandler::HandlePragma(Preprocessor &PP,
? Sema::PSK_Push_Set
: Sema::PSK_Set;
} else if (Tok.is(tok::identifier)) {
// Map pragma pack options to pack (integer).
auto MapPack = [&](const char *Literal) {
Action = Sema::PSK_Push_Set;
Alignment = Tok;
Alignment.setKind(tok::numeric_constant);
Alignment.setLiteralData(Literal);
Alignment.setLength(1);
};

const IdentifierInfo *II = Tok.getIdentifierInfo();
if (II->isStr("show")) {
Action = Sema::PSK_Show;
PP.Lex(Tok);
} else if (II->isStr("packed") && PP.getLangOpts().ZOSExt) {
// #pragma pack(packed) is the same as #pragma pack(1)
MapPack("1");
PP.Lex(Tok);
} else if (II->isStr("full") && PP.getLangOpts().ZOSExt) {
// #pragma pack(full) is the same as #pragma pack(4)
MapPack("4");
PP.Lex(Tok);
} else if (II->isStr("twobyte") && PP.getLangOpts().ZOSExt) {
// #pragma pack(twobyte) is the same as #pragma pack(2)
MapPack("2");
PP.Lex(Tok);
} else if (II->isStr("reset") && PP.getLangOpts().ZOSExt) {
// #pragma pack(reset) is the same as #pragma pack(pop) on XL
Action = Sema::PSK_Pop;
PP.Lex(Tok);
} else {
if (II->isStr("push")) {
Action = Sema::PSK_Push;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Driver/zos-pragma-pack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// REQUIRES: systemz-registered-target

// RUN: %clang -### -target s390x-ibm-zos -c %s -o /dev/null 2>&1 | FileCheck %s
// CHECK: "-fxl-pragma-pack"

// RUN: %clang -### -fno-xl-pragma-pack -target s390x-ibm-zos -c %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=NOOPT
// NOOPT-NOT: "-fxl-pragma-pack"

12 changes: 12 additions & 0 deletions clang/test/SemaCXX/pragma-pack-packed-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -triple s390x-ibm-zos -fzos-extensions -fsyntax-only -verify %s
// RUN: %clang_cc1 -triple s390x-ibm-zos -fzos-extensions -fxl-pragma-pack -fsyntax-only -verify %s
// RUN: %clang -target s390x-ibm-zos -S -emit-llvm -Xclang -verify -fno-xl-pragma-pack %s

#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
#pragma pack(twobyte)
#pragma pack(packed)
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 1}}
#pragma pack(reset)
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 2}}
#pragma pack(pop)
#pragma pack(show) // expected-warning {{value of #pragma pack(show) == 8}}
Loading