[EXT_EP-10833] Compiler fails to handle bare \r as a line separator Created: 06/Jun/22  Updated: 02/Apr/24  Resolved: 29/Jun/22

Status: Fixed
Project: Embedded Software & Tools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: High
Reporter: TI User Assignee: TI User
Resolution: Fixed Votes: 0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Product: Code Generation Tools
Internal ID: CODEGEN-10058
Forum URL: https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1103378/tms320f280025-compiler-issue
Found In Release: C7000_1.4.0.LTS
C2000_22.6.0.LTS
C6000_8.3.0
MSP430_20.2.0.LTS
C7000_2.1.0.LTS
MSP430_21.6.0.LTS
C2000_21.6.0.LTS
ARM_20.2.0.LTS
C2000_20.2.0.LTS
Fix In Release: ARM_20.2.7.LTS
C7000_2.1.2.LTS
C2000_20.2.7.LTS
C2000_22.6.1.LTS
MSP430_21.6.1.LTS
C6000_8.3.13
C7000_1.4.3.LTS
C2000_21.6.1.LTS
MSP430_20.2.7.LTS
Affected Platform/Device: default
Workaround: Insert a carriage return \n or \r\n before the affected line of code.

 Description   

The parser for the TI compiler treats stand alone carriage return \r as white space.

If a line of code (function call, expression, etc) following a line with
comments ending in \r, then the line of code will be treated as comments.

For below example, the function call two() is treated as comments as continued from the comments at end of the previous line.

void one(), two();

void line_ending_test()

{ one(); // this line ends with only \r two(); }

More details
--------------
The attached source uses Windows text file line endings \r \n. Except one line has been intentionally changed to end only with \r. Even viewing this file is odd, because it depends on how the viewer software handles the case of a bare \r character. Here is a character by character dump using the utility od ...

% od -An -c -w10 line_ending_test.c
   v   o   i   d       o   n   e   (   )
   ,       t   w   o   (   )   ;  \r  \n
  \r  \n   v   o   i   d       l   i   n
   e   _   e   n   d   i   n   g   _   t
   e   s   t   (   )  \r  \n   {  \r  \n
               o   n   e   (   )   ;
   /   /       t   h   i   s       l   i
   n   e       e   n   d   s       w   i
   t   h       o   n   l   y       \   r
  \r               t   w   o   (   )   ;
  \r  \n   }  \r  \n

Notice how every line ends with the sequence \r \n, except for the one with the comment: // this line ends with only \r . The TI proprietary compilers, including cl2000, view the bare \r character like a space or tab. It does not cause the line to end. Thus, the call to the function two() is commented out. Every other compiler I tried, including tiarmclang, views the bare \r as a line separator. Thus, the call to the function two() is not commented out. This is easily verified by viewing the assembly code generated by the compiler. I loaded this into compiler explorer, and tried many compilers. https://godbolt.org/z/Tfa7hTPad . Every one I tried generates a call to the function two().


Generated at Thu Apr 10 14:37:41 CDT 2025 using Jira 9.12.17#9120017-sha1:aba4002bcd633f188b6a4bb5dd8a0e1f20b79ee4.