public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch,AVR]: Fix PR56263
@ 2013-03-11 18:03 Georg-Johann Lay
  2013-03-12  7:14 ` Denis Chertykov
  2013-03-12 13:28 ` Jakub Jelinek
  0 siblings, 2 replies; 3+ messages in thread
From: Georg-Johann Lay @ 2013-03-11 18:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov, Eric Weddington

[-- Attachment #1: Type: text/plain, Size: 1223 bytes --]

This patch implements a new warning option -Waddr-space-convert warns about
conversions to a non-containing address space.

Address spaces are implemented in such a way that each address space is
contained in each other space so that casting is possible, e.g. in code like

char read_c (bool in_flash, const char *str)
{
    if (in_flash)
      return * (const __flash char*) str;
    else
      return *str;
}

However, there are no warning about implicit or explicit address space
conversions, which makes it hard to port progmem code to address space code.

If an address space qualifier is missing, e.g. when calling a function that is
not qualified correctly, this would result in wrong code (in contrast to
pgm_read that work no matter how the address is qualified).

There is still some work to do to get more precise warnings and this is just a
first take to implement PR56263, see the FIXME in the source.

The details can be worked out later, e.g. for 4.8.1.


Ok for trunk?


	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.

[-- Attachment #2: addrspace-convert.diff --]
[-- Type: text/x-patch, Size: 3426 bytes --]

Index: config/avr/avr.opt
===================================================================
--- config/avr/avr.opt	(revision 196495)
+++ config/avr/avr.opt	(working copy)
@@ -74,3 +74,7 @@ When accessing RAM, use X as imposed by
 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.
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 196495)
+++ config/avr/avr.c	(working copy)
@@ -10765,6 +10765,42 @@ avr_addr_space_subset_p (addr_space_t su
 }
 
 
+/* Implement `TARGET_CONVERT_TO_TYPE'.  */
+
+static tree
+avr_convert_to_type (tree type, tree expr)
+{
+  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 +12185,9 @@ avr_fold_builtin (tree fndecl, int n_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
 
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 196495)
+++ doc/invoke.texi	(working copy)
@@ -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
@@ -11653,6 +11653,11 @@ when @code{EICALL} or @code{EIJMP} instr
 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch,AVR]: Fix PR56263
  2013-03-11 18:03 [Patch,AVR]: Fix PR56263 Georg-Johann Lay
@ 2013-03-12  7:14 ` Denis Chertykov
  2013-03-12 13:28 ` Jakub Jelinek
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Chertykov @ 2013-03-12  7:14 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: gcc-patches, Eric Weddington

2013/3/11 Georg-Johann Lay <avr@gjlay.de>:
> This patch implements a new warning option -Waddr-space-convert warns about
> conversions to a non-containing address space.
>
> Address spaces are implemented in such a way that each address space is
> contained in each other space so that casting is possible, e.g. in code like
>
> char read_c (bool in_flash, const char *str)
> {
>     if (in_flash)
>       return * (const __flash char*) str;
>     else
>       return *str;
> }
>
> However, there are no warning about implicit or explicit address space
> conversions, which makes it hard to port progmem code to address space code.
>
> If an address space qualifier is missing, e.g. when calling a function that is
> not qualified correctly, this would result in wrong code (in contrast to
> pgm_read that work no matter how the address is qualified).
>
> There is still some work to do to get more precise warnings and this is just a
> first take to implement PR56263, see the FIXME in the source.
>
> The details can be worked out later, e.g. for 4.8.1.
>
>
> Ok for trunk?
>
>
>         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.

Approved.

Denis.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch,AVR]: Fix PR56263
  2013-03-11 18:03 [Patch,AVR]: Fix PR56263 Georg-Johann Lay
  2013-03-12  7:14 ` Denis Chertykov
@ 2013-03-12 13:28 ` Jakub Jelinek
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2013-03-12 13:28 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: gcc-patches, Denis Chertykov, Eric Weddington

On Mon, Mar 11, 2013 at 07:03:14PM +0100, Georg-Johann Lay wrote:
> 	PR target/56263
> 	* doc/invoke.texi (AVR Options): Document it.

This change broke building of info doc everywhere:

../../gcc/doc//invoke.texi:11652: @item found outside of an insertion block.
makeinfo: Removing output file `doc/gcc.info' due to errors; use --force to preserve.
make: *** [doc/gcc.info] Error 1

Fixed thusly, committed as obvious.

2013-03-12  Jakub Jelinek  <jakub@redhat.com>

	* doc/invoke.texi (-Waddr-space-convert): Move into the table earlier.

--- gcc/doc/invoke.texi	(revision 196613)
+++ gcc/doc/invoke.texi	(working copy)
@@ -11632,6 +11632,11 @@ sbiw r26, const   ; X -= const
 @item -mtiny-stack
 @opindex mtiny-stack
 Only change the lower 8@tie{}bits of the stack pointer.
+
+@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.
 @end table
 
 @subsubsection @code{EIND} and Devices with more than 128 Ki Bytes of Flash
@@ -11649,11 +11654,6 @@ when @code{EICALL} or @code{EIJMP} instr
 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


	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-12 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-11 18:03 [Patch,AVR]: Fix PR56263 Georg-Johann Lay
2013-03-12  7:14 ` Denis Chertykov
2013-03-12 13:28 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).