Bug 65325 - float/interger operation needs cast with 02 switch.
Summary: float/interger operation needs cast with 02 switch.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-03-05 13:15 UTC by Stephane Cerveau
Modified: 2018-12-20 14:11 UTC (History)
0 users

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-03-05 00:00:00


Attachments
assembly code (46.44 KB, application/x-object)
2015-03-05 16:09 UTC, Stephane Cerveau
Details
assembly code (46.43 KB, application/x-object)
2015-03-06 10:43 UTC, Stephane Cerveau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stephane Cerveau 2015-03-05 13:15:56 UTC
A bug has been reported to gstreamer bug tracker: 

https://bugzilla.gnome.org/show_bug.cgi?id=745667

This bug seems to be related to gcc optimization behaviour. The operations needs specific cast for operation with double and integers.
Comment 1 Sebastian Dröge 2015-03-05 13:18:30 UTC
To provide more details, the code in question is basically

float x = ...;
int y = x * INTEGER_LITERAL;

if x < 1.0, this always resulted in 0. Adding casts like

int y = (int) ((double) x * (double) INTEGER_LITERAL);

fixed it.


The problem only happened with -O1 and -O2 on ARM(v7), not with -O0. And also went away after adding some debug printf() around the code in question.


gcc 4.9 was used here.
Comment 2 Sebastian Dröge 2015-03-05 13:20:10 UTC
http://comments.gmane.org/gmane.linux.embedded.yocto.meta-freescale/13018 also has other mentions of this bug.
Comment 3 Marek Polacek 2015-03-05 13:57:30 UTC
Can you please provide a stand-alone testcase (that maybe calls abort() if the alleged bug occurs)?
Comment 4 Stephane Cerveau 2015-03-05 16:07:29 UTC
http://pastebin.com/stQFwaSg

Here is a sample which is supposed to describe the same behaviour as in gstvolume.c but i'm not able to reproduce it with this code.

Here is my build command line:

arm-oad-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 -O2 -pipe -g -feliminate-unused-debug-types test_float.c -o test_float
Comment 5 Stephane Cerveau 2015-03-05 16:09:38 UTC
Created attachment 34963 [details]
assembly code

Here is the command line:

arm-oad-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter -std=gnu99 -DHAVE_CONFIG_H -I. -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/work/cortexa9hf-vfp-neon-mx6-oad-linux-gnueabi/gstreamer1.0-plugins-base/1.4.1-r0/gst-plugins-base-1.4.1/gst/volume -I../.. -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/work/cortexa9hf-vfp-neon-mx6-oad-linux-gnueabi/gstreamer1.0-plugins-base/1.4.1-r0/gst-plugins-base-1.4.1/gst-libs -I../../gst-libs -pthread -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/include/gstreamer-1.0 -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/include/glib-2.0 -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/lib/glib-2.0/include -pthread -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/include/glib-2.0 -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/lib/glib-2.0/include -pthread -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/include/gstreamer-1.0 -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/include/glib-2.0 -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/lib/glib-2.0/include -DG_THREADS_MANDATORY -DG_DISABLE_CAST_CHECKS -DG_DISABLE_ASSERT -Wall -Wdeclaration-after-statement -Wvla -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wformat-nonliteral -Wformat-security -Winit-self -Wmissing-include-dirs -Waddress -Waggregate-return -Wno-multichar -Wnested-externs -I/home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/sysroots/jupiter/usr/include/orc-0.4 -O2 -pipe -g -feliminate-unused-debug-types -S /home/sce/DEV/yocto-oad-dizzy/build_oad-jupiter/tmp/work/cortexa9hf-vfp-neon-mx6-oad-linux-gnueabi/gstreamer1.0-plugins-base/1.4.1-r0/gst-plugins-base-1.4.1/gst/volume/gstvolume.c  -fPIC -DPIC -o .libs/libgstvolume_la-gstvolume.o
Comment 6 Sebastian Dröge 2015-03-05 21:27:08 UTC
Can you provide the assembly code with and without the added casts?
Comment 7 Stephane Cerveau 2015-03-06 09:16:18 UTC
It is already without the cast ...
Comment 8 Stephane Cerveau 2015-03-06 10:43:40 UTC
Created attachment 34973 [details]
assembly code

This is the version with float casting
Comment 9 Sebastian Dröge 2015-03-06 11:16:02 UTC
The assembly code looks exactly the same to me, except for the source locations. But I also don't see the multiplication in either, only conversion between integers and floating point values, and then storing the results. It's near line 254 in the original source for both.
Comment 10 Andrew Pinski 2016-08-28 21:47:38 UTC
Do you have the preprocessed source?
Comment 11 Richard Earnshaw 2018-12-20 14:11:27 UTC
No testcase supplied