From 66225db98d832bec75ffb96298107c015b0035f0 Mon Sep 17 00:00:00 2001 From: Zarko Todorovski Date: Fri, 16 Jul 2021 07:49:36 -0400 Subject: [PATCH] [PowerPC][AIX] Add warning when alignment is incompatible with XL https://reviews.llvm.org/D105659 implements ByVal handling in llc but some cases are not compatible with existing XL compiler on AIX. Adding a clang warning for such cases. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D105660 --- clang/include/clang/Basic/DiagnosticGroups.td | 3 +++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++++ clang/lib/Sema/SemaDeclAttr.cpp | 6 ++++++ clang/test/Sema/aix-attr-align.c | 22 ++++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 clang/test/Sema/aix-attr-align.c diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 18097cf..eb1b564 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1083,6 +1083,9 @@ def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct, // A warning group for warnings about code that clang accepts but gcc doesn't. def GccCompat : DiagGroup<"gcc-compat">; +// A warning group for warnings about code that may be incompatible on AIX. +def AIXCompat : DiagGroup<"aix-compat">; + // Warnings for Microsoft extensions. def MicrosoftCharize : DiagGroup<"microsoft-charize">; def MicrosoftDrectveSection : DiagGroup<"microsoft-drectve-section">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 7790939..823a36a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3254,6 +3254,10 @@ def warn_assume_aligned_too_great : Warning<"requested alignment must be %0 bytes or smaller; maximum " "alignment assumed">, InGroup>; +def warn_not_xl_compatible + : Warning<"requesting an alignment of 16 bytes or greater for struct" + " members is not binary compatible with AIX XL 16.1 and older">, + InGroup; def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning< "%q0 redeclared without %1 attribute: previous %1 ignored">, InGroup; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 3586ad3..9aac9d2 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3953,6 +3953,12 @@ void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, return; uint64_t AlignVal = Alignment.getZExtValue(); + // 16 byte ByVal alignment not due to a vector member is not honoured by XL + // on AIX. Emit a warning here that users are generating binary incompatible + // code to be safe. + if (AlignVal >= 16 && isa(D) && + Context.getTargetInfo().getTriple().isOSAIX()) + Diag(AttrLoc, diag::warn_not_xl_compatible) << E->getSourceRange(); // C++11 [dcl.align]p2: // -- if the constant expression evaluates to zero, the alignment diff --git a/clang/test/Sema/aix-attr-align.c b/clang/test/Sema/aix-attr-align.c new file mode 100644 index 0000000..ac70aab --- /dev/null +++ b/clang/test/Sema/aix-attr-align.c @@ -0,0 +1,22 @@ +// off-no-diagnostics +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify -fsyntax-only %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify -fsyntax-only %s +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -verify=off -Wno-aix-compat -fsyntax-only %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -verify=off -Wno-aix-compat -fsyntax-only %s +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -verify=off -fsyntax-only %s + +struct S { + int a[8] __attribute__((aligned(8))); // no-warning +}; + +struct T { + int a[4] __attribute__((aligned(16))); // expected-warning {{requesting an alignment of 16 bytes or greater for struct members is not binary compatible with AIX XL 16.1 and older}} +}; + +struct U { + int a[2] __attribute__((aligned(32))); // expected-warning {{requesting an alignment of 16 bytes or greater for struct members is not binary compatible with AIX XL 16.1 and older}} +}; + +int a[8] __attribute__((aligned(8))); // no-warning +int b[4] __attribute__((aligned(16))); // no-warning +int c[2] __attribute__((aligned(32))); // no-warning -- 2.7.4