-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[SystemZ][z/OS] Use the XL pragma pack semantics on z/OS #111053
Conversation
perry-ca
commented
Oct 3, 2024
- 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
@llvm/pr-subscribers-backend-systemz @llvm/pr-subscribers-clang Author: Sean Perry (perry-ca) Changes
Full diff: https://github.com/llvm/llvm-project/pull/111053.diff 4 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/ZOS.cpp b/clang/lib/Driver/ToolChains/ZOS.cpp
index 074e0556ecd2ad..c5ad3ef1b00f1d 100644
--- a/clang/lib/Driver/ToolChains/ZOS.cpp
+++ b/clang/lib/Driver/ToolChains/ZOS.cpp
@@ -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,
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index cc6f18b5b319f9..12fed448d477c0 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -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) {
@@ -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;
diff --git a/clang/test/Driver/zos-pragma-pack.c b/clang/test/Driver/zos-pragma-pack.c
new file mode 100644
index 00000000000000..0e04878daba4c5
--- /dev/null
+++ b/clang/test/Driver/zos-pragma-pack.c
@@ -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"
+
diff --git a/clang/test/SemaCXX/pragma-pack-packed-2.cpp b/clang/test/SemaCXX/pragma-pack-packed-2.cpp
new file mode 100644
index 00000000000000..3639addd6fe5fc
--- /dev/null
+++ b/clang/test/SemaCXX/pragma-pack-packed-2.cpp
@@ -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}}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, can we add [SystemZ][z/OS] in the title to make it consistent with other PRs