https://gcc.gnu.org/g:0cd24b06d130d99bd86e5e03a01c38047413a92e

commit r15-3947-g0cd24b06d130d99bd86e5e03a01c38047413a92e
Author: Mikael Pettersson <mikpeli...@gmail.com>
Date:   Sun Sep 29 10:15:55 2024 -0600

    [PATCH] [PATCH] Avoid integer overflow in gcc.dg/cpp/charconst-3.c (PR 
testsuite/116806)
    
    The intermediate expression (unsigned char) '\234' * scale overflows
    int on int16 targets, causing the test case to fail there.  Fixed by
    performing the arithmetic in unsigned type, as suggested by Andrew Pinski.
    
    Regression tested on x86_64-pc-linux-gnu, and on an out-of-tree 16-bit
    target with simulator.  Manually checked the generated code for pdp11
    and xstormy16.
    
    Ok for trunk? (I don't have commit rights so I'd need help committing it.)
    
    gcc/testsuite/
    
            PR testsuite/116806
            * gcc.dg/cpp/charconst-3.c: Perform arithmetic in unsigned
            type to avoid integer overflow.

Diff:
---
 gcc/testsuite/gcc.dg/cpp/charconst-3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/cpp/charconst-3.c 
b/gcc/testsuite/gcc.dg/cpp/charconst-3.c
index 7c1966391315..7b2df8b2998e 100644
--- a/gcc/testsuite/gcc.dg/cpp/charconst-3.c
+++ b/gcc/testsuite/gcc.dg/cpp/charconst-3.c
@@ -20,7 +20,7 @@ int main ()
   if ('ab' != (int) ((unsigned char) 'a' * scale + (unsigned char) 'b'))
     abort ();
 
-  if ('\234b' != (int) ((unsigned char) '\234' * scale + (unsigned char) 'b'))
+  if ('\234b' != (int) ((unsigned char) '\234' * (unsigned int) scale + 
(unsigned char) 'b'))
     abort ();
 
   if ('b\234' != (int) ((unsigned char) 'b' * scale + (unsigned char) '\234'))

Reply via email to