Browse Source

* Compiler error is now thrown if record alignment is not a power of 2 or is greater than 64.

J. Gareth "Curious Kit" Moreton 3 years ago
parent
commit
971b8b9217
1 changed files with 4 additions and 1 deletions
  1. 4 1
      compiler/ptype.pas

+ 4 - 1
compiler/ptype.pas

@@ -1068,7 +1068,10 @@ implementation
            begin
            begin
              consume(_ID);
              consume(_ID);
              alignment:=get_intconst.svalue;
              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
              else
                recst.recordalignment:=shortint(alignment);
                recst.recordalignment:=shortint(alignment);
            end;
            end;