public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count
@ 2005-01-06 16:01 bjoern dot m dot haase at web dot de
  2005-01-06 16:53 ` [Bug target/19293] " pinskia at gcc dot gnu dot org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: bjoern dot m dot haase at web dot de @ 2005-01-06 16:01 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]

avr-gcc crashes with an internal compiler error when shift operations with 
negative shift count are used, e.g. a >> -13. Error message is "negative 
instruction length", probably since the expression used for calculating the 
instruction length (c-code) assumes the shift count to be a positive number. 
Test cases known to fail are, e.g. . 
 
gcc.c-torture/compile/20020710-1 
                      20021119-1 
                      20021123-4 
                      920626-1 
                      930621-1 
 
Problem is present in 4.0 and I expect it to exist in all the previous 
releases. (compare the test report in gcc-testreports@gcc.gnu.org. 
 
Björn.

-- 
           Summary: avr-gcc crashes when using shifts with negative shift
                    count
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bjoern dot m dot haase at web dot de
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: avr-*-*


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
@ 2005-01-06 16:53 ` pinskia at gcc dot gnu dot org
  2005-01-06 17:35 ` bjoern dot m dot haase at web dot de
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-06 16:53 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
  2005-01-06 16:53 ` [Bug target/19293] " pinskia at gcc dot gnu dot org
@ 2005-01-06 17:35 ` bjoern dot m dot haase at web dot de
  2005-01-06 18:03 ` joseph at codesourcery dot com
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bjoern dot m dot haase at web dot de @ 2005-01-06 17:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bjoern dot m dot haase at web dot de  2005-01-06 17:35 -------
It seems that the standard says that shift operations with negative shift count 
are supposed to yield an "unspecified" result. 
 
Is there some more specific convention for gcc on how to behave in these cases? 
Otherwise the only thing to do would be to fix the instruction length 
calculation in the back-end code.  
 
 
Copy from C-Standards description: 
http://www.open-std.org/jtc1/sc22/open/n2794/n2794.txt 
 
 
 
       6.5.7  Bitwise shift operators 
 
       Syntax 
 
       [#1] 
 
               shift-expr: 
                       additive-expr 
                       shift-expr << additive-expr 
                       shift-expr >> additive-expr 
 
       Constraints 
 
       [#2] Each of the operands shall have integer type. 
 
       Semantics 
 
       [#3] The integer promotions are performed  on  each  of  the 
       operands.   The  type  of the result is that of the promoted 
       left operand.  If the value of the right operand is negative 
       or  is  greater  than  or equal to the width of the promoted 
       left operand, the behavior is undefined. 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
  2005-01-06 16:53 ` [Bug target/19293] " pinskia at gcc dot gnu dot org
  2005-01-06 17:35 ` bjoern dot m dot haase at web dot de
@ 2005-01-06 18:03 ` joseph at codesourcery dot com
  2005-01-06 18:57 ` bjoern dot m dot haase at web dot de
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: joseph at codesourcery dot com @ 2005-01-06 18:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From joseph at codesourcery dot com  2005-01-06 18:03 -------
Subject: Re:  avr-gcc crashes when using shifts with negative
 shift count

On Thu, 6 Jan 2005, bjoern dot m dot haase at web dot de wrote:

> It seems that the standard says that shift operations with negative shift count 
> are supposed to yield an "unspecified" result. 

Undefined, not unspecified.

> Is there some more specific convention for gcc on how to behave in these cases? 

For some other cases of runtime undefined behavior we generate an abort 
(with a warning that we are doing so).  This is what we do for va_arg with 
types changed by the default argument promotions, and for calls to 
functions cast to incompatible types.  We could do it for negative or 
too-wide shifts as well if we wish, either generally or for the specific 
targets for which they are problems.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (2 preceding siblings ...)
  2005-01-06 18:03 ` joseph at codesourcery dot com
@ 2005-01-06 18:57 ` bjoern dot m dot haase at web dot de
  2005-01-06 22:00 ` ericw at evcohs dot com
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bjoern dot m dot haase at web dot de @ 2005-01-06 18:57 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 7034 bytes --]


------- Additional Comments From bjoern dot m dot haase at web dot de  2005-01-06 18:57 -------
If it would be OK for GCC to simply ignore negative constant shift counts, 
the following patch would do. I have tested this with the test suite for 
gcc-3.4.3 . Unfortunately avr-gcc is still broken on head, so I could not test 
it properly for 4.0 . I, however, expect no difficulties either. 
 
regards, 
 
Björn 
 
 
Index: avr.c 
=================================================================== 
RCS file: /cvsroot/gcc/gcc/gcc/config/avr/avr.c,v 
retrieving revision 1.108.4.3 
diff -c -1 -0 -r1.108.4.3 avr.c 
*** avr.c	28 Sep 2004 01:13:55 -0000	1.108.4.3 
--- avr.c	6 Jan 2005 18:44:28 -0000 
*************** 
*** 3287,3307 **** 
   
  const char * 
  ashrqi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
   
        if (!len) 
  	len = &k; 
!  
        switch (INTVAL (operands[2])) 
  	{ 
  	case 1: 
  	  *len = 1; 
  	  return AS1 (asr,%0); 
   
  	case 2: 
  	  *len = 2; 
  	  return (AS1 (asr,%0) CR_TAB 
  		  AS1 (asr,%0)); 
--- 3287,3312 ---- 
   
  const char * 
  ashrqi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
   
        if (!len) 
  	len = &k; 
!        
!       if ( (INTVAL(operands[2]) < 0) || (INTVAL(operands[2]) > 7) ) 
!        { /* illegal shift count */ 
!          *len = 0; 
!          return ""; 
!        } 
        switch (INTVAL (operands[2])) 
  	{ 
  	case 1: 
  	  *len = 1; 
  	  return AS1 (asr,%0); 
   
  	case 2: 
  	  *len = 2; 
  	  return (AS1 (asr,%0) CR_TAB 
  		  AS1 (asr,%0)); 
*************** 
*** 3357,3376 **** 
--- 3362,3387 ---- 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int scratch = (GET_CODE (PATTERN (insn)) == PARALLEL); 
        int ldi_ok = test_hard_reg_class (LD_REGS, operands[0]); 
        int k; 
        int *t = len; 
         
        if (!len) 
  	len = &k; 
+        
+       if ( (INTVAL(operands[2]) < 0) || (INTVAL(operands[2]) > 15) ) 
+         { /* illegal shift count */ 
+           *len = 0; 
+           return ""; 
+         } 
   
        switch (INTVAL (operands[2])) 
  	{ 
  	case 4: 
  	case 5: 
  	  /* XXX try to optimize this too? */ 
  	  break; 
   
  	case 6: 
  	  if (optimize_size) 
*************** 
*** 3517,3537 **** 
  const char * 
  ashrsi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
        int *t = len; 
         
        if (!len) 
  	len = &k; 
!        
        switch (INTVAL (operands[2])) 
  	{ 
  	case 8: 
  	  { 
  	    int reg0 = true_regnum (operands[0]); 
  	    int reg1 = true_regnum (operands[1]); 
  	    *len=6; 
  	    if (reg0 <= reg1) 
  	      return (AS2 (mov,%A0,%B1) CR_TAB 
  		      AS2 (mov,%B0,%C1) CR_TAB 
--- 3528,3553 ---- 
  const char * 
  ashrsi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
        int *t = len; 
         
        if (!len) 
  	len = &k; 
!  
!       if ((INTVAL(operands[2]) < 0) || (INTVAL(operands[2])>31))  
!         { /* illegal shift count */ 
!           *len = 0; 
!           return ""; 
!         }      
        switch (INTVAL (operands[2])) 
  	{ 
  	case 8: 
  	  { 
  	    int reg0 = true_regnum (operands[0]); 
  	    int reg1 = true_regnum (operands[1]); 
  	    *len=6; 
  	    if (reg0 <= reg1) 
  	      return (AS2 (mov,%A0,%B1) CR_TAB 
  		      AS2 (mov,%B0,%C1) CR_TAB 
*************** 
*** 3632,3652 **** 
   
  const char * 
  lshrqi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
   
        if (!len) 
  	len = &k; 
!        
        switch (INTVAL (operands[2])) 
  	{ 
  	default: 
  	  *len = 1; 
  	  return AS1 (clr,%0); 
   
  	case 1: 
  	  *len = 1; 
  	  return AS1 (lsr,%0); 
   
--- 3648,3673 ---- 
   
  const char * 
  lshrqi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
   
        if (!len) 
  	len = &k; 
!       if ( (INTVAL(operands[2]) < 0) || (INTVAL(operands[2]) > 7) )  
!         { /* illegal shift count */ 
!           *len = 0; 
!           return ""; 
!         } 
!  
        switch (INTVAL (operands[2])) 
  	{ 
  	default: 
  	  *len = 1; 
  	  return AS1 (clr,%0); 
   
  	case 1: 
  	  *len = 1; 
  	  return AS1 (lsr,%0); 
   
*************** 
*** 3719,3747 **** 
  		      insn, operands, len, 1); 
    return ""; 
  } 
   
  /* 16bit logic shift right ((unsigned short)x >> i) */ 
   
  const char * 
  lshrhi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
!     { 
        int scratch = (GET_CODE (PATTERN (insn)) == PARALLEL); 
        int ldi_ok = test_hard_reg_class (LD_REGS, operands[0]); 
        int k; 
        int *t = len; 
   
        if (!len) 
  	len = &k; 
         
        switch (INTVAL (operands[2])) 
  	{ 
  	case 4: 
  	  if (optimize_size && scratch) 
  	    break;  /* 5 */ 
  	  if (ldi_ok) 
  	    { 
  	      *len = 6; 
  	      return (AS1 (swap,%B0)      CR_TAB 
  		      AS1 (swap,%A0)      CR_TAB 
--- 3740,3774 ---- 
  		      insn, operands, len, 1); 
    return ""; 
  } 
   
  /* 16bit logic shift right ((unsigned short)x >> i) */ 
   
  const char * 
  lshrhi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
!     {  
        int scratch = (GET_CODE (PATTERN (insn)) == PARALLEL); 
        int ldi_ok = test_hard_reg_class (LD_REGS, operands[0]); 
        int k; 
        int *t = len; 
   
        if (!len) 
  	len = &k; 
         
+       if ((INTVAL(operands[2]) < 0) || (INTVAL(operands[2]) > 15))  
+        { /* illegal constant shift count. Do nothing */ 
+          *len = 0; 
+          return ""; 
+        } 
+         
        switch (INTVAL (operands[2])) 
  	{ 
  	case 4: 
  	  if (optimize_size && scratch) 
  	    break;  /* 5 */ 
  	  if (ldi_ok) 
  	    { 
  	      *len = 6; 
  	      return (AS1 (swap,%B0)      CR_TAB 
  		      AS1 (swap,%A0)      CR_TAB 
*************** 
*** 3978,3997 **** 
--- 4005,4031 ---- 
  lshrsi3_out (rtx insn, rtx operands[], int *len) 
  { 
    if (GET_CODE (operands[2]) == CONST_INT) 
      { 
        int k; 
        int *t = len; 
         
        if (!len) 
  	len = &k; 
         
+       if ((INTVAL (operands[2]) < 0) || (INTVAL (operands[2]) > 31)) 
+         { /* illegal constant shift count. */ 
+           /* do nothing. */ 
+           *len = 0; 
+           return ""; 
+         }; 
+        
        switch (INTVAL (operands[2])) 
  	{ 
  	case 8: 
  	  { 
  	    int reg0 = true_regnum (operands[0]); 
  	    int reg1 = true_regnum (operands[1]); 
  	    *len = 4; 
  	    if (reg0 <= reg1) 
  	      return (AS2 (mov,%A0,%B1) CR_TAB 
  		      AS2 (mov,%B0,%C1) CR_TAB 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (3 preceding siblings ...)
  2005-01-06 18:57 ` bjoern dot m dot haase at web dot de
@ 2005-01-06 22:00 ` ericw at evcohs dot com
  2005-01-15  5:54 ` pinskia at gcc dot gnu dot org
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: ericw at evcohs dot com @ 2005-01-06 22:00 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ericw at evcohs dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (4 preceding siblings ...)
  2005-01-06 22:00 ` ericw at evcohs dot com
@ 2005-01-15  5:54 ` pinskia at gcc dot gnu dot org
  2005-01-18 23:28 ` bjoern dot m dot haase at web dot de
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-15  5:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-15 05:53 -------
Confirmed:
20020710-1.c:9: warning: right shift count is negative
20020710-1.c:12: error: negative insn length
(insn 13 8 16 (set (reg:HI 24 r24 [orig:42 D.1107 ] [42])
        (lshiftrt:HI (reg/v:HI 24 r24 [orig:44 y ] [44])
            (const_int -13 [0xfffffff3]))) 68 {lshrhi3} (insn_list:REG_DEP_TRUE 7 (nil))
    (nil))

This is just like what the i386 PR 7245 used to do which is what 20020710-1 was the test was for.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |ice-on-valid-code
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-15 05:53:55
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (5 preceding siblings ...)
  2005-01-15  5:54 ` pinskia at gcc dot gnu dot org
@ 2005-01-18 23:28 ` bjoern dot m dot haase at web dot de
  2005-01-19  0:04 ` bernie at develer dot com
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bjoern dot m dot haase at web dot de @ 2005-01-18 23:28 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 625 bytes --]


------- Additional Comments From bjoern dot m dot haase at web dot de  2005-01-18 23:27 -------
Hi, 
 
I have just stepped over a patch suggested by Bernardo Innocenti in order to 
treat the case of "shift_count == 0" correctly. My presently suggested 
patch (above) only treats the case of negative shift counts.  
I did not realize that the case of "0" also is buggy. 
 
So for treating the shifting problem comprehensively, one should combine both. 
This could be done by replacing the checks for  "< 0" in my patch by checks 
for "<= 0". 
 
Yours, 
 
Björn 
  

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (6 preceding siblings ...)
  2005-01-18 23:28 ` bjoern dot m dot haase at web dot de
@ 2005-01-19  0:04 ` bernie at develer dot com
  2005-01-19  0:09 ` bernie at develer dot com
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bernie at develer dot com @ 2005-01-19  0:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bernie at develer dot com  2005-01-19 00:04 -------
*** Bug 19329 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at libero dot
                   |                            |it


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (7 preceding siblings ...)
  2005-01-19  0:04 ` bernie at develer dot com
@ 2005-01-19  0:09 ` bernie at develer dot com
  2005-01-19  0:19 ` bernie at develer dot com
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bernie at develer dot com @ 2005-01-19  0:09 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |bernie at develer dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-01-15 05:53:55         |2005-01-19 00:09:33
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (8 preceding siblings ...)
  2005-01-19  0:09 ` bernie at develer dot com
@ 2005-01-19  0:19 ` bernie at develer dot com
  2005-01-19  5:17 ` schlie at comcast dot net
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bernie at develer dot com @ 2005-01-19  0:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bernie at develer dot com  2005-01-19 00:18 -------
(In reply to comment #3)


A quick informal review.


>     if (GET_CODE (operands[2]) == CONST_INT) 
>       { 
>         int k; 
>    
>         if (!len) 
>   	len = &k; 
> !        

This line contains spurious whitespace.

> !       if ( (INTVAL(operands[2]) < 0) || (INTVAL(operands[2]) > 7) ) 

The coding standard requires a space between INTVAL and the
opening parenthesis.

Also remember to replace "<" with "<="!


> !        { /* illegal shift count */ 
> !          *len = 0; 
> !          return ""; 
> !        } 

The comment should stay on its own line, with
capitalized initial, a full stop (".") at the
end, followed by *two* whitespaces.

This also applies to the other hunks.


>   const char * 
>   lshrhi3_out (rtx insn, rtx operands[], int *len) 
>   { 
>     if (GET_CODE (operands[2]) == CONST_INT) 
> !     {  
>         int scratch = (GET_CODE (PATTERN (insn)) == PARALLEL); 
>         int ldi_ok = test_hard_reg_class (LD_REGS, operands[0]); 
>         int k; 

This hunk adds spurious whitespace after the opening brace.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (9 preceding siblings ...)
  2005-01-19  0:19 ` bernie at develer dot com
@ 2005-01-19  5:17 ` schlie at comcast dot net
  2005-01-19  5:26 ` schlie at comcast dot net
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: schlie at comcast dot net @ 2005-01-19  5:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-01-19 05:17 -------
Actually wonder if a better solutions would be to and (&) the rhs shift count by
Log2(rhs-mode-size) bit mask, thereby the resulting value will always be within
0 >= shift <= (N-1), resulting effectivly a shift modulo N, which is more similar
to what hardware and would guess most machines actually do, or am I mistaken?



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (10 preceding siblings ...)
  2005-01-19  5:17 ` schlie at comcast dot net
@ 2005-01-19  5:26 ` schlie at comcast dot net
  2005-01-19 21:25 ` bjoern dot m dot haase at web dot de
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: schlie at comcast dot net @ 2005-01-19  5:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-01-19 05:26 -------
(In reply to comment #8)

Never mind, as it's likely not worth the bother as the behavor
is undefined anyway, and the existing proposal is simpler.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (11 preceding siblings ...)
  2005-01-19  5:26 ` schlie at comcast dot net
@ 2005-01-19 21:25 ` bjoern dot m dot haase at web dot de
  2005-01-20  5:46 ` bernie at develer dot com
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bjoern dot m dot haase at web dot de @ 2005-01-19 21:25 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4783 bytes --]


------- Additional Comments From bjoern dot m dot haase at web dot de  2005-01-19 21:25 -------
Hi, 
 
here is the changed patch for avr.c . I hope that it is now compliant to the 
gcc coding standards. I however did not understand what you have meant with 
"this hunk adds spurious whitespace". 
 
Yours, 
 
Björn 
 
 
Index: avr.c 
=================================================================== 
RCS file: /cvsroot/gcc/gcc/gcc/config/avr/avr.c,v 
retrieving revision 1.108.4.3 
diff -U10 -r1.108.4.3 avr.c 
--- avr.c	28 Sep 2004 01:13:55 -0000	1.108.4.3 
+++ avr.c	19 Jan 2005 21:19:49 -0000 
@@ -3288,20 +3288,27 @@ 
 const char * 
 ashrqi3_out (rtx insn, rtx operands[], int *len) 
 { 
   if (GET_CODE (operands[2]) == CONST_INT) 
     { 
       int k; 
  
       if (!len) 
 	len = &k; 
  
+      /* Test for illegal or strange shift count.  */       
+      if ( (INTVAL (operands[2]) <= 0 ) || ( INTVAL (operands[2]) > 7) ) 
+       {  
+         *len = 0; 
+         return ""; 
+       } 
+ 
       switch (INTVAL (operands[2])) 
 	{ 
 	case 1: 
 	  *len = 1; 
 	  return AS1 (asr,%0); 
  
 	case 2: 
 	  *len = 2; 
 	  return (AS1 (asr,%0) CR_TAB 
 		  AS1 (asr,%0)); 
@@ -3357,20 +3364,27 @@ 
 { 
   if (GET_CODE (operands[2]) == CONST_INT) 
     { 
       int scratch = (GET_CODE (PATTERN (insn)) == PARALLEL); 
       int ldi_ok = test_hard_reg_class (LD_REGS, operands[0]); 
       int k; 
       int *t = len; 
        
       if (!len) 
 	len = &k; 
+      
+      /* Test for illegal or strange shift count.  */  
+      if ( (INTVAL (operands[2]) <= 0) || (INTVAL (operands[2]) > 15) ) 
+        {  
+          *len = 0; 
+          return ""; 
+        } 
  
       switch (INTVAL (operands[2])) 
 	{ 
 	case 4: 
 	case 5: 
 	  /* XXX try to optimize this too? */ 
 	  break; 
  
 	case 6: 
 	  if (optimize_size) 
@@ -3517,21 +3531,27 @@ 
 const char * 
 ashrsi3_out (rtx insn, rtx operands[], int *len) 
 { 
   if (GET_CODE (operands[2]) == CONST_INT) 
     { 
       int k; 
       int *t = len; 
        
       if (!len) 
 	len = &k; 
-       
+ 
+      /* Test for illegal or strange shift count.  */ 
+      if ((INTVAL (operands[2]) <= 0) || (INTVAL (operands[2])>31))  
+        {  
+          *len = 0; 
+          return ""; 
+        }      
       switch (INTVAL (operands[2])) 
 	{ 
 	case 8: 
 	  { 
 	    int reg0 = true_regnum (operands[0]); 
 	    int reg1 = true_regnum (operands[1]); 
 	    *len=6; 
 	    if (reg0 <= reg1) 
 	      return (AS2 (mov,%A0,%B1) CR_TAB 
 		      AS2 (mov,%B0,%C1) CR_TAB 
@@ -3633,20 +3653,27 @@ 
 const char * 
 lshrqi3_out (rtx insn, rtx operands[], int *len) 
 { 
   if (GET_CODE (operands[2]) == CONST_INT) 
     { 
       int k; 
  
       if (!len) 
 	len = &k; 
        
+      /* Test for illegal or not useful shift count.  */ 
+      if ( (INTVAL (operands[2]) <= 0) | (INTVAL (operands[2]) > 7) )  
+        {  
+          *len = 0; 
+          return ""; 
+        } 
+ 
       switch (INTVAL (operands[2])) 
 	{ 
 	default: 
 	  *len = 1; 
 	  return AS1 (clr,%0); 
  
 	case 1: 
 	  *len = 1; 
 	  return AS1 (lsr,%0); 
  
@@ -3719,29 +3746,36 @@ 
 		      insn, operands, len, 1); 
   return ""; 
 } 
  
 /* 16bit logic shift right ((unsigned short)x >> i) */ 
  
 const char * 
 lshrhi3_out (rtx insn, rtx operands[], int *len) 
 { 
   if (GET_CODE (operands[2]) == CONST_INT) 
-    { 
+    {  
       int scratch = (GET_CODE (PATTERN (insn)) == PARALLEL); 
       int ldi_ok = test_hard_reg_class (LD_REGS, operands[0]); 
       int k; 
       int *t = len; 
  
       if (!len) 
 	len = &k; 
        
+      /* Test for illegal or not useful shift count.  */  
+      if ((INTVAL (operands[2]) <= 0) || (INTVAL (operands[2]) > 15))  
+       {  
+         *len = 0; 
+         return ""; 
+       } 
+        
       switch (INTVAL (operands[2])) 
 	{ 
 	case 4: 
 	  if (optimize_size && scratch) 
 	    break;  /* 5 */ 
 	  if (ldi_ok) 
 	    { 
 	      *len = 6; 
 	      return (AS1 (swap,%B0)      CR_TAB 
 		      AS1 (swap,%A0)      CR_TAB 
@@ -3977,20 +4011,27 @@ 
 const char * 
 lshrsi3_out (rtx insn, rtx operands[], int *len) 
 { 
   if (GET_CODE (operands[2]) == CONST_INT) 
     { 
       int k; 
       int *t = len; 
        
       if (!len) 
 	len = &k; 
+      
+      /* Test for illegal or not useful shift counts.  */  
+      if ((INTVAL (operands[2]) <= 0) || (INTVAL (operands[2]) > 31)) 
+        {  
+          *len = 0; 
+          return ""; 
+        }; 
        
       switch (INTVAL (operands[2])) 
 	{ 
 	case 8: 
 	  { 
 	    int reg0 = true_regnum (operands[0]); 
 	    int reg1 = true_regnum (operands[1]); 
 	    *len = 4; 
 	    if (reg0 <= reg1) 
 	      return (AS2 (mov,%A0,%B1) CR_TAB 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (12 preceding siblings ...)
  2005-01-19 21:25 ` bjoern dot m dot haase at web dot de
@ 2005-01-20  5:46 ` bernie at develer dot com
  2005-01-26 21:45 ` cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: bernie at develer dot com @ 2005-01-20  5:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bernie at develer dot com  2005-01-20 05:46 -------
(In reply to comment #10)
> Hi, 
>  
> here is the changed patch for avr.c . I hope that it is now compliant to the 
> gcc coding standards. I however did not understand what you have meant with 
> "this hunk adds spurious whitespace". 

There's a change of one line that adds a single
whitespace after an opening brace.

Also, there's an if-block that has the braces
indented by one space instead of two spaces.

Sorry for being picky.  I'll fix these before
committing if the patch gets approved.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (13 preceding siblings ...)
  2005-01-20  5:46 ` bernie at develer dot com
@ 2005-01-26 21:45 ` cvs-commit at gcc dot gnu dot org
  2005-01-26 23:11 ` bernie at develer dot com
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-01-26 21:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-01-26 21:44 -------
Subject: Bug 19293

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	marekm@gcc.gnu.org	2005-01-26 21:44:26

Modified files:
	gcc            : ChangeLog 
	gcc/config/avr : avr.c avr.md 

Log message:
	PR target/19293
	PR target/19329
	* config/avr/avr.c (notice_update_cc): Only set condition code for
	ashrqi3 if shift count > 0.
	(out_shift_with_cnt): Handle shift count <= 0 as a no-op.
	(ashlqi3_out, ashlhi3_out, ashlsi3_out, ashrqi3_out, ashrhi3_out,
	ashrsi3_out, lshrqi3_out, lshrhi3_out, lshrsi3_out): Handle shift
	count <= 0 as a no-op, and shift count >= width by copying zero
	or sign bit to all bits of the result.
	* config/avr/avr.md (all shifts): Add alternatives for zero shift
	count, with attribute "length" set to 0 and "cc" set to "none".

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7290&r2=2.7291
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr.c.diff?cvsroot=gcc&r1=1.127&r2=1.128
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr.md.diff?cvsroot=gcc&r1=1.47&r2=1.48



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (14 preceding siblings ...)
  2005-01-26 21:45 ` cvs-commit at gcc dot gnu dot org
@ 2005-01-26 23:11 ` bernie at develer dot com
  2005-01-27 22:36 ` cvs-commit at gcc dot gnu dot org
  2005-01-27 22:59 ` pinskia at gcc dot gnu dot org
  17 siblings, 0 replies; 19+ messages in thread
From: bernie at develer dot com @ 2005-01-26 23:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bernie at develer dot com  2005-01-26 23:11 -------
Please also apply to 3.4-branch.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (15 preceding siblings ...)
  2005-01-26 23:11 ` bernie at develer dot com
@ 2005-01-27 22:36 ` cvs-commit at gcc dot gnu dot org
  2005-01-27 22:59 ` pinskia at gcc dot gnu dot org
  17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-01-27 22:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-01-27 22:36 -------
Subject: Bug 19293

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	marekm@gcc.gnu.org	2005-01-27 22:36:00

Modified files:
	gcc            : ChangeLog 
	gcc/config/avr : avr.c avr.md 

Log message:
	PR target/19293
	PR target/19329
	* config/avr/avr.c (notice_update_cc): Only set condition code for
	ashrqi3 if shift count > 0.
	(out_shift_with_cnt): Handle shift count <= 0 as a no-op.
	(ashlqi3_out, ashlhi3_out, ashlsi3_out, ashrqi3_out, ashrhi3_out,
	ashrsi3_out, lshrqi3_out, lshrhi3_out, lshrsi3_out): Handle shift
	count <= 0 as a no-op, and shift count >= width by copying zero
	or sign bit to all bits of the result.
	* config/avr/avr.md (all shifts): Add alternatives for zero shift
	count, with attribute "length" set to 0 and "cc" set to "none".

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.785&r2=2.2326.2.786
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.108.4.3&r2=1.108.4.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/avr/avr.md.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.42.4.1&r2=1.42.4.2



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

* [Bug target/19293] avr-gcc crashes when using shifts with negative shift count
  2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
                   ` (16 preceding siblings ...)
  2005-01-27 22:36 ` cvs-commit at gcc dot gnu dot org
@ 2005-01-27 22:59 ` pinskia at gcc dot gnu dot org
  17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-27 22:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-27 22:59 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to fail|3.4.2 3.4.3 4.0.0           |3.4.2 3.4.3
      Known to work|                            |3.4.4 4.0.0
         Resolution|                            |FIXED
   Target Milestone|---                         |3.4.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19293


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

end of thread, other threads:[~2005-01-27 22:59 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-06 16:01 [Bug c/19293] New: avr-gcc crashes when using shifts with negative shift count bjoern dot m dot haase at web dot de
2005-01-06 16:53 ` [Bug target/19293] " pinskia at gcc dot gnu dot org
2005-01-06 17:35 ` bjoern dot m dot haase at web dot de
2005-01-06 18:03 ` joseph at codesourcery dot com
2005-01-06 18:57 ` bjoern dot m dot haase at web dot de
2005-01-06 22:00 ` ericw at evcohs dot com
2005-01-15  5:54 ` pinskia at gcc dot gnu dot org
2005-01-18 23:28 ` bjoern dot m dot haase at web dot de
2005-01-19  0:04 ` bernie at develer dot com
2005-01-19  0:09 ` bernie at develer dot com
2005-01-19  0:19 ` bernie at develer dot com
2005-01-19  5:17 ` schlie at comcast dot net
2005-01-19  5:26 ` schlie at comcast dot net
2005-01-19 21:25 ` bjoern dot m dot haase at web dot de
2005-01-20  5:46 ` bernie at develer dot com
2005-01-26 21:45 ` cvs-commit at gcc dot gnu dot org
2005-01-26 23:11 ` bernie at develer dot com
2005-01-27 22:36 ` cvs-commit at gcc dot gnu dot org
2005-01-27 22:59 ` pinskia at gcc dot gnu dot org

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