View Issue Details

IDProjectCategoryView StatusLast Update
0035873FPCCompilerpublic2019-09-17 11:37
ReporterTimm ThalerAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformAVROSembeddedOS VersionAVR5
Product Version3.3.1Product Buildr42480 
Target VersionFixed in Version 
Summary0035873: AVR: Enumerations always use 32 bit variables
DescriptionEnumerations always use 32 bit variables. According to description (https://wiki.freepascal.org/Enum_Type/de) enum type should be as small as possible.
Steps To Reproducetype
  Tnum = (eins, zwei, drei);
var
  a, b : uint16;
  n : Tnum;
  m : (one, two, three, four, five);

procedure testtest();
begin
    if (m = three) or (n = drei) then begin

    end;
end;

begin
  repeat
    n := zwei;
    m := four;
  until false;
end.

compiles to

PsTEST_ss_TESTTEST:
.Lc2:
# [test.lpr]
# [14] begin
# [15] if (m = three) or (n = drei) then begin
    lds r20,(U_sPsTEST_ss_M)
    lds r18,(U_sPsTEST_ss_M+1)
    lds r21,(U_sPsTEST_ss_M+2)
    lds r19,(U_sPsTEST_ss_M+3)
    cpi r20,2
    cpc r18,r1
    cpc r21,r1
    cpc r19,r1
    breq .Lj5
    lds r21,(U_sPsTEST_ss_N)
    lds r19,(U_sPsTEST_ss_N+1)
    lds r18,(U_sPsTEST_ss_N+2)
    lds r20,(U_sPsTEST_ss_N+3)
    cpi r21,2
    cpc r19,r1
    cpc r18,r1
    cpc r20,r1
    brne .Lj7
.Lj5:
.Lj7:
# [18] end;
    ret

# [22] n := zwei;
    ldi r18,1
    sts (U_sPsTEST_ss_N),r18
    sts (U_sPsTEST_ss_N+1),r1
    sts (U_sPsTEST_ss_N+2),r1
    sts (U_sPsTEST_ss_N+3),r1
# [23] m := four;
    ldi r18,3
    sts (U_sPsTEST_ss_M),r18
    sts (U_sPsTEST_ss_M+1),r1
    sts (U_sPsTEST_ss_M+2),r1
    sts (U_sPsTEST_ss_M+3),r1
Additional InformationStrange: With parser mode -MDelphi enumerations uses 8 bit, with all other parser modes -Mfpc, -MPbjFPC... enumerations uses 32 bit.

Small variables can be forced with {$PACKENUM 1}.
TagsAVR
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Jonas Maebe

2019-07-22 10:21

manager   ~0117342

The wiki is wrong. See the official documentation for the actual behaviour, and for how to modify it: https://www.freepascal.org/docs-html/current/prog/progsu59.html

Issue History

Date Modified Username Field Change
2019-07-22 00:59 Timm Thaler New Issue
2019-07-22 10:21 Jonas Maebe Assigned To => Jonas Maebe
2019-07-22 10:21 Jonas Maebe Status new => resolved
2019-07-22 10:21 Jonas Maebe Resolution open => no change required
2019-07-22 10:21 Jonas Maebe FPCTarget => -
2019-07-22 10:21 Jonas Maebe Note Added: 0117342
2019-09-17 11:37 Dimitrios Chr. Ioannidis Tag Attached: AVR