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.

Compiler/CCSTUDIO: instruction is commented by #define preprocessor directive, but program still run to there.

Part Number: CCSTUDIO


Tool/software: TI C/C++ Compiler

IDE: CCS 8.2.0

compiler: TI v5.2.5

chip: am335x

screenshot: https://imgur.com/a/jd0TMAm

It's clear to see that at line 186(while(*d++ = *s++)) is commented by preprocessor directive.

but the disassembly run to there.

As per this theme: https://e2e.ti.com/support/tools/ccs/f/81/t/749457

I've checked the option.

Please give me a hand, thanks

  • That's what things look like when a call to strcpy is inlined.  That is, instead of calling the function strcpy, the code for the strcpy function is copied to the call site, then optimized into the surrounding context.  This is an example of where compiler optimization can cause confusion while debugging.

    Thanks and regards,

    -George

  • Hello Andy,

    recompile your source with assembly file preserving option.
    Check your .asm file.
    Probably _INLINE or/and _STRCPY is defined.
  • Hi, George.
    Are u saying this is a common thing when it comes to lnline?
    I'm not clear about this concept and I'm an ESL. Can you give me some direction?
    What do you mean by "strcpy is inlined", I just saw a normal usage of #if defined (_INLINE).

    FYI, the commented block is not only for line 180 to 189, but from line 118(top side) to bottom line(347).
  • Hi Tomasz,

    Are you saying the option what I referred in link?
    If so, I already checked it.
  • Yes, check assembler file.
  • Andy Lin94 said:
    Are u saying this is a common thing when it comes to lnline?

    Yes

    Andy Lin94 said:
    I'm not clear about this concept and I'm an ESL. Can you give me some direction?

    For general background on the topic, do a web search on the term inline expansion.  

    But I think an example, similar to your situation, is also helpful.  Start with this simple, contrived, source file ...

    /* inline_expansion.c */
    
    #include <string.h>
    
    void fxn(char *dst, char *src)
    {
       strcpy(dst, src);
    }

    Build it like this ...

    % armcl --opt_level=3 --opt_for_speed=3 --gen_acp_raw inline_expansion.c

    The options --opt_level=3 and --opt_for_speed=3 are chosen because they are the simplest thing I could find which matches what you show in your screen shot.  I'm sure your build options are different.  But these options are close enough for this example.

    The option --gen_acp_raw says to create a preprocessor listing file.  In this case the file inline_expansion.rl is created.  (For those following along, the option --gen_acp_raw is replaced by the option --gen_preprocessor_listing in recent compiler versions.  Note this customer is using a fairly old version 5.2.5.  At some point, the old option --gen_acp_raw will no longer be accepted.)  Read more about all the options in the ARM compiler manual.

    Inspect the file inline_expansion.rl with your favorite text editor.  Search for strcpy.  These lines are key ...

    N#if defined(_INLINE) || defined(_STRCPY)
    X#if 1L || 0L
    N_OPT_IDEFN char *strcpy(register char *dest, register const char *src)
    Xstatic __inline char *strcpy(register char *dest, register const char *src)
    N{
    N     register char       *d = dest;     
    N     register const char *s = src;
    N
    N     while (*d++ = *s++);
    N     return dest;
    N}

    In the preprocessor listing, every line is prepended with a character which indicates some information about that line.  N stands for a normal line copied straight from the source file.  If non-trivial preprocessing occurs, an N line is followed by an X line.  The X line shows what the compiler sees after the preprocessing phase.  The net result, in this case, is that the compiler sees the full implementation of the function strcpy, modified by the qualifiers static __inline.  These qualifiers tell the compiler to perform an inline expansion of strcpy at every site where it is called.

    Which is what happens in your case.  I hope this makes it clear why, after all these transformations, the final result can be difficult to debug.

    Thanks and regards,

    -George

  • Andy Lin94 said:
    I'm an ESL.

    Could you explain the ESL?
    English is not my native language.

  • English as a second language