• Not Answered

CCS/TMS320F28335: local variable value is wrong on 4.1.3 compiler except add volatile in front

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hi

CCS 3.3.82.13

Compiler 4.1.3 

For below local variable all and half.

1. The value in debugging environment is right only if we add volatile in front of variable or none optimize.

int64 half2quan(int32 target,int64 now, Uint16 Axis)
{
volatile
 int64 all,half;
 int64 TMP;
// long lsd;
// lsd=0x80000000;
// min=(int64)lsd*Position_Numerator1/Position_Divisor1;
// lsd=0x7fffffff;
// max=(long long)lsd*Position_Numerator1/Position_Divisor1;
// half=(int64)0x80000000;
// half=(int64)half*Position_Numerator1/Position_Divisor1;
 all=(int64)0x100000000;
 all=(int64)all*Position_Numerator1/Position_Divisor1;
 half=all;
 half=half>>1;//((int64)all>>1);
 TMP = (int64)target*Position_Numerator1/Position_Divisor1-now;

 if(TMP>half) TMP-=all;
 else if(TMP<-half) TMP+=all;
 return TMP;
}

2. if set optimize level to 3 or remove volatile. The value is wrong.

Could you let me know does it caused by old compiler ? Why should we must add volatile for a local variable? Thanks.

3 Replies

  • Daniel Fang
    Compiler 4.1.3 

    That compiler is over 10 years old.  Please upgrade.  I cannot guarantee that upgrading fixes your problem.  But I think your chances are good.

    You might consider using a newer compiler with that old CCS 3.3.  That combination has not been tested.  It often works.  But the farther apart in time the releases of CCS and the compiler, the more likely it is a problem will occur.

    To understand how your problem occurred, I need to reproduce it.  I don't need to run the code.  I can usually see the problem by inspecting the assembly code generated by the compiler.  Please submit a test case, by using these steps.

    1. Preprocess the source file which contains the function half2quan
    2. Attach that to your next post
    3. Show all the compiler options exactly as the compiler sees them

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click Verify Answer on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    The 
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.

  • In reply to George Mock:

    Hello George,

    Do you mean you are still not sure it's caused by CCS or compiler version? Is there any early log fix on this before?

    Why it can be avoided by must add volatile? We are very worry about on other variables.

    What's the test case you need? Could you kindly give some more hints on this? Thanks a lot.
  • In reply to Daniel Fang:

    Daniel Fang
    Do you mean you are still not sure it's caused by CCS or compiler version? Is there any early log fix on this before?

    We don't know the cause.  So I cannot say whether this is caused by a known bug.

    Daniel Fang
    Why it can be avoided by must add volatile?

    Using volatile disables many optimizations throughout multiple levels of the compiler.  The code generated ends up being very different in many ways.  It is not surprising the volatile avoids the problem, whatever it is.

    Daniel Fang
    What's the test case you need? Could you kindly give some more hints on this?

    A test case means I build the same source code the same way you do.  I can't run it.  But I can inspect the assembly code generated by the compiler.  This is often (though not always) good enough to discover the problem.  I list the steps needed to submit a test case in my previous post.  But I can add more detail.  First, preprocess the file.  Follow this link for more details on that process.  You end up with file named something.pp.  Add the file extension .txt to form the file name something.pp.txt.  Attach that file to your next post.  After you click on Reply, click on Use rich formatting in the lower right corner.  This brings up a message compose interface with more features.  Use the paper clip icon to attach the file.  To show the compiler build options, copy-n-paste them from the Console view in CCS.

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click Verify Answer on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    The 
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.