sfertile updated this revision to Diff 364782. sfertile added a comment. Moved the diagnostic emission to ` Sema::ActOnTagFinishDefinition` as suggested.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D107506/new/ https://reviews.llvm.org/D107506 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaDecl.cpp clang/test/Sema/aix-pragma-align-packed-warn.c Index: clang/test/Sema/aix-pragma-align-packed-warn.c =================================================================== --- /dev/null +++ clang/test/Sema/aix-pragma-align-packed-warn.c @@ -0,0 +1,16 @@ +// 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) +struct A { // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} + short s1; + int : 0; + short s2; +}; + +struct B { // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} + short a : 8; + short b : 8; + int c; +}; +#pragma align(reset) Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -16573,6 +16573,15 @@ // Notify the consumer that we've defined a tag. if (!Tag->isInvalidDecl()) Consumer.HandleTagDeclDefinition(Tag); + + // Clangs implementation of #pragma align(pack) differs in bitfield layout + // from XLs and instead matches the XL #pragma pack(1) behavior. + if (Context.getTargetInfo().getTriple().isOSAIX() && + AlignPackStack.hasValue()) { + AlignPackInfo APInfo = AlignPackStack.CurrentValue; + if (APInfo.IsAlignAttr() && APInfo.getAlignMode() == AlignPackInfo::Packed) + Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible); + } } void Sema::ActOnObjCContainerFinishDefinition() { 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-align-packed-warn.c =================================================================== --- /dev/null +++ clang/test/Sema/aix-pragma-align-packed-warn.c @@ -0,0 +1,16 @@ +// 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) +struct A { // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} + short s1; + int : 0; + short s2; +}; + +struct B { // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}} + short a : 8; + short b : 8; + int c; +}; +#pragma align(reset) Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -16573,6 +16573,15 @@ // Notify the consumer that we've defined a tag. if (!Tag->isInvalidDecl()) Consumer.HandleTagDeclDefinition(Tag); + + // Clangs implementation of #pragma align(pack) differs in bitfield layout + // from XLs and instead matches the XL #pragma pack(1) behavior. + if (Context.getTargetInfo().getTriple().isOSAIX() && + AlignPackStack.hasValue()) { + AlignPackInfo APInfo = AlignPackStack.CurrentValue; + if (APInfo.IsAlignAttr() && APInfo.getAlignMode() == AlignPackInfo::Packed) + Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible); + } } void Sema::ActOnObjCContainerFinishDefinition() { 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