sfertile created this revision. sfertile added reviewers: stevewan, Jake-Egan, cebowleratibm. sfertile added a project: PowerPC. Herald added subscribers: shchenz, nemanjai. sfertile requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
With xlc and xlC pragma align(packed) will pack bitfields the same way as pragma align(bit_packed). xlclang, xlclang++ and clang will pack bitfields the same way as pragma pack(1). Issue a warning when source code using pragma align(packed) to alert the user it may not be compatible with xlc/xlC. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D107506 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaAttr.cpp clang/test/Sema/aix-pragma-align-packed-warn.c clang/test/Sema/aix-pragma-pack-and-align.c Index: clang/test/Sema/aix-pragma-pack-and-align.c =================================================================== --- clang/test/Sema/aix-pragma-pack-and-align.c +++ clang/test/Sema/aix-pragma-pack-and-align.c @@ -170,7 +170,7 @@ } // namespace test7 namespace test8 { -#pragma align(packed) +#pragma align(packed) // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} #pragma pack(2) #pragma pack(show) // expected-warning {{value of #pragma pack(show) == 2}} struct A { Index: clang/test/Sema/aix-pragma-align-packed-warn.c =================================================================== --- /dev/null +++ clang/test/Sema/aix-pragma-align-packed-warn.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fxl-pragma-pack -verify -fsyntax-only %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fxl-pragma-pack -verify -fsyntax-only %s + +#pragma align(packed) // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} +struct A { + int a : 8; + int : 0; + short s; +}; +#pragma align(reset) Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -234,6 +234,8 @@ // Note that '#pragma options align=packed' is not equivalent to attribute // packed, it has a different precedence relative to attribute aligned. case POAK_Packed: + if (this->Context.getTargetInfo().getTriple().isOSAIX()) + Diag(PragmaLoc, diag::warn_pragma_align_not_xl_compatible); Action = Sema::PSK_Push_Set; ModeVal = AlignPackInfo::Packed; break; Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -913,6 +913,9 @@ InGroup<IgnoredPragmas>; def err_pragma_options_align_mac68k_target_unsupported : Error< "mac68k alignment pragma is not supported on this target">; +def warn_pragma_align_not_xl_compatible : Warning< + "#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++">, + InGroup<AIXCompat>; def warn_pragma_pack_invalid_alignment : Warning< "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">, InGroup<IgnoredPragmas>;
Index: clang/test/Sema/aix-pragma-pack-and-align.c =================================================================== --- clang/test/Sema/aix-pragma-pack-and-align.c +++ clang/test/Sema/aix-pragma-pack-and-align.c @@ -170,7 +170,7 @@ } // namespace test7 namespace test8 { -#pragma align(packed) +#pragma align(packed) // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} #pragma pack(2) #pragma pack(show) // expected-warning {{value of #pragma pack(show) == 2}} struct A { Index: clang/test/Sema/aix-pragma-align-packed-warn.c =================================================================== --- /dev/null +++ clang/test/Sema/aix-pragma-align-packed-warn.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fxl-pragma-pack -verify -fsyntax-only %s +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fxl-pragma-pack -verify -fsyntax-only %s + +#pragma align(packed) // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} +struct A { + int a : 8; + int : 0; + short s; +}; +#pragma align(reset) Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -234,6 +234,8 @@ // Note that '#pragma options align=packed' is not equivalent to attribute // packed, it has a different precedence relative to attribute aligned. case POAK_Packed: + if (this->Context.getTargetInfo().getTriple().isOSAIX()) + Diag(PragmaLoc, diag::warn_pragma_align_not_xl_compatible); Action = Sema::PSK_Push_Set; ModeVal = AlignPackInfo::Packed; break; Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -913,6 +913,9 @@ InGroup<IgnoredPragmas>; def err_pragma_options_align_mac68k_target_unsupported : Error< "mac68k alignment pragma is not supported on this target">; +def warn_pragma_align_not_xl_compatible : Warning< + "#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++">, + InGroup<AIXCompat>; def warn_pragma_pack_invalid_alignment : Warning< "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">, InGroup<IgnoredPragmas>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits