[Bug c++/59394] New: Unused code generated

2013-12-05 Thread smal.root at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59394

Bug ID: 59394
   Summary: Unused code generated
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: smal.root at gmail dot com
Target: AVR

Created attachment 31385
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31385&action=edit
source code

GCC:
avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.8.2/lto-wrapper
Target: avr
Configured with: /build/avr-gcc/src/gcc-4.8.2/configure
--disable-cloog-version-check --disable-install-libiberty --disable-libssp
--disable-libstdcxx-pch --disable-libunwind-exceptions
--disable-linker-build-id --disable-nls --disable-werror --enable-__cxa_atexit
--enable-checking=release --enable-clocale=gnu --enable-cloog-backend=isl
--enable-gnu-unique-object --enable-gold --enable-languages=c,c++
--enable-ld=default --enable-lto --enable-plugin --enable-shared
--infodir=/usr/share/info --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --prefix=/usr --target=avr --with-as=/usr/bin/avr-as
--with-gnu-as --with-gnu-ld --with-ld=/usr/bin/avr-ld --with-plugin-ld=ld.gold
--with-system-zlib
Thread model: single
gcc version 4.8.2 (GCC) 

OS:
Arch Linux 
Linux 3.12.0-1-ARCH #1 SMP PREEMPT Wed Nov 6 09:06:27 CET 2013 x86_64 GNU/Linux

Command line:
avr-gcc -Wall -mmcu=atxmega64a3 -DF_CPU=1600UL  -mno-interrupts -Os
-pedantic-errors -pedantic -std=c++11 -Wfatal-errors -Wall   
-I/usr/avr/include  -c main.cpp -o obj/Release/main.o
main.cpp: In function 'int main()':
main.cpp:55:21: warning: variable 'tval32' set but not used
[-Wunused-but-set-variable]
   volatile uint32_t tval32;
 ^
avr-g++  -o bin/Release/lambda_test.elf obj/Release/main.o   -mmcu=atxmega64a3
-Wl,-Map=bin/Release/lambda_test.map,--cref  
Output size is 7,92 KB
Running project post-build steps
avr-size bin/Release/lambda_test.elf
   text   databssdechexfilename
850  0   2400   3250cb2   
bin/Release/lambda_test.elf
avr-objdump -h -S bin/Release/lambda_test.elf > bin/Release/lambda_test.lss
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 1 warnings (0 minutes, 0 seconds)

Source file: attached main.cpp
Generated assembly: attached lambda_test.lss

Problem.
A. As you can see in generated assembly:
1. function Sort_OldStyle(_Z13Sort_OldStylev) contain(as inline) functions Sort
and Sort_OldStyle_Internal
2. function Sort_NewStyle(_Z13Sort_NewStylev) contain(as inline) functions Sort
and lambda-expression

B. But also generated code contain unneded:
1. function Sort(_Z4SortPV5SPairS1_PFvRS0_E)
2. function Sort_OldStyle_Internal(_Z22Sort_OldStyle_InternalRV5SPair)
3. lambda-expression(_ZZ13Sort_NewStylevENUlRV5SPairE_4_FUNES1_)

Why gcc include functions from B-list if they already exist in functions of
list A? Also why gcc use inline for function Sort and don't use call with -Os
used?


[Bug c++/59394] Unused code generated

2013-12-05 Thread smal.root at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59394

--- Comment #1 from smalcom  ---
Created attachment 31386
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31386&action=edit
generated assembly


[Bug c++/84814] New: Type of arithmetic expression

2018-03-10 Thread smal.root at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84814

Bug ID: 84814
   Summary: Type of arithmetic expression
   Product: gcc
   Version: 7.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: smal.root at gmail dot com
  Target Milestone: ---

Created attachment 43620
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43620&action=edit
Project archive

File: main.cpp, line: 20.

When used variant
> if((curtime - LastTime) >= Request)

then we get following assembly code (file: type_test_wo_conv.lss):

> 8000260:  8806ldrhr6, [r0, #0]
> 8000262:  7825ldrbr5, [r4, #0]
> 8000264:  b292uxthr2, r2
> 8000266:  1b92subsr2, r2, r6
> 8000268:  42aacmp r2, r5

as you can see "subs" result is not converted to uint16_t, but must. Because
both arguments of subtraction has same type:

"— Otherwise, the integral promotions (4.5) shall be performed on both
operands. Then the following rules shall be applied to the promoted operands:

— If both operands have the same type, no further conversion is needed."

As result - arguments of "cmp" is invalid uint32_t values.

If we use additional "manual" type conversion for expression

> if((uint16_t)(curtime - LastTime) >= Request)

then we get right result:

> 8000260:  8806ldrhr6, [r0, #0]
> 8000262:  7825ldrbr5, [r4, #0]
> 8000264:  1b92subsr2, r2, r6
> 8000266:  b292uxthr2, r2
> 8000268:  42aacmp r2, r5

after "subs" result is converted to uint16_t.

[Bug c++/79600] New: [c++11] reinterpret_cast not working in enum class

2017-02-19 Thread smal.root at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79600

Bug ID: 79600
   Summary: [c++11] reinterpret_cast not working in enum class
   Product: gcc
   Version: 7.0.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: smal.root at gmail dot com
  Target Milestone: ---

Created attachment 40774
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40774&action=edit
source code

New compiler do not want to assign value to member of enum class and show
error:

1.cpp: In function 'int main()':
1.cpp:14:43: error: reinterpret_cast from integer to pointer
  EnumMember = reinterpret_cast(&TEST_MACROS)
   ^  
1.cpp:14:43: error: 'reinterpret_cast(2048)' is not a
constant expression
1.cpp:14:58: error: enumerator value for 'EnumMember' is not an integer
constant
  EnumMember = reinterpret_cast(&TEST_MACROS)


But value successfully assigned for regular variable.
avr-gcc-4.9.4 - compilation successful
avr-gcc-5.4.0 - compilation successful
avr-gcc-6.3.0 - compilation error
avr-gcc-7.0.1-20170219 - compilation error

I'll attach *.ii files for every gcc version.

Build string:
avr-g++ -save-temps -std=c++11 -Wall -Os -pedantic -mmcu=atxmega128a3u -c 1.cpp
-o 1.o && avr-g++ -std=c++11 -Wall -Os -mmcu=atxmega128a3u 1.o -o 1

Information about compilers

1.
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr/libexec/gcc/avr/4.9.4/lto-wrapper
Target: avr
Configured with: ../gcc-4.9.4/configure --prefix=/opt/toolchain/avr
--target=avr --disable-nls --enable-languages=c,c++ --disable-libssp
--enable-lto --with-isl
Thread model: single
gcc version 4.9.4 (GCC) 

2.
5.4.0
Using built-in specs.
Reading specs from
/opt/toolchain/avr_5/lib/gcc/avr/5.4.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr_5/libexec/gcc/avr/5.4.0/lto-wrapper
Target: avr
Configured with: ../gcc-5.4.0/configure --prefix=/opt/toolchain/avr_5
--disable-nls --disable-shared --target=avr --disable-install-libiberty
--disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions
--disable-linker-build-id --disable-werror --disable-__cxa_atexit
--enable-checking=release --enable-clocale=gnu --enable-gnu-unique-object
--enable-gold --enable-languages=c,c++ --enable-ld=default --enable-lto
--enable-plugin --enable-shared --with-gnu-as --with-gnu-ld
--with-plugin-ld=ld.gold --with-system-zlib --with-isl
--enable-gnu-indirect-function
Thread model: single
gcc version 5.4.0 (GCC) 

3.
6.3.0
Using built-in specs.
Reading specs from
/opt/toolchain/avr_6/lib/gcc/avr/6.3.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr_6/libexec/gcc/avr/6.3.0/lto-wrapper
Target: avr
Configured with: ../gcc-6.3.0/configure --prefix=/opt/toolchain/avr_6
--disable-nls --disable-shared --target=avr --disable-install-libiberty
--disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions
--disable-linker-build-id --disable-werror --disable-__cxa_atexit
--enable-checking=release --enable-clocale=gnu --enable-gnu-unique-object
--enable-gold --enable-languages=c,c++ --enable-ld=default --enable-lto
--enable-plugin --enable-shared --with-gnu-as --with-gnu-ld
--with-plugin-ld=ld.gold --with-system-zlib --with-isl
--enable-gnu-indirect-function
Thread model: single
gcc version 6.3.0 (GCC) 

4.
trunk
Using built-in specs.
Reading specs from
/opt/toolchain/avr_trunk/lib/gcc/avr/7.0.1/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/opt/toolchain/avr_trunk/libexec/gcc/avr/7.0.1/lto-wrapper
Target: avr
Configured with: ../gcc_trunk/configure --prefix=/opt/toolchain/avr_trunk
--disable-nls --disable-shared --target=avr --enable-languages=c,c++
--enable-lto --enable-plugin --with-isl
Thread model: single
gcc version 7.0.1 20170219 (experimental) (GCC) 


Why do not to use version 4 or 5? ))
avr-gcc-4.9.4 generate file with size ~58kB. Nice, but not working.
avr-gcc-5.3.0 generate file with size ~74kB. Uncool.

[Bug c++/79600] [c++11] reinterpret_cast not working in enum class

2017-02-19 Thread smal.root at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79600

--- Comment #1 from smalcom  ---
Created attachment 40775
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40775&action=edit
ii from 4.9.4

[Bug c++/79600] [c++11] reinterpret_cast not working in enum class

2017-02-19 Thread smal.root at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79600

--- Comment #2 from smalcom  ---
Created attachment 40776
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40776&action=edit
ii from 6.3.0

[Bug c++/79600] [c++11] reinterpret_cast not working in enum class

2017-02-19 Thread smal.root at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79600

--- Comment #3 from smalcom  ---
Created attachment 40777
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40777&action=edit
ii from 7.0.1

[Bug c++/79600] [c++11] reinterpret_cast not working in enum class

2017-02-19 Thread smal.root at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79600

--- Comment #5 from smalcom  ---
Second error string... I'm stupid. Thanks for help.
So, old compilers just kinder?

[Bug middle-end/59394] Unused code generated

2021-12-23 Thread smal.root at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59394

--- Comment #5 from smalcom  ---
Created attachment 52049
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52049&action=edit
Generated assembly when using "gc-section". avr-gcc-10.2

[Bug middle-end/59394] Unused code generated

2021-12-23 Thread smal.root at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59394

--- Comment #6 from smalcom  ---
Created attachment 52050
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52050&action=edit
Generated assembly when using "LTO". avr-gcc-10.2

(In reply to Andrew Pinski from comment #4)
> If I use -Wl,--gc-sections -ffunction-sections, then all of the unused
> (non-static) functions are removed.
> 
> Also -flto is able to optimize it too.

I confirm that:
1. With set "-Wl,--gc-sections -ffunction-sections" output file do not contain
unused functions (attached gcsec.lss).
2. With "-flto" all functions are inlined and present only used code (attached
lto.lss).

Tested using gcc-10:

avr-gcc -v
Using built-in specs.
Reading specs from
/mnt/stor5/opt/сборка/avr-10.2.0/bin/../lib/gcc/avr/10.2.0/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/mnt/stor5/opt/сборка/avr-10.2.0/bin/../libexec/gcc/avr/10.2.0/lto-wrapper
Target: avr
Configured with: ../configure --prefix=/opt/toolchain/avr-10.2.0 --target=avr
--enable-languages=c,c++ --disable-nls --disable-libssp --with-dwarf2
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 

Great. Thanks!