Changeset 436 in dev for trunk/abdev/BasicCompiler32


Ignore:
Timestamp:
Mar 15, 2008, 3:33:36 PM (16 years ago)
Author:
dai_9181
Message:

関数の戻り値の構造体など、一時メモリに保持された構造体のメンバに直接アクセスした場合、その一時メモリの解放が正常に行われないバグを修正(64bit版も修正した)。

Location:
trunk/abdev/BasicCompiler32
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler32/CParameter.cpp

    r435 r436  
    6565                //変数ではないとき
    6666                Type calcType;
    67                 BOOL bUseHeap;
    68                 NumOpe( Parms[i2], dummyType, calcType, &bUseHeap );
     67                bool isNeedHeapFreeStructure;
     68                NumOpe( Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure );
    6969                //↑ここでスタックに積む
    7070
     
    8686                    i2);
    8787
    88                 if( result && bUseHeap ){
     88                if( result )
     89                {
    8990                    useTempParameters[i2] = true;
     91                    isNeedFreeStructures[i2] = true;
    9092                    useTempObject = true;
    9193
     
    107109    for(int i2=ParmsNum-1;i2>=0;i2--){
    108110        if( useTempParameters[i2] ){
    109             if( types[i2].IsStruct() ){
     111            if( types[i2].IsStruct() )
     112            {
    110113                // 構造体の一時メモリ
    111114
    112                 //メモリを解放する
    113 
    114                 //call free
    115                 extern const UserProc *pSub_free;
    116                 compiler.codeGenerator.op_call(pSub_free);
    117             }
    118             else{
    119                 if( types[i2].Is64() ){
     115                if( isNeedFreeStructures[i2] )
     116                {
     117                    //メモリを解放する
     118
     119                    //call free
     120                    extern const UserProc *pSub_free;
     121                    compiler.codeGenerator.op_call(pSub_free);
     122                }
     123                else
     124                {
     125                    //pop ... 参照を消す
     126                    compiler.codeGenerator.op_add_esp( PTR_SIZE );
     127                }
     128            }
     129            else
     130            {
     131                if( types[i2].Is64() )
     132                {
    120133                    //pop ... 参照を消す
    121134                    //pop ... 上位32ビット
     
    123136                    compiler.codeGenerator.op_add_esp( PTR_SIZE * 3 );
    124137                }
    125                 else{
     138                else
     139                {
    126140                    //pop ... 参照を消す
    127141                    //pop ... 値を消す
     
    150164
    151165    Type calcType;
    152     BOOL bUseHeap;
     166    bool isNeedHeapFreeStructure;
    153167    NumOpe( expression,
    154168        baseType,
    155169        calcType,
    156         &bUseHeap );
     170        &isNeedHeapFreeStructure );
    157171
    158172    // ※スタックにある二つのデータ(コピー先、コピー元)の値を必要とする
    159     SetStructVariable( baseType, calcType, bUseHeap );
     173    SetStructVariable( baseType, calcType, isNeedHeapFreeStructure );
    160174}
    161175
     
    234248            }
    235249
    236             BOOL bCalcUseHeap;
    237250            Type calcType;
    238             if( !NumOpe( Parms[i2], dummyType, calcType, &bCalcUseHeap ) ){
     251            bool isNeedHeapFreeStructure;
     252            if( !NumOpe( Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure ) )
     253            {
    239254                break;
    240255            }
    241256
    242             if( calcType.IsObject() ){
     257            if( calcType.IsObject() )
     258            {
    243259                if( !dummyType.IsObject()
    244260                    ||
    245261                    dummyType.IsObject() &&
    246                     !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ){
     262                    !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) )
     263                {
    247264                        //キャスト演算子のオーバーロードに対応する
    248                         CallCastOperatorProc( calcType, bCalcUseHeap,dummyType );
     265                        CallCastOperatorProc( calcType, isNeedHeapFreeStructure,dummyType );
    249266                }
    250267            }
  • trunk/abdev/BasicCompiler32/Compile_Calc.cpp

    r435 r436  
    573573
    574574    //NumOpe...(スタックに答えが格納される)
    575     BOOL bCalcUseHeap;
    576575    Type calcType;
    577     if( !NumOpe(Command+i+1,varType,calcType,&bCalcUseHeap) ){
     576    bool isNeedHeapFreeStructure;
     577    if( !NumOpe(Command+i+1,varType,calcType,&isNeedHeapFreeStructure) ){
    578578        return;
    579579    }
     
    588588        if( !isUpCast ){
    589589            //キャスト演算子のオーバーロードに対応する
    590             CallCastOperatorProc(calcType,bCalcUseHeap,varType);
     590            CallCastOperatorProc(calcType,isNeedHeapFreeStructure,varType);
    591591        }
    592592    }
     
    606606    if( varType.IsStruct() ){
    607607        //構造体インスタンスへの代入
    608         SetStructVariable(varType,calcType,bCalcUseHeap);
     608        SetStructVariable(varType,calcType,isNeedHeapFreeStructure);
    609609        return;
    610610    }
  • trunk/abdev/BasicCompiler32/Compile_Var.cpp

    r424 r436  
    116116    for(i=i3-1;i>=0;i--){
    117117        Type tempType;
    118         BOOL bUseHeap;
    119         NumOpe( pParm[i], Type( DEF_LONG ), tempType, &bUseHeap );
    120         if( tempType.IsObject() ){
     118        bool isNeedHeapFreeStructure;
     119        NumOpe( pParm[i], Type( DEF_LONG ), tempType, &isNeedHeapFreeStructure );
     120        if( tempType.IsObject() )
     121        {
    121122            //キャスト演算子のオーバーロードに対応する
    122123            CallCastOperatorProc(
    123124                tempType,
    124                 bUseHeap, Type(DEF_LONG) );
     125                isNeedHeapFreeStructure, Type(DEF_LONG) );
    125126            tempType.SetBasicType( DEF_LONG );
    126127        }
     
    130131        compiler.codeGenerator.op_pop(REG_EAX);
    131132
    132         for(i2=i+1,i4=1;i2<i3;i2++) i4*=subscripts[i2]+1;
     133        for( i2=i+1, i4=1; i2<i3; i2++ )
     134        {
     135            i4*=subscripts[i2]+1;
     136        }
    133137
    134138        //imul eax,i4
  • trunk/abdev/BasicCompiler32/NumOpe.cpp

    r435 r436  
    671671            const Type &baseType,
    672672            Type &resultType,
    673             BOOL *pbUseHeap ){
    674 
    675     if( !NumOpe( expression, baseType, resultType, pbUseHeap ) ){
     673            bool *pbIsNeedHeapFreeStructure ){
     674
     675    if( !NumOpe( expression, baseType, resultType, pbIsNeedHeapFreeStructure ) )
     676    {
    676677        return false;
    677678    }
     
    703704            const Type &baseType,
    704705            Type &resultType,
    705             BOOL *pbUseHeap )
     706            bool *pbIsNeedHeapFreeStructure )
    706707{
    707708    int i,i2,i3;
     
    12741275    }
    12751276
    1276     if(pbUseHeap) *pbUseHeap = isNeedHeapFreeStructureStack[0];
     1277    if(pbIsNeedHeapFreeStructure)
     1278    {
     1279        *pbIsNeedHeapFreeStructure = isNeedHeapFreeStructureStack[0];
     1280    }
    12771281
    12781282    resultType.SetType( type_stack[0], index_stack[0] );
  • trunk/abdev/BasicCompiler32/Opcode.h

    r435 r436  
    7373            const Type &baseType,
    7474            Type &resultType,
    75             BOOL *pbUseHeap = NULL );
     75            bool *pbIsNeedHeapFreeStructure = NULL );
    7676bool NumOpe( const char *Command,
    7777           const Type &baseType,
    7878           Type &resultType,
    79            BOOL *pbUseHeap = NULL );
     79           bool *pbIsNeedHeapFreeStructure = NULL );
    8080
    8181//NumOpe_Arithmetic.cpp
     
    177177    bool useTempObject;
    178178    bool useTempParameters[255];
     179    bool isNeedFreeStructures[255];
    179180    int nCountOfTempObjects;
    180181
Note: See TracChangeset for help on using the changeset viewer.