[clang] [Clang] Warn when an explicit alignment is weakened by other directives (PR #198417)
David Meng via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 6 20:00:30 PDT 2026
================
@@ -2452,6 +2481,41 @@ static bool mustSkipTailPadding(TargetCXXABI ABI, const CXXRecordDecl *RD) {
llvm_unreachable("bad tail-padding use kind");
}
+void ItaniumRecordLayoutBuilder::DiagnoseAlignmentWeakeningSource(
+ const Decl *RD, CharUnits Weakened, bool DueToPackedAttr) {
+ enum WeakeningSource {
+ WS_PragmaPack,
+ WS_PackedAttr,
+ WS_PragmaOptionsAlign,
+ WS_CommandLine,
+ };
+ WeakeningSource Source;
+ SourceLocation Loc;
+
+ if (DueToPackedAttr) {
+ Source = WS_PackedAttr;
+ if (const auto *PA = RD->getAttr<PackedAttr>())
+ Loc = PA->getLocation();
+ } else if (RD->hasAttr<AlignMac68kAttr>()) {
+ Source = WS_PragmaOptionsAlign;
+ if (const auto *A = RD->getAttr<AlignMac68kAttr>())
+ Loc = A->getLocation();
+ } else if (const auto *MFAA = RD->getAttr<MaxFieldAlignmentAttr>()) {
+ Source = WS_PragmaPack;
+ Loc = MFAA->getLocation();
+ } else {
+ Source = WS_CommandLine;
+ }
+
+ // Fall back to the record location.
----------------
davidmenggx wrote:
Alternatively we could omit the note in this case
https://github.com/llvm/llvm-project/pull/198417
More information about the cfe-commits
mailing list