[clang] [Clang] Warn when an explicit alignment is weakened by other directives (PR #198417)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 5 07:05:44 PDT 2026


================
@@ -1268,6 +1268,14 @@ ItaniumRecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
     UnpackedAlignTo = std::min(UnpackedAlignTo, MaxFieldAlignment);
   }
 
+  CharUnits MaxAlignmentInChars =
+      Context.toCharUnitsFromBits(Base->Class->getMaxAlignment());
+  if (!MaxAlignmentInChars.isZero() && MaxAlignmentInChars > BaseAlign) {
+    Diag(Base->Class->getLocation(), diag::warn_explicit_alignment_weakened)
+        << Base->Class->getName() << MaxAlignmentInChars.getQuantity()
----------------
AaronBallman wrote:

```suggestion
        << Base->Class << MaxAlignmentInChars.getQuantity()
```
You can pass in any `NamedDecl *` and the diagnostics engine will properly determine how to display it (including quoting, etc).

https://github.com/llvm/llvm-project/pull/198417


More information about the cfe-commits mailing list