GCC Extensions in TI Compilers

From Texas Instruments Wiki
Jump to: navigation, search

Introduction

The GNU Compiler Collection (GCC) supports many language features not found in the ANSI/ISO standards for C and C++. The GCC compilers (gcc and g++) are widely used, particularly in open source applications. In order to allow users to compile code developed using the GCC tools, TI compilers can accept some GCC language extensions. This article describes the state of support for the GCC extensions in the TI C/C++ compilers.


Overview

The current (Sept 2010) GCC release is GCC 4.5. The definition and examples of the language extensions may be found at the GNU web site, in particular in the documentation for GCC 4.5.

Production TI compilers began including this support in 2006, and by 2007 it was available for all target architectures. An upgrade of the support began appearing in late 2010. The following table identifies the relevant compiler versions for the various targets. See Production Compiler Releases for information on release availability.


Target Initial
Release
Upgrade
Release
Compiler
User’s Guide
ARM 4.4.0 4.8.0 spnu151
C2000 5.0.0 6.0.0 spru514
C5500 4.0.0 4.4.0 spru281
C6000 6.1.0 7.2.0 spru187
MSP430 2.0.0 4.0.0 slau132


The Optimizing C/C++ Compiler User’s Guide for your target has a section entitled GNU C Compiler Extensions which lists the supported extensions. However, depending on the publication date of the manual and the compiler release date, the manual may not reflect the exact level of support available in your compiler.


Enabling GCC Language Extensions

The GCC language extensions are available when compiling in “Relaxed ANSI” mode (selected by the --relaxed_ansi option) or when the --gcc option is used.

Most extensions (when supported) are available in both C and C++, but not all are specified by GCC as being included in C++. Prior to the Upgrade Release the GCC extensions were not supported for C++ by the TI compilers.

 Prior to the Upgrade Release the GCC extensions are not included in Relaxed ANSI mode; --gcc must be used.


Language Features

The following table of features is based on the list of extensions given at the GNU web site (GCC 4.5). Each feature name is a link to the corresponding GNU definition of the feature.

Code Availability
Key to When column
-- Not supported
A Initial Release
B Upgrade Release


Feature When Description
Statement Exprs A Putting statements and declarations inside expressions
Local Labels A Labels local to a block
Labels as Values -- Getting pointers to labels, and computed gotos
Nested Functions -- As in Algol and Pascal, lexical scoping of functions
Constructing Calls -- Dispatching a call to another function.
Naming Types A Giving a name to the type of some expression
Typeof A typeof: referring to the type of an expression.
Generalized Lvalues A Using '?:', ',' and casts in lvalues.
Conditionals A Omitting the middle operand of a '?:' expression.
Long Long A Double-word integers---long long int.
Complex -- Data types for complex numbers.
Floating Types -- Additional floating types.
Decimal Float -- Decimal floating types.
Hex Floats -- Hexadecimal floating-point constants.
Fixed-Point -- Fixed-point types.
Named Address Spaces -- Named address spaces.
Zero Length A Zero-length arrays.
Variable Length -- Arrays whose length is computed at run time. For alloca(), see GNU alloca in TI Compilers
Empty Structures A Structures with no members.
Variadic Macros A Macros with a variable number of arguments.
Escaped Newlines -- Slightly looser rules for escaped newlines.
Multi-line Strings A String literals with embedded newlines
Subscripting A Any array can be subscripted, even if not an lvalue.
Pointer Arith B Arithmetic on void-pointers and function pointers.
Initializers A Non-constant initializers.
Compound Literals A Compound literals give structures, unions or arrays as values.
Designated Inits B Labeling elements of initializers.
Cast to Union A Casting to union type from any member of the union.
Case Ranges A 'case 1 ... 9' and such.
Mixed Declarations A Mixing declarations and code.
Function Attributes A Declaring that functions have no side effects, or that they can never return. (See details below)
Attribute Syntax A Formal syntax for attributes.
Function Prototypes A Prototype declarations and old-style definitions.
C++ Comments A C++ comments are recognized.
Dollar Signs A Dollar sign is allowed in identifiers.
Character Escapes A '\e' stands for the character <ESC>.
Variable Attributes A Specifying attributes of variables. (See details below)
Type Attributes A Specifying attributes of types. (See details below)
Alignment A Inquiring about the alignment of a type or variable. (__alignof__)
Inline A Defining inline functions (as fast as macros).
Extended Asm -- Assembler instructions with C expressions as operands.
Constraints -- Constraints for asm operands
Asm Labels A Specifying the assembler name to use for a C symbol.
Explicit Reg Vars -- Defining variables residing in specified registers.
Alternate Keywords A __const__, __asm__, etc., for header files. (also __extension__)
Incomplete Enums A Define an enum tag without specifying its values
Function Names A Printable strings which are the name of the current function (__FUNCTION__, etc)
Return Address A Getting the return or frame address of a function.
Vector Extensions -- Using vector instructions through built-in functions.
Offsetof -- Special syntax for implementing offsetof.
Atomic Builtins -- Built-in functions for atomic memory access.
Object Size Checking -- Built-in functions for limited buffer overflow checking.
Other Builtins A Other built-in functions. (See details below)
Target Builtins A Built-in functions specific to particular targets.
Target Format Checks n/a Format checks specific to particular targets. (Solaris-only)
Pragmas -- Pragmas accepted by GCC.
Unnamed Fields A Unnamed struct/union fields within structs/unions.
Thread-Local -- Per-thread variables.
Binary constants -- Binary constants using the '0b' prefix.


Notes

  • Statement Expressions are not currently available in C++.
  • The Naming Types feature was dropped after GCC 3.1, but is still supported in the TI compiler.
  • For MSP430 support for the long long type was added in the Upgrade Release.
  • When the long long type is supported it is always available even in strict ANSI mode.
  • The Multi-line Strings feature was dropped after GCC 3.2, but is still supported in the TI compiler.
  • The Desiginated Inits feature was supported for struct types in the Initial Release.
  • In the Initial Release the following features were not rejected even though they were not supported by the compiler: Labels as Values, Hex Floats, Pointer Arith, Extended Asm, Constraints, and Explicit Reg Vars.
  • Not all function attributes, variable attributes, type attributes, and builtin functions are supported. See the following sections for details on these features.

Attributes

Function Attributes

Function attribute definitions and examples at the GNU web site.


Available in Initial Release

deprecated, section, unused, visibility (C60 EABI only)
Added in Upgrade Release

always_inline, const, constructor, format, format_arg, malloc, noinline, noreturn/volatile,
pure, used, warn_unused_result, weak (EABI only)

Notes

  • The format attribute is applied to the declarations of printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf, scanf, fscanf and sscanf in stdio.h. This means that when GCC extensions are available the data arguments of these functions will be type checked against the format specifiers in the format string argument and warnings issued when there is a mismatch. These warnings can be suppressed in the usual ways if they are not desired.
  • The malloc attribute is applied to the declarations of malloc, calloc, realloc and memalign in stdlib.h


Variable Attributes

Variable attribute definitions and examples at the GNU web site.


Available in Initial Release

deprecated, section, unused
Added in Upgrade Release

aligned, mode, packed, transparent_union, used, weak (EABI only)

Notes

  • See the notes about packed (struct/union) in the Type Attributes section.


Type Attributes

Type attribute definitions and examples at the GNU web site.


Available in Initial Release

packed (enum), unused, visibility (C60 EABI only)
Added in Upgrade Release

aligned, deprecated, packed (struct/union), transparent_union

Notes

  • The packed (struct/union) attribute is NOT available for C5500 or C2000.
  • The packed (struct/union) attribute is available for C6000 only for architectures which support unaligned access (C64x, C64x+, etc.).
  • The packed (struct/union) attribute is available on ARM only for architectures which support unaligned access (Cortex) and when the --unaligned_access=on option is in effect. (Note: that --unaligned_access=on by default for architectures which support unaligned access.)
  • For ARM, the packed (struct/union) attribute may not be used, directly or indirectly, on a member of a struct or union of type long long, unsigned long long, double, or long double.
  • The packed (struct/union) attribute is also available for ARM Cortex M3 starting with version 4.6.1 and for Cortex R4 and A8 devices starting with version 4.7.0, but may not be used, directly or indirectly, on a bit-field. This restriction is lifted in the Upgrade Release.


Builtin Functions

Information about builtin functions at the GNU web site.


Available in Initial Release

__builtin_constant_p, __builtin_expect, __builtin_frame_address, __builtin_return_address
Added in Upgrade Release

__builtin_abs, __builtin_fabs, __builtin_fabsf, __builtin_labs, __builtin_llabs, __builtin_memcpy,
__builtin_sqrt, __builtin_sqrtf

Notes

  • The function __builtin_constant_p was not treated as compile-time constant in the Initial Release.
  • The function __builtin_expect does not currently provide optimization based on this construct.
  • The functions __builtin_frame_address and __builtin_return_address return zero for all arguments except a constant zero for C6000 and ARM targets. In the Initial Release they always return zero.
  • The function __builtin_llabs is available only on targets that support the type long long.
  • The functions __builtin_sqrt and __builtin_sqrtf are available only for ARM with VFP hardware.