public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix invalid left shift of negative value.
@ 2015-11-10 11:11 Dominik Vogt
  2015-11-10 11:13 ` [PATCH 1/2] " Dominik Vogt
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dominik Vogt @ 2015-11-10 11:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Arnez, Andreas Krebbel

The following series of patches fixes all occurences of
left-shifting negative constants in C code which is undefined by
the C standard.  The patches have been tested on s390x, covering
only a small subset of the changes.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

* Re: [PATCH 1/2] Fix invalid left shift of negative value.
  2015-11-10 11:11 [PATCH 0/2] Fix invalid left shift of negative value Dominik Vogt
@ 2015-11-10 11:13 ` Dominik Vogt
  2015-11-10 16:51   ` Mike Stump
  2015-11-10 11:14 ` [PATCH 2/2] " Dominik Vogt
  2015-11-10 11:16 ` [PATCH 0/2] " Dominik Vogt
  2 siblings, 1 reply; 5+ messages in thread
From: Dominik Vogt @ 2015-11-10 11:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Arnez, Andreas Krebbel

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

On Tue, Nov 10, 2015 at 12:11:23PM +0100, Dominik Vogt wrote:
> The following series of patches fixes all occurences of
> left-shifting negative constants in C code which is undefined by
> the C standard.  The patches have been tested on s390x, covering
> only a small subset of the changes.

Changes in gdb/.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0001-gdb-Fix-left-shift-of-negative-value.patch --]
[-- Type: text/x-diff, Size: 2913 bytes --]

From f0480d41f3036d193513fa4dfbba414201b610ec Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 30 Oct 2015 15:17:22 +0100
Subject: [PATCH 1/2] gdb: Fix left shift of negative value.

This patch fixes all occurences of left-shifting negative constants in C cod
which is undefined by the C standard.

gdb/ChangeLog:

        * hppa-tdep.c (hppa_sign_extend, hppa_low_hppa_sign_extend)
        (prologue_inst_adjust_sp, hppa_frame_cache): Fix left shift of negative
        value.
        * dwarf2read.c (read_subrange_type): Likewise.
---
 gdb/ChangeLog    | 7 +++++++
 gdb/dwarf2read.c | 2 +-
 gdb/hppa-tdep.c  | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 87dc8b4..48921e7 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15048,7 +15048,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      the bounds as signed, and thus sign-extend their values, when
      the base type is signed.  */
   negative_mask =
-    (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
+    -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
   if (low.kind == PROP_CONST
       && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
     low.data.const_val |= negative_mask;
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index ba7f946..3206729 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -104,7 +104,7 @@ static const struct objfile_data *hppa_objfile_priv_data = NULL;
 static int
 hppa_sign_extend (unsigned val, unsigned bits)
 {
-  return (int) (val >> (bits - 1) ? (-1 << bits) | val : val);
+  return (int) (val >> (bits - 1) ? (-(1 << bits)) | val : val);
 }
 
 /* For many immediate values the sign bit is the low bit!  */
@@ -112,7 +112,7 @@ hppa_sign_extend (unsigned val, unsigned bits)
 static int
 hppa_low_hppa_sign_extend (unsigned val, unsigned bits)
 {
-  return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
+  return (int) ((val & 0x1 ? (-(1 << (bits - 1))) : 0) | val >> 1);
 }
 
 /* Extract the bits at positions between FROM and TO, using HP's numbering
@@ -1357,7 +1357,7 @@ prologue_inst_adjust_sp (unsigned long inst)
 
   /* std,ma X,D(sp) */
   if ((inst & 0xffe00008) == 0x73c00008)
-    return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
+    return (inst & 0x1 ? -(1 << 13) : 0) | (((inst >> 4) & 0x3ff) << 3);
 
   /* addil high21,%r30; ldo low11,(%r1),%r30)
      save high bits in save_high21 for later use.  */
@@ -2066,7 +2066,7 @@ hppa_frame_cache (struct frame_info *this_frame, void **this_cache)
 		CORE_ADDR offset;
 		
 		if ((inst >> 26) == 0x1c)
-		  offset = (inst & 0x1 ? -1 << 13 : 0)
+		  offset = (inst & 0x1 ? -(1 << 13) : 0)
 		    | (((inst >> 4) & 0x3ff) << 3);
 		else if ((inst >> 26) == 0x03)
 		  offset = hppa_low_hppa_sign_extend (inst & 0x1f, 5);
-- 
2.3.0


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

* Re: [PATCH 2/2] Fix invalid left shift of negative value.
  2015-11-10 11:11 [PATCH 0/2] Fix invalid left shift of negative value Dominik Vogt
  2015-11-10 11:13 ` [PATCH 1/2] " Dominik Vogt
@ 2015-11-10 11:14 ` Dominik Vogt
  2015-11-10 11:16 ` [PATCH 0/2] " Dominik Vogt
  2 siblings, 0 replies; 5+ messages in thread
From: Dominik Vogt @ 2015-11-10 11:14 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Arnez, Andreas Krebbel

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

On Tue, Nov 10, 2015 at 12:11:23PM +0100, Dominik Vogt wrote:
> The following series of patches fixes all occurences of
> left-shifting negative constants in C code which is undefined by
> the C standard.  The patches have been tested on s390x, covering
> only a small subset of the changes.

Changes in gdb/testsuite/.  I'm not sure whether these are good or
not.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

[-- Attachment #2: 0002-gdb-testsuite-Fix-left-shift-of-negative-value.patch --]
[-- Type: text/x-diff, Size: 1935 bytes --]

From d1cbc6f371e2720fe4bf4975d8ad9c81a9f01351 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 30 Oct 2015 15:18:06 +0100
Subject: [PATCH 2/2] gdb/testsuite: Fix left shift of negative value.

This patch fixes all occurences of left-shifting negative constants in C cod
which is undefined by the C standard.

gdb/testsuite/ChangeLog:

        * lib/dwarf.exp (_note): Fix left shift of negative value.
        * gdb.trace/trace-condition.exp: Likewise.
---
 gdb/testsuite/gdb.trace/trace-condition.exp | 2 +-
 gdb/testsuite/lib/dwarf.exp                 | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.trace/trace-condition.exp b/gdb/testsuite/gdb.trace/trace-condition.exp
index aec0401..46fa5ed 100644
--- a/gdb/testsuite/gdb.trace/trace-condition.exp
+++ b/gdb/testsuite/gdb.trace/trace-condition.exp
@@ -152,7 +152,7 @@ foreach trace_command { "trace" "ftrace" } {
     test_tracepoints $trace_command "21 * 2 == 42" 10
     test_tracepoints $trace_command "21 << 1 == 42" 10
     test_tracepoints $trace_command "42 >> 1 == 21" 10
-    test_tracepoints $trace_command "-21 << 1 == -42" 10
+    test_tracepoints $trace_command "-(21 << 1) == -42" 10
     test_tracepoints $trace_command "-42 >> 1 == -21" 10
     test_tracepoints $trace_command "(0xabababab & 0x0000ffff) == 0xabab" 10
     test_tracepoints $trace_command "(0xabababab | 0x0000ffff) == 0xababffff" 10
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 9716795..c87da87 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -1289,7 +1289,7 @@ namespace eval Dwarf {
 	_op .ascii [_quote $name]
 	# Alignment.
 	set align 2
-	set total [expr {($namelen + (1 << $align) - 1) & (-1 << $align)}]
+	set total [expr {($namelen + (1 << $align) - 1) & -(1 << $align)}]
 	for {set i $namelen} {$i < $total} {incr i} {
 	    _op .byte 0
 	}
-- 
2.3.0


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

* Re: [PATCH 0/2] Fix invalid left shift of negative value.
  2015-11-10 11:11 [PATCH 0/2] Fix invalid left shift of negative value Dominik Vogt
  2015-11-10 11:13 ` [PATCH 1/2] " Dominik Vogt
  2015-11-10 11:14 ` [PATCH 2/2] " Dominik Vogt
@ 2015-11-10 11:16 ` Dominik Vogt
  2 siblings, 0 replies; 5+ messages in thread
From: Dominik Vogt @ 2015-11-10 11:16 UTC (permalink / raw)
  To: gcc-patches

Sorry, wrong mailing list, please ignore.

On Tue, Nov 10, 2015 at 12:11:23PM +0100, Dominik Vogt wrote:
> The following series of patches fixes all occurences of
> left-shifting negative constants in C code which is undefined by
> the C standard.  The patches have been tested on s390x, covering
> only a small subset of the changes.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

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

* Re: [PATCH 1/2] Fix invalid left shift of negative value.
  2015-11-10 11:13 ` [PATCH 1/2] " Dominik Vogt
@ 2015-11-10 16:51   ` Mike Stump
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Stump @ 2015-11-10 16:51 UTC (permalink / raw)
  To: vogt; +Cc: gcc-patches, Andreas Arnez, Andreas Krebbel

On Nov 10, 2015, at 3:13 AM, Dominik Vogt <vogt@linux.vnet.ibm.com> wrote:
> On Tue, Nov 10, 2015 at 12:11:23PM +0100, Dominik Vogt wrote:
>> The following series of patches fixes all occurences of
>> left-shifting negative constants in C code which is undefined by
>> the C standard.  The patches have been tested on s390x, covering
>> only a small subset of the changes.
> 
> Changes in gdb/.

So, should these go to the gdb list?

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

end of thread, other threads:[~2015-11-10 16:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-10 11:11 [PATCH 0/2] Fix invalid left shift of negative value Dominik Vogt
2015-11-10 11:13 ` [PATCH 1/2] " Dominik Vogt
2015-11-10 16:51   ` Mike Stump
2015-11-10 11:14 ` [PATCH 2/2] " Dominik Vogt
2015-11-10 11:16 ` [PATCH 0/2] " Dominik Vogt

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).