Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testcase generate with csmith --float warning: implicit conversion of out of range value from 'double' to 'uint32_t' (aka 'unsigned int') is undefined #132

Open
yansendao opened this issue Mar 25, 2021 · 6 comments

Comments

@yansendao
Copy link

test command

csmith --float -o test.c -s 1618990070589446
clang -g3 -fsanitize=undefined,address -O0 -I /home/yansendao/software/csmith/include test.c -Wall 2>&1 | grep "undefined" -w

result

test.c:43:13: warning: implicit conversion of out of range value from 'double' to 'uint32_t' (aka 'unsigned int') is undefined [-Wliteral-conversion]

csmith version:

csmith 2.4.0
Git version: deddca6

test.zip

@jxyang
Copy link
Member

jxyang commented Mar 28, 2021

Csmith is by design liberal when converting between scalar types. Many times the compilers treat the code in the same way even though the code might be undefined by "book".

Do you see the test case produces different results when compiled by different compilers? If so that becomes a valid bug.

@yansendao
Copy link
Author

you see the test case produces different results when compiled by different compilers? If so that becomes a valid bug.

I will take several days to check whether this compiler warning causes different compilers or different compiler options to run differently.

@yansendao
Copy link
Author

image

/*
 * This is a RANDOMLY GENERATED PROGRAM.
 *
 * Generator: csmith 2.4.0
 * Git version: deddca6
 * Options:   --float -o test.c
 * Seed:      2256145340
 */
yansendao@jvm-146:dir-799$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
yansendao@jvm-146:dir-799$ uname -a
Linux jvm-146 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
yansendao@jvm-146:dir-799$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 
yansendao@jvm-146:dir-799$ clang -v
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64

test.zip

@jxyang

@yansendao
Copy link
Author

image

/*
 * This is a RANDOMLY GENERATED PROGRAM.
 *
 * Generator: csmith 2.4.0
 * Git version: deddca6
 * Options:   --float -o test.c
 * Seed:      3731180208
 */
yansendao@jvm-146:dir-712$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
yansendao@jvm-146:dir-712$ uname -a
Linux jvm-146 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
yansendao@jvm-146:dir-712$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 
yansendao@jvm-146:dir-712$ clang -v
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64

test.zip

@chenyang78
Copy link
Member

@yansendao Thanks for reporting the issue. It's known that passing --float would generate programs with UBs related to float-to-int conversion.

commit b138a40da6c385023567c0f9f61d46d45286f524
Author: Yang Chen <chenyang@cs.utah.edu>
Date:   Sat Sep 20 18:26:37 2014 -0700
    ...    
    Currently csmith is able to generate programs that can be compiled successfully, but full with
    UBs caused by convertion from floating-point to integers where the floating-point value is
    out of the range of integers.

So, please don't use this option if you want to generate UB-free programs. I should've added some notes in the corresponding help message.

On the other hand, you might want to try strict-float, which avoid generating assignments between floats and integers.

@yansendao
Copy link
Author

yansendao commented Apr 23, 2021

@yansendao Thanks for reporting the issue. It's known that passing --float would generate programs with UBs related to float-to-int conversion.

commit b138a40da6c385023567c0f9f61d46d45286f524
Author: Yang Chen <chenyang@cs.utah.edu>
Date:   Sat Sep 20 18:26:37 2014 -0700
    ...    
    Currently csmith is able to generate programs that can be compiled successfully, but full with
    UBs caused by convertion from floating-point to integers where the floating-point value is
    out of the range of integers.

So, please don't use this option if you want to generate UB-free programs. I should've added some notes in the corresponding help message.

On the other hand, you might want to try strict-float, which avoid generating assignments between floats and integers.

@chenyang78

#133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants