/* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
static const struct default_options avr_option_optimization_table[] =
{
- // With -fdelete-null-pointer-checks option, the compiler assumes
- // that dereferencing of a null pointer would halt the program.
- // For AVR this assumption is not true and a program can safely
- // dereference null pointers. Changes made by this option may not
- // work properly for AVR. So disable this option.
- { OPT_LEVELS_ALL, OPT_fdelete_null_pointer_checks, NULL, 0 },
// The only effect of -fcaller-saves might be that it triggers
// a frame without need when it tries to be smart around calls.
{ OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 },
flag_omit_frame_pointer = 0;
}
+ /* Disable flag_delete_null_pointer_checks if zero is a valid address. */
+ if (targetm.addr_space.zero_address_valid (ADDR_SPACE_GENERIC))
+ flag_delete_null_pointer_checks = 0;
+
if (flag_pic == 1)
warning (OPT_fpic, "%<-fpic%> is not supported");
if (flag_pic == 2)
(void) avr_addr_space_supported_p (as, loc);
}
+/* Implement `TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID. Zero is a valid
+ address in all address spaces. Even in ADDR_SPACE_FLASH1 etc..,
+ a zero address is valid and means 0x<RAMPZ val>0000, where RAMPZ is
+ set to the appropriate segment value. */
+
+static bool
+avr_addr_space_zero_address_valid (addr_space_t)
+{
+ return true;
+}
/* Look if DECL shall be placed in program memory space by
means of attribute `progmem' or some address-space qualifier.
#undef TARGET_ADDR_SPACE_DIAGNOSE_USAGE
#define TARGET_ADDR_SPACE_DIAGNOSE_USAGE avr_addr_space_diagnose_usage
+#undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
+#define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID avr_addr_space_zero_address_valid
+
#undef TARGET_MODE_DEPENDENT_ADDRESS_P
#define TARGET_MODE_DEPENDENT_ADDRESS_P avr_mode_dependent_address_p
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Os -Wall" } */
+
+/* Verify no "array subscript 0 is outside array bounds of" is generated
+ for accessing memory addresses in the 0-4096 range. */
+
+typedef __UINT8_TYPE__ uint8_t;
+
+#define SREG (*(volatile uint8_t*) (0x3F + __AVR_SFR_OFFSET__ ))
+
+void bar (void)
+{
+ SREG = 0;
+}
if [target_info exists keeps_null_pointer_checks] {
return 1
}
- if { [istarget msp430-*-*] } {
+ if { [istarget msp430-*-*]
+ || [istarget avr-*-*] } {
return 1;
}
return 0