From 971b8b9217d257dba56b7cdac22d71492fb6a7d5 Mon Sep 17 00:00:00 2001
From: "J. Gareth \"Curious Kit\" Moreton" <gareth@moreton-family.com>
Date: Wed, 13 Apr 2022 11:02:27 +0100
Subject: [PATCH]   * Compiler error is now thrown if record alignment is not a
 power of 2 or is greater than 64.

---
 compiler/ptype.pas | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/compiler/ptype.pas b/compiler/ptype.pas
index 245bf7c0c0..59d38a9b3c 100644
--- a/compiler/ptype.pas
+++ b/compiler/ptype.pas
@@ -1068,7 +1068,10 @@ implementation
            begin
              consume(_ID);
              alignment:=get_intconst.svalue;
-             if not(alignment in [1,2,4,8,16,32,64]) then
+             { "(alignment and not $7F) = 0" means it's between 0 and 127, and
+               PopCnt = 1 for powers of 2 }
+             if ((alignment and not $7F) <> 0) or (PopCnt(Byte(alignment))<>1) then
+               message(scanner_e_illegal_alignment_directive)
              else
                recst.recordalignment:=shortint(alignment);
            end;