2010-07-12 Yao Qi Merge from Sourcery G++ 4.4: 2009-10-06 Paul Brook Issue #3869 gcc/ * target.h (gcc_target): Add warn_func_result. * target-def.h (TARGET_WARN_FUNC_RESULT): Define and use. * tree-cfg.h (execute_warn_function_return): Use targetm.warn_func_result. * config/arm/arm.c (TARGET_WARN_FUNC_RESULT): Define. (arm_warn_func_result): New function. gcc/testuite/ * gcc.target/arm/naked-3.c: New test. 2010-07-10 Sandra Loosemore Backport from mainline: === modified file 'gcc/config/arm/arm.c' --- old/gcc/config/arm/arm.c 2010-07-29 16:58:56 +0000 +++ new/gcc/config/arm/arm.c 2010-07-30 13:58:02 +0000 @@ -214,6 +214,7 @@ static int arm_issue_rate (void); static void arm_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; static bool arm_allocate_stack_slots_for_args (void); +static bool arm_warn_func_result (void); static const char *arm_invalid_parameter_type (const_tree t); static const char *arm_invalid_return_type (const_tree t); static tree arm_promoted_type (const_tree t); @@ -378,6 +379,9 @@ #undef TARGET_TRAMPOLINE_ADJUST_ADDRESS #define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address +#undef TARGET_WARN_FUNC_RESULT +#define TARGET_WARN_FUNC_RESULT arm_warn_func_result + #undef TARGET_DEFAULT_SHORT_ENUMS #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums @@ -2008,6 +2012,14 @@ return !IS_NAKED (arm_current_func_type ()); } +static bool +arm_warn_func_result (void) +{ + /* Naked functions are implemented entirely in assembly, including the + return sequence, so suppress warnings about this. */ + return !IS_NAKED (arm_current_func_type ()); +} + /* Output assembler code for a block containing the constant parts of a trampoline, leaving space for the variable parts. === modified file 'gcc/target-def.h' --- old/gcc/target-def.h 2010-03-24 20:44:48 +0000 +++ new/gcc/target-def.h 2010-07-30 13:58:02 +0000 @@ -212,6 +212,10 @@ #define TARGET_EXTRA_LIVE_ON_ENTRY hook_void_bitmap #endif +#ifndef TARGET_WARN_FUNC_RESULT +#define TARGET_WARN_FUNC_RESULT hook_bool_void_true +#endif + #ifndef TARGET_ASM_FILE_START_APP_OFF #define TARGET_ASM_FILE_START_APP_OFF false #endif @@ -1020,6 +1024,7 @@ TARGET_EMUTLS, \ TARGET_OPTION_HOOKS, \ TARGET_EXTRA_LIVE_ON_ENTRY, \ + TARGET_WARN_FUNC_RESULT, \ TARGET_UNWIND_TABLES_DEFAULT, \ TARGET_HAVE_NAMED_SECTIONS, \ TARGET_HAVE_SWITCHABLE_BSS_SECTIONS, \ === modified file 'gcc/target.h' --- old/gcc/target.h 2010-03-27 10:27:39 +0000 +++ new/gcc/target.h 2010-07-30 13:58:02 +0000 @@ -1171,6 +1171,10 @@ bits in the bitmap passed in. */ void (*live_on_entry) (bitmap); + /* Return false if warnings about missing return statements or suspect + noreturn attributes should be suppressed for the current function. */ + bool (*warn_func_result) (void); + /* True if unwinding tables should be generated by default. */ bool unwind_tables_default; === added file 'gcc/testsuite/gcc.target/arm/naked-3.c' --- old/gcc/testsuite/gcc.target/arm/naked-3.c 1970-01-01 00:00:00 +0000 +++ new/gcc/testsuite/gcc.target/arm/naked-3.c 2010-07-30 13:58:02 +0000 @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall" } */ +/* Check that we do not get warnings about missing return statements + or bogus looking noreturn functions. */ +int __attribute__((naked)) +foo(void) +{ + __asm__ volatile ("mov r0, #1\r\nbx lr\n"); +} + +int __attribute__((naked,noreturn)) +bar(void) +{ + __asm__ volatile ("frob r0\n"); +} === modified file 'gcc/tree-cfg.c' --- old/gcc/tree-cfg.c 2010-03-16 12:31:38 +0000 +++ new/gcc/tree-cfg.c 2010-07-30 13:58:02 +0000 @@ -47,6 +47,7 @@ #include "value-prof.h" #include "pointer-set.h" #include "tree-inline.h" +#include "target.h" /* This file contains functions for building the Control Flow Graph (CFG) for a function tree. */ @@ -7092,6 +7093,9 @@ edge e; edge_iterator ei; + if (!targetm.warn_func_result()) + return 0; + /* If we have a path to EXIT, then we do return. */ if (TREE_THIS_VOLATILE (cfun->decl) && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0)