public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "amk7r at mtmail dot mtsu.edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108720] New: INT_MIN * -1 is incorrect Date: Wed, 08 Feb 2023 16:41:56 +0000 [thread overview] Message-ID: <bug-108720-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108720 Bug ID: 108720 Summary: INT_MIN * -1 is incorrect Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: amk7r at mtmail dot mtsu.edu Target Milestone: --- Created attachment 54434 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54434&action=edit Attached is a file with the source code (.c) and the preprocessed file (.i) Version of GCC: 11.3.0 System type: Ubuntu 22.04.1 LTS Options given when GCC was configured/built: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --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-bootstrap --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 --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --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-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Complete command line that triggers the bug: gcc err_file.c The compiler output (error messages, warnings, ect.): n/a; there were no errors or warnings Expected behavior: The program should print out the value of y, and then print out “true 4” because -INT_MIN is equal to INT_MIN, which is less than 0. Actual behavior: The program prints out the value of y, and then prints out “true 2.” Case 1: y>= 0. "true 1" should not be printed because y is INT_MIN. -> Test Pass Case 2: (x-1)>= 0. "true 2" should not be printed because x is INT_MIN. -> Test Fail o INT_MIN * -1 = INT_MIN. Case 3: (x-1)>= zero. "true 3" should not be printed because x is INT_MIN. -> Test Pass o INT_MIN * -1 = INT_MIN and int zero has 0 Case 4: (x-1)< 0. "true 4" should be printed because x is INT_MIN. o INT_MIN * -1 = INT_MIN and INT_MIN is less than 0 -> Test Fail More information: If you translate the C code into assembly code using the command “gcc -s err_file.c,” and check the .L2 block: In .L2: The assembly code should be: #equivalent c code cmpl $0, -8(%rbp) #because it has the result of x * -1 if ((x*-1)>=0) js .L3 #instead of jg .L3 Explanation: * x *-1 is INT_MIN. * “jg” instruction will skip the statement in “if block” if (x*-1) or INT_MIN is greater than 0. * Since, (x*-1) or INT_MIN is not greater than 0, the statement in the “if block” is printed (“true 2”). * But “true 2” should only be printed if (x*-1) or INT_MIN is greater than or equal to 0 (check c code line 9). * In this case, doing “js .L3” would make more sense and will give the expected result.
next reply other threads:[~2023-02-08 16:41 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-08 16:41 amk7r at mtmail dot mtsu.edu [this message] 2023-02-08 16:43 ` [Bug c/108720] " amk7r at mtmail dot mtsu.edu 2023-02-08 16:45 ` jakub at gcc dot gnu.org 2023-02-08 16:47 ` pinskia at gcc dot gnu.org 2023-02-08 16:49 ` pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108720-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).