``` []$ gcc -v Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto Thread model: posix gcc version 9.2.0 (GCC) []$ cat a.c int f(long long a,int b){ return a%b; } []$ gcc -Wall -Wconversion a.c -c a.c: In function ‘f’: a.c:2:10: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion] 2 | return a%b; | ~^~ ``` The specification for `-Wconversion` is "Warn for implicit conversions that may alter a value.". In this case the result is guaranteed to be convertible to the type of `b` (`int`) without changing the value.
No i think there is one case where what you said is incorrect. When both are INT_MIN.
*** Bug 92219 has been marked as a duplicate of this bug. ***
(In reply to Andrew Pinski from comment #1) > No i think there is one case where what you said is incorrect. When both are > INT_MIN. In this case the result will be 0.
Confirmed.
Unfortunately the value range info is not available in the frontend :(.
(In reply to Xi Ruoyao from comment #5) > Unfortunately the value range info is not available in the frontend :(. Here "value range info" means the info from the VRP pass. For this case we can specially check MOD_EXPR, but doing so won't help with the general cases like "return a % b / 2;".