Bug 66650 - libgfortran: warning: left shift of negative value [-Wshift-negative-value]
Summary: libgfortran: warning: left shift of negative value [-Wshift-negative-value]
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 4.9.4
Assignee: Uroš Bizjak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-24 14:13 UTC by Thomas Schwinge
Modified: 2015-07-29 17:46 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-06-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwinge 2015-06-24 14:13:49 UTC
As of the changes in context of PR65179, <http://news.gmane.org/find-root.php?message_id=%3C20150422183633.GI28950%40redhat.com%3E>, I'm seeing a bunch of -Wshift-negative-value warnings in the libgfortran build, for example:

    In file included from [...]/libgfortran/intrinsics/cshift0.c:26:0:
    [...]/libgfortran/intrinsics/cshift0.c: In function 'cshift0':
    [...]/libgfortran/libgfortran.h:408:48: warning: left shift of negative value [-Wshift-negative-value]
       ((~((index_type) 0) >> GFC_DTYPE_SIZE_SHIFT) << GFC_DTYPE_SIZE_SHIFT)
                                                    ^
    [...]/libgfortran/libgfortran.h:409:35: note: in expansion of macro 'GFC_DTYPE_SIZE_MASK'
     #define GFC_DTYPE_TYPE_SIZE_MASK (GFC_DTYPE_SIZE_MASK | GFC_DTYPE_TYPE_MASK)
                                       ^
    [...]/libgfortran/libgfortran.h:411:52: note: in expansion of macro 'GFC_DTYPE_TYPE_SIZE_MASK'
     #define GFC_DTYPE_TYPE_SIZE(desc) ((desc)->dtype & GFC_DTYPE_TYPE_SIZE_MASK)
                                                        ^
    [...]/libgfortran/intrinsics/cshift0.c:94:15: note: in expansion of macro 'GFC_DTYPE_TYPE_SIZE'
       type_size = GFC_DTYPE_TYPE_SIZE (array);
                   ^

Unless this will be resolved by demoting the warning (I have not reviewed the recent discussion, such as PR66066, <http://news.gmane.org/find-root.php?message_id=%3C20150511142112.GO3384%40redhat.com%3E>), I supposed this should be fixed in libgfortran/libgfortran.h, perhaps by making index_type an unsiged type if that's possible?
Comment 1 Dominique d'Humieres 2015-06-24 16:16:34 UTC
Confirmed for r222892 and more recent revisions, not present for r222830.
Comment 2 Uroš Bizjak 2015-07-29 11:49:50 UTC
Patch that rewrites GFC_DTYPE_SIZE_MASK definition to avoid "left shift of negative value" warning:

--cut here--
Index: libgfortran.h
===================================================================
--- libgfortran.h       (revision 226339)
+++ libgfortran.h       (working copy)
@@ -404,8 +404,7 @@
 
 /* Macros to get both the size and the type with a single masking operation  */
 
-#define GFC_DTYPE_SIZE_MASK \
-  ((~((index_type) 0) >> GFC_DTYPE_SIZE_SHIFT) << GFC_DTYPE_SIZE_SHIFT)
+#define GFC_DTYPE_SIZE_MASK (-((index_type) 1 << GFC_DTYPE_SIZE_SHIFT))
 #define GFC_DTYPE_TYPE_SIZE_MASK (GFC_DTYPE_SIZE_MASK | GFC_DTYPE_TYPE_MASK)
 
 #define GFC_DTYPE_TYPE_SIZE(desc) ((desc)->dtype & GFC_DTYPE_TYPE_SIZE_MASK)
--cut here--
Comment 3 uros 2015-07-29 15:42:34 UTC
Author: uros
Date: Wed Jul 29 15:42:03 2015
New Revision: 226355

URL: https://gcc.gnu.org/viewcvs?rev=226355&root=gcc&view=rev
Log:
	PR libgfortran/66650
	* libgfortran.h (GFC_DTYPE_SIZE_MASK): Rewrite to avoid
	"left shift of negative value" warning.


Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/libgfortran.h
Comment 4 uros 2015-07-29 17:13:00 UTC
Author: uros
Date: Wed Jul 29 17:12:28 2015
New Revision: 226357

URL: https://gcc.gnu.org/viewcvs?rev=226357&root=gcc&view=rev
Log:
	PR libgfortran/66650
	* libgfortran.h (GFC_DTYPE_SIZE_MASK): Rewrite to avoid
	"left shift of negative value" warning.


Modified:
    branches/gcc-5-branch/libgfortran/ChangeLog
    branches/gcc-5-branch/libgfortran/libgfortran.h
Comment 5 uros 2015-07-29 17:45:38 UTC
Author: uros
Date: Wed Jul 29 17:45:07 2015
New Revision: 226360

URL: https://gcc.gnu.org/viewcvs?rev=226360&root=gcc&view=rev
Log:
	PR libgfortran/66650
	* libgfortran.h (GFC_DTYPE_SIZE_MASK): Rewrite to avoid
	"left shift of negative value" warning.


Modified:
    branches/gcc-4_9-branch/libgfortran/ChangeLog
    branches/gcc-4_9-branch/libgfortran/libgfortran.h
Comment 6 Uroš Bizjak 2015-07-29 17:46:45 UTC
Fixed everywhere.