[fpc-devel] TypeInfo RTTI / possible inconsistency
Sven Barth
pascaldragon at googlemail.com
Wed May 19 22:10:26 CEST 2021
Am 18.05.2021 um 15:24 schrieb Martin Frb via fpc-devel:
> I was looking at TypeInfo (based on 3.2.2rc)
>
> line 632 unit TypInfo
>> tkMethod:
>> (MethodKind : TMethodKind;
>> ParamCount : Byte;
>> ParamList : array[0..1023] of Char
>> {in reality ParamList is a array[1..ParamCount] of:
>> record
>> Flags : TParamFlags;
>> ParamName : ShortString;
>> TypeName : ShortString;
>> end;
>> followed by
>> ResultType : ShortString // for mkFunction,
>> mkClassFunction only
>> ResultTypeRef : PPTypeInfo; // for mkFunction,
>> mkClassFunction only
>> CC : TCallConv;
>> ParamTypeRefs : array[1..ParamCount] of PPTypeInfo;}
>> );
>
> To find out about alignment (for any target which needs alignment), I
> looked through other code:
>
> fpc_3.2.2\source\tests\webtbs\tw12038.pp
> line 194 procedure DisplayDetails(Informations : TPropInfo;
> const expectedresult: ansistring);
> appears to access the data (except for the ParamTypeRefs array)
> The testcase does not seem to make any adjustments for alignment.
It does at line 285.
>
> fpc_3.2.2\source\packages\rtl-objpas\src\inc\rtti.pp
> line 3341 TRttiMethodType.GetParameters
> also appears to access the same typeinfo.
> It makes alignments in 3 different places
> ptr := AlignTParamFlags(ptr); // foreach Flags :
> TParamFlags; in the ParamList
> ptr := AlignToPtr(PByte(ptr) + ptr^ + SizeOf(Byte)); //
> ResultTypeRef
> paramtypes := PPPTypeInfo(AlignTypeData(ptr)); // ParamTypeRefs
>
> Which is correct?
> Or do they access different structures?
They are for different parts of the structure, cause they have different
alignment requirements (e.g. the param names and flags are aligned to
the TParamFlags (which is 2 Byte) while the ResultType is aligned to a
pointer. Though right now I don't know why the last one uses
AlignTypeData which would align to the QWord fields instead of Pointer
ones...
> A few other notes:
> FPC_REQUIRES_PROPER_ALIGNMENT
> does not seem to be listed on
> https://www.freepascal.org/docs-html/prog/progap7.html
There are a few from TOption.TargetOptions (in options.pas) that are not
yet documented.
> TypInfo line 1461
> in Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
> TP:=aligntoptr(PPropInfo(aligntoptr((Pointer(@TD^.UnitName)+Length(TD^.UnitName)+1))));
>
> Why call aligntoptr twice?
> The TypeCast in between does not change the alignment. (all the math
> is done within the innermost call)
That one is already fixed in trunk.
Regards,
Sven
More information about the fpc-devel
mailing list