This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

function returning struct by value, assign it to struct, fails with -o3

Other Parts Discussed in Thread: RM48L952

Hello

Still with RM48L952. Compiler 5.0.1 and 5.0.4 (for tests)

Following example:

In FIQ interrupt isr a subfunction called function1() has a struct variable with 2 float, called myStruct and has following instruction:

myStruct = getResultFromFunction2();

getResultFromFunction2() returns a struct of same type (2 floats) by value. The function is located in another C module and is not inlined.

Running this without optimization runs as expected.

Running with -O3 has the effect, that sometimes myStruct gets other values. Not sure from where yet.

I saw: SDSCM00043229 in defect history. Are there other issues known?

Thank you for any hint!

Best Regards!

Roger

  • Roger,

    Thank you for using our forum.

    I've contacted our Code Generation Team and they will check this problem.
    I may have to move this post to the Code Gen Forum.

  • Jean-Marc,

    Can you please move this thread to the Code Gen forum.

    Thanks,
    Christian

  • Christian,

    The option to move a thread is no more available... I will check to see what is going on.

  • We'll need a complete, compilable test case which demonstrates the problem, including the complete command-line options.

  • Roger44834 said:
    Running with -O3 has the effect, that sometimes myStruct gets other values.

    Sometimes myStruct gets other values?  Anything is possible, but inconsistent behavior like that does not usually indicate a compiler problem.  It is more likely that something else is going wrong, and this is the only symptom you currently see.  Perhaps the stack is overflowing?  Or some interrupt fails to preserve all of its state?  

    Thanks and regards,

    -George

  • Thank you all for your replies.

    My colleague "Aedu", has taken the lead for this task in our team. So I will let him sending more information to you in the next days.

    Best Regards,

    Roger

  • Hi I've got the same problem. Here a very simple example:

    typedef struct {
    	float a;
    	float b;
    	float c;
    } myStruct;
    
    myStruct getStruct(int bla) {
    
    	myStruct temp;
    	temp.a = 42;
    	temp.b = 666;
    	
    	if (bla == 1) {
    		temp.a = 13;
    		temp.b = 333;
    	}
    	// here everything is fine
    	return temp;
    }
    
    void someFunc(int bla) {
    
    	myStruct local;
    	
    	local = getStruct(bla);
    	// at this point things get strange:
    	
    	// do something with local...
    }

    The problem I have is that inside someFuinc() the value of local != temp (from getStruct)

    I have two cases:

    1. bla=0
      • everything is fine
    2. bla=1
      • local.a = 42 (!!!! EVIL !!!!), local.b=333 (OK) local.c (don't care)

    The stack is not overflowing. The problem does not occur with O0.

    Once I move the "myStruct temp" variable from the stack scope to the global scope the coe works, even if I'm not sure if it's just by accident

    Is this an alignment problem?

    Regards

    Fabian

  • Are you using the TI ARM compiler?  If not, please indicate which compiler you are using.  Please tell me the compiler version and show the exact build options you use.

    Thanks and regards,

    -George

  • I'm using C6000 compiler.  The problem occurs with 7.4.9 as well as with 7.3.17

    The Build command I use is the following (Debug, working):

    cl6x --output_file myFile.obj -c -mv6713 --abi=coffabi -ms0 --relaxed_ansi --mem_model:data=far --super_quiet --display_error_number --cpp_default --gen_func_subsections=on --src_interlist -O0 -g --keep_asm -DDEBUG -DCHIP_6713 -DCHIP_6000 -DFPGA_LOAD -Isrc -IC:\ti\bios_5_42_01_09\packages\ti\bios\include -IC:\ti\ccsv6\tools\compiler\c6000_7.4.9\include -Iproject_c6713\c6xcsl\include -Isrc src\myFile.cpp

    Release-Build Command (not working):

    cl6x --output_file myFile.obj -c -mv6713 --abi=coffabi -ms0 --relaxed_ansi --mem_model:data=far --super_quiet --display_error_number --cpp_default --gen_func_subsections=on --src_interlist -O3 --symdebug:none --keep_asm -DARGUSOMDS -DRELEASE -DCHIP_6713 -DCHIP_6000 -DFPGA_LOAD -Isrc -IC:\ti\bios_5_42_01_09\packages\ti\bios\include -IC:\ti\ccsv6\tools\compiler\c6000_7.4.9\include -Iproject_c6713\c6xcsl\include -Isrc src\myFile.cpp

    However I could not reproduce the problem with a minimalistic example.

    Regards Fabian

  • Fabian Lindner said:
    I could not reproduce the problem with a minimalistic example.

    We cannot advance this issue without a test case which allows us to reproduce it.  However, it doesn't always have to be a super simple example.  In this case, send the source file(s) with the actual counterparts to someFunc and getStruct from your simple example above.  Preprocess the source file(s) like this.  Make sure there are some comments or something to indicate where things go wrong.  Indicate what you expect and what you actually get.

    Thanks and regards,

    -George

  • A colleague just gave me the tip to try the new 7.4.11 compiler release and now it works. So it seems like the bug was fixed in 7.4.11.


    Probably it has something to do with the following bugfix:

    Summary            : Variable write not happening in inlined CPP function
    
    Fixed in           : 7.4.11
    Severity           : S2 - Major
    Affected Component : Optimizer
    
    Release Notes:
      In circumstances that are not well understood, structure fields may not
      be written correctly in the presence of complicated conditional code.

    Regards Fabian