aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGeorg-Johann Lay <gjl@gcc.gnu.org>2013-03-12 11:42:26 +0000
committerGeorg-Johann Lay <gjl@gcc.gnu.org>2013-03-12 11:42:26 +0000
commitf22e3c85d7529038e1e5621ae1187453d6fef2f6 (patch)
tree218bdd8cb693895b400d70c7b61830c64f4c3762 /gcc
parentdedd8ef17d484b3cb0cb094480a0ed6399e5f487 (diff)
downloadgcc-f22e3c85d7529038e1e5621ae1187453d6fef2f6.zip
gcc-f22e3c85d7529038e1e5621ae1187453d6fef2f6.tar.gz
gcc-f22e3c85d7529038e1e5621ae1187453d6fef2f6.tar.bz2
re PR target/56263 ([avr] Provide strict address-space checking)
PR target/56263 * config/avr/avr.c (TARGET_CONVERT_TO_TYPE): Define to... (avr_convert_to_type): ...this new static function. * config/avr/avr.opt (-Waddr-space-convert): New C option. * doc/invoke.texi (AVR Options): Document it. From-SVN: r196611
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/avr/avr.c63
-rw-r--r--gcc/config/avr/avr.opt4
-rw-r--r--gcc/doc/invoke.texi7
3 files changed, 73 insertions, 1 deletions
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index a35f47e..c916d6b 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -10765,6 +10765,66 @@ avr_addr_space_subset_p (addr_space_t subset ATTRIBUTE_UNUSED,
}
+/* Implement `TARGET_CONVERT_TO_TYPE'. */
+
+static tree
+avr_convert_to_type (tree type, tree expr)
+{
+ /* Print a diagnose for pointer conversion that changes the address
+ space of the pointer target to a non-enclosing address space,
+ provided -Waddr-space-convert is on.
+
+ FIXME: Filter out cases where the target object is known to
+ be located in the right memory, like in
+
+ (const __flash*) PSTR ("text")
+
+ Also try to distinguish between explicit casts requested by
+ the user and implicit casts like
+
+ void f (const __flash char*);
+
+ void g (const char *p)
+ {
+ f ((const __flash*) p);
+ }
+
+ under the assumption that an explicit casts means that the user
+ knows what he is doing, e.g. interface with PSTR or old style
+ code with progmem and pgm_read_xxx.
+ */
+
+ if (avr_warn_addr_space_convert
+ && expr != error_mark_node
+ && POINTER_TYPE_P (type)
+ && POINTER_TYPE_P (TREE_TYPE (expr)))
+ {
+ addr_space_t as_old = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (expr)));
+ addr_space_t as_new = TYPE_ADDR_SPACE (TREE_TYPE (type));
+
+ if (avr_log.progmem)
+ avr_edump ("%?: type = %t\nexpr = %t\n\n", type, expr);
+
+ if (as_new != ADDR_SPACE_MEMX
+ && as_new != as_old)
+ {
+ location_t loc = EXPR_LOCATION (expr);
+ const char *name_old = avr_addrspace[as_old].name;
+ const char *name_new = avr_addrspace[as_new].name;
+
+ warning (OPT_Waddr_space_convert,
+ "conversion from address space %qs to address space %qs",
+ ADDR_SPACE_GENERIC_P (as_old) ? "generic" : name_old,
+ ADDR_SPACE_GENERIC_P (as_new) ? "generic" : name_new);
+
+ return fold_build1_loc (loc, ADDR_SPACE_CONVERT_EXPR, type, expr);
+ }
+ }
+
+ return NULL_TREE;
+}
+
+
/* Worker function for movmemhi expander.
XOP[0] Destination as MEM:BLK
XOP[1] Source " "
@@ -12149,6 +12209,9 @@ avr_fold_builtin (tree fndecl, int n_args ATTRIBUTE_UNUSED, tree *arg,
#undef TARGET_FIXED_POINT_SUPPORTED_P
#define TARGET_FIXED_POINT_SUPPORTED_P hook_bool_void_true
+#undef TARGET_CONVERT_TO_TYPE
+#define TARGET_CONVERT_TO_TYPE avr_convert_to_type
+
#undef TARGET_ADDR_SPACE_SUBSET_P
#define TARGET_ADDR_SPACE_SUBSET_P avr_addr_space_subset_p
diff --git a/gcc/config/avr/avr.opt b/gcc/config/avr/avr.opt
index 134a1d4..6b2e755 100644
--- a/gcc/config/avr/avr.opt
+++ b/gcc/config/avr/avr.opt
@@ -74,3 +74,7 @@ When accessing RAM, use X as imposed by the hardware, i.e. just use pre-decremen
msp8
Target Report RejectNegative Var(avr_sp8) Init(0)
The device has no SPH special function register. This option will be overridden by the compiler driver with the correct setting if presence/absence of SPH can be deduced from -mmcu=MCU.
+
+Waddr-space-convert
+Warning C Report Var(avr_warn_addr_space_convert) Init(0)
+Warn if the address space of an address is change.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d81c78d..a3f3d5a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -514,7 +514,7 @@ Objective-C and Objective-C++ Dialects}.
@emph{AVR Options}
@gccoptlist{-mmcu=@var{mcu} -maccumulate-args -mbranch-cost=@var{cost} @gol
-mcall-prologues -mint8 -mno-interrupts -mrelax @gol
--mstrict-X -mtiny-stack}
+-mstrict-X -mtiny-stack -Waddr-space-convert}
@emph{Blackfin Options}
@gccoptlist{-mcpu=@var{cpu}@r{[}-@var{sirevision}@r{]} @gol
@@ -11649,6 +11649,11 @@ when @code{EICALL} or @code{EIJMP} instructions are used.
Indirect jumps and calls on these devices are handled as follows by
the compiler and are subject to some limitations:
+@item -Waddr-space-convert
+@opindex Waddr-space-convert
+Warn about conversions between address spaces in the case where the
+resulting address space is not contained in the incoming address space.
+
@itemize @bullet
@item