[clang] c781dc7 - [SystemZ][z/OS] Set default alignment rules for z/OS target

Abhina Sreeskantharajan via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 6 10:16:21 PDT 2020


Author: Fanbo Meng
Date: 2020-10-06T13:16:15-04:00
New Revision: c781dc74a8b282eb4c6f3aa48982c5de898611a2

URL: https://github.com/llvm/llvm-project/commit/c781dc74a8b282eb4c6f3aa48982c5de898611a2
DIFF: https://github.com/llvm/llvm-project/commit/c781dc74a8b282eb4c6f3aa48982c5de898611a2.diff

LOG: [SystemZ][z/OS] Set default alignment rules for z/OS target

Set the default alignment control variables for z/OS target and add test case for alignment rules on z/OS.

Reviewed By: abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D88845

Added: 
    clang/test/CodeGen/zos-alignment.c

Modified: 
    clang/lib/Basic/Targets/OSTargets.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 9b96690f413c..7445dbe72794 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -779,6 +779,11 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo<Target> {
   ZOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
       : OSTargetInfo<Target>(Triple, Opts) {
     this->WCharType = TargetInfo::UnsignedInt;
+    this->UseBitFieldTypeAlignment = false;
+    this->UseZeroLengthBitfieldAlignment = true;
+    this->ZeroLengthBitfieldBoundary = 32;
+    this->MinGlobalAlign = 0;
+    this->DefaultAlignForAttributeAligned = 128;
   }
 };
 

diff  --git a/clang/test/CodeGen/zos-alignment.c b/clang/test/CodeGen/zos-alignment.c
new file mode 100644
index 000000000000..5a72096a56f6
--- /dev/null
+++ b/clang/test/CodeGen/zos-alignment.c
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -emit-llvm -triple s390x-none-zos -fdump-record-layouts %s -o - | FileCheck %s
+
+struct s0 {
+  short a:3;
+  long b:5;
+  int c:1;
+  long d:10;
+  char e:5;
+} S0;
+// CHECK:              0 | struct s0
+// CHECK-NEXT:     0:0-2 |   short a
+// CHECK-NEXT:     0:3-7 |   long b
+// CHECK-NEXT:     1:0-0 |   int c
+// CHECK-NEXT:    1:1-10 |   long d
+// CHECK-NEXT:     2:3-7 |   char e
+// CHECK-NEXT:           | [sizeof=3, align=1]
+
+struct s1 {
+  char a:7;
+  long b:27;
+  int c:2;
+} S1;
+// CHECK:              0 | struct s1
+// CHECK-NEXT:     0:0-6 |   char a
+// CHECK-NEXT:    0:7-33 |   long b
+// CHECK-NEXT:     4:2-3 |   int c
+// CHECK-NEXT:           | [sizeof=5, align=1]
+
+struct s2 {
+  char a:7;
+  char  :0;
+  short :0;
+  short :0;
+} S2;
+// CHECK:              0 | struct s2
+// CHECK-NEXT:     0:0-6 |   char a
+// CHECK-NEXT:       4:- |   char
+// CHECK-NEXT:       4:- |   short
+// CHECK-NEXT:       4:- |   short
+// CHECK-NEXT:           | [sizeof=4, align=4]
+
+struct s3 {
+  int a;
+  int b:16;
+  char  :0;
+  char c:1;
+} S3;
+// CHECK:              0 | struct s3
+// CHECK-NEXT:         0 |   int a
+// CHECK-NEXT:    4:0-15 |   int b
+// CHECK-NEXT:       8:- |   char
+// CHECK-NEXT:     8:0-0 |   char c
+// CHECK-NEXT:           | [sizeof=12, align=4]
+
+struct s4 {
+ unsigned int __attribute__((aligned(32))) a;
+} S4;
+// CHECK:              0 | struct s4
+// CHECK-NEXT:         0 |   unsigned int a
+// CHECK-NEXT:           | [sizeof=32, align=32]
+
+struct s5 {
+  char a;
+  int  b:19 __attribute__((aligned(4)));
+  int  c:22 __attribute__((aligned(8)));
+  int  :0;
+  int  d:10;
+} S5;
+// CHECK:              0 | struct s5
+// CHECK-NEXT:         0 |   char a
+// CHECK-NEXT:    4:0-18 |   int b
+// CHECK-NEXT:    8:0-21 |   int c
+// CHECK-NEXT:      12:- |   int
+// CHECK-NEXT:    12:0-9 |   int d
+// CHECK-NEXT:           | [sizeof=16, align=8]
+
+struct s6 {
+  char * a;
+  char * b[];
+} S6;
+// CHECK:              0 | struct s6
+// CHECK-NEXT:         0 |   char * a
+// CHECK-NEXT:         8 |   char *[] b
+// CHECK-NEXT:           | [sizeof=8, align=8]
+
+struct s10 {
+ unsigned int __attribute__((aligned)) a;
+} S10;
+// CHECK:              0 | struct s10
+// CHECK-NEXT:         0 |   unsigned int a
+// CHECK-NEXT:           | [sizeof=16, align=16]
+
+union u0 {
+  unsigned short     d1 __attribute__((packed));
+  int                d2:10;
+  long               d3;
+} U0 __attribute__((aligned(8)));
+// CHECK:              0 | union u0
+// CHECK-NEXT:         0 |   unsigned short d1
+// CHECK-NEXT:     0:0-9 |   int d2
+// CHECK-NEXT:         0 |   long d3
+// CHECK-NEXT:           | [sizeof=8, align=8]
+
+union u1 {
+  unsigned int        :0;
+  short               a;
+} U1;
+// CHECK:              0 | union u1
+// CHECK-NEXT:       0:- |   unsigned int
+// CHECK-NEXT:         0 |   short a
+// CHECK-NEXT:           | [sizeof=4, align=4]
+
+union u2 {
+  long      :0;
+  short      a;
+} U2;
+// CHECK:              0 | union u2
+// CHECK-NEXT:       0:- |   long
+// CHECK-NEXT:         0 |   short a
+// CHECK-NEXT:           | [sizeof=8, align=8]
+
+union u3 {
+  unsigned char :0;
+  unsigned short :0;
+} U3;
+// CHECK:              0 | union u3
+// CHECK-NEXT:       0:- |   unsigned char
+// CHECK-NEXT:       0:- |   unsigned short
+// CHECK-NEXT:           | [sizeof=0, align=4]


        


More information about the cfe-commits mailing list