diff --git a/gcc/config/avr/avr-c.cc b/gcc/config/avr/avr-c.cc index 53f15f2be7b3b743052c2f8865b2a4f8e2e2d6cb..f4236555bf6cf326ea98b3633052326e974081eb 100644 --- a/gcc/config/avr/avr-c.cc +++ b/gcc/config/avr/avr-c.cc @@ -500,7 +500,8 @@ avr_cpu_cpp_builtins (cpp_reader *pfile) not a specific builtin is available. */ #define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS) \ - cpp_define (pfile, "__BUILTIN_AVR_" #NAME); + if (avr_builtin_supported_p (AVR_BUILTIN_ ## NAME)) \ + cpp_define (pfile, "__BUILTIN_AVR_" #NAME); #include "builtins.def" #undef DEF_BUILTIN diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h index 83137c7f6f63fbee8c3354ec936483b301261d22..6f37c48143ec82377a785ba18eec9ae2deaf864d 100644 --- a/gcc/config/avr/avr-protos.h +++ b/gcc/config/avr/avr-protos.h @@ -21,6 +21,7 @@ extern bool avr_function_arg_regno_p (int r); extern void avr_cpu_cpp_builtins (cpp_reader * pfile); +extern bool avr_builtin_supported_p (unsigned id); extern enum reg_class avr_regno_reg_class (int r); extern void asm_globalize_label (FILE *file, const char *name); extern void avr_adjust_reg_alloc_order (void); diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index 656d3e7389b4f2a7c812346ed31191d245d11f8d..2b550e7761c8ca96aa85945c48a766a80585db01 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -15689,6 +15689,24 @@ avr_bdesc[AVR_BUILTIN_COUNT] = }; +/* Some of our built-in function are available for GNU-C only: + - Built-ins that use named address-spaces. + - Built-ins that use fixed-point types. */ + +bool +avr_builtin_supported_p (unsigned id) +{ + const bool uses_as = id == AVR_BUILTIN_FLASH_SEGMENT; + + // We don't support address-spaces on Reduced Tiny. + if (AVR_TINY && uses_as) + return false; + + return (lang_GNU_C () + || id < AVR_FIRST_C_ONLY_BUILTIN_ID); +} + + /* Implement `TARGET_BUILTIN_DECL'. */ static tree @@ -15891,9 +15909,10 @@ avr_init_builtins (void) char *name = (char *) alloca (1 + strlen (Name)); \ \ gcc_assert (id < AVR_BUILTIN_COUNT); \ - avr_bdesc[id].fndecl \ - = add_builtin_function (avr_tolower (name, Name), TYPE, id, \ - BUILT_IN_MD, LIBNAME, ATTRS); \ + avr_bdesc[id].fndecl = avr_builtin_supported_p (id) \ + ? add_builtin_function (avr_tolower (name, Name), TYPE, id, \ + BUILT_IN_MD, LIBNAME, ATTRS) \ + : NULL_TREE; \ } #include "builtins.def" #undef DEF_BUILTIN diff --git a/gcc/config/avr/builtins.def b/gcc/config/avr/builtins.def index 61dbc3a6c1be4369bd100ccc87d39653b7d14d14..ad75fe9c267ce6a5fea73cdaad7a5bc4e60b7302 100644 --- a/gcc/config/avr/builtins.def +++ b/gcc/config/avr/builtins.def @@ -34,6 +34,8 @@ ATTRS: Function attributes like "attr_const" for the `const' attribute or "NULL_TREE" for no attribute. */ +#define AVR_FIRST_C_ONLY_BUILTIN_ID AVR_BUILTIN_FLASH_SEGMENT + /* Mapped to respective instruction. */ DEF_BUILTIN (NOP, -1, void_ftype_void, nothing, NULL, NULL_TREE) @@ -56,6 +58,11 @@ DEF_BUILTIN (DELAY_CYCLES, -1, void_ftype_uintSI, nothing, NULL, NULL_TREE) DEF_BUILTIN (NOPS, -1, void_ftype_uintSI, nothing, NULL, NULL_TREE) DEF_BUILTIN (MASK1, 2, uintQI_ftype_uintQI_uintQI, gen_mask1, NULL, attr_const) DEF_BUILTIN (INSERT_BITS, 3, uintQI_ftype_uintSI_uintQI_uintQI, insert_bits, NULL, attr_const) + +/* All following built-ins are C only, see avr.cc::avr_builtin_C_only_p() + * since they are using named address-spaces or fixed-point types, none + * of which are supported for C++. */ + DEF_BUILTIN (FLASH_SEGMENT, 1, intQI_ftype_const_memx_ptr, flash_segment, NULL, attr_const) /* ISO/IEC TR 18037 "Embedded C" diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 2764597a479b3412d795a0ea555decf4ecd75009..c6e7bc37f7dc419589ab798499c0d9b4cc882128 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -17369,14 +17369,6 @@ might increase delay time. @var{ticks} must be a compile-time integer constant; delays with a variable number of cycles are not supported. @enddefbuiltin -@defbuiltin{int8_t __builtin_avr_flash_segment (const __memx void*)} -This built-in takes a byte address to the 24-bit -@ref{AVR Named Address Spaces,address space} @code{__memx} and returns -the number of the flash segment (the 64 KiB chunk) where the address -points to. Counting starts at @code{0}. -If the address does not point to flash memory, return @code{-1}. -@enddefbuiltin - @defbuiltin{uint8_t __builtin_avr_insert_bits (uint32_t @var{map}, uint8_t @var{bits}, uint8_t @var{val})} Insert bits from @var{bits} into @var{val} and return the resulting value. The nibbles of @var{map} determine how the insertion is @@ -17445,6 +17437,16 @@ Insert @var{count} @code{NOP} instructions. The number of instructions must be a compile-time integer constant. @enddefbuiltin +@b{All of the following built-in functions are only available for GNU-C} + +@defbuiltin{int8_t __builtin_avr_flash_segment (const __memx void*)} +This built-in takes a byte address to the 24-bit +@ref{AVR Named Address Spaces,named address space} @code{__memx} and returns +the number of the flash segment (the 64 KiB chunk) where the address +points to. Counting starts at @code{0}. +If the address does not point to flash memory, return @code{-1}. +@enddefbuiltin + @noindent There are many more AVR-specific built-in functions that are used to implement the ISO/IEC TR 18037 ``Embedded C'' fixed-point functions of