[Bug c/56767] New: gcc does not generate correct code with -O2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56767 Bug #: 56767 Summary: gcc does not generate correct code with -O2 Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: jupitercu...@gmail.com == How to repeat (on a 32-bit Linux machine) == With following code: // begin of code #include int round2(int n) { int ret; if (n == 0) { return 0; } __asm__ __volatile__ ("bsr %0, %1\n\t" :"=r"(ret): "r"(n)); ret = 1 << ret; } int main() { int a; scanf("%d", &a); printf("%d\n", round2(a)); return 0; } // end of code With -O0, we get correct result, but with -O2, the generated assembly is: main: .LFB12: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl%esp, %ebp .cfi_def_cfa_register 5 andl$-16, %esp subl$32, %esp leal28(%esp), %eax movl%eax, 4(%esp) movl$.LC0, (%esp) call__isoc99_scanf movl28(%esp), %eax testl %eax, %eax je .L6 #APP # 6 "bit.c" 1 bsr %eax, %eax # 0 "" 2 #NO_APP .L6: movl$0, 4(%esp) // ALWAYS output 0 movl$.LC1, (%esp) callprintf xorl%eax, %eax leave
[Bug c++/82067] New: G++ has an internal compiler error in possible_polymorphic_call_targets, at ipa-devirt.c:1557
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82067 Bug ID: 82067 Summary: G++ has an internal compiler error in possible_polymorphic_call_targets, at ipa-devirt.c:1557 Product: gcc Version: 4.9.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jupitercuso4 at gmail dot com Target Milestone: --- Applied patch from PR60871 but it still fails: $ gcc -v COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/project/usr-tensilica-RHEL5/stools-8.0-2017-06-05/bin/../libexec/gcc/x86_64-pc-linux-gnu/4.9.4/lto-wrapper Target: x86_64-pc-linux-gnu ../gcc-4.9.4/configure --with-checking=release --build=x86_64-pc-linux-gnu -enable-languages=c,c++ --disable-libgcj --prefix=/usr/bin $ g++ -c -O2 -g -MD -Werror -Wno-unused-value -fPIC -Wall -Werror -O3 -fomit-frame-pointer -std=gnu++0x -Wno-non-virtual-dtor -Wno-write-strings -Wno-deprecated -Wno-parentheses -Wno-delete-non-virtual-dtor -Wno-parentheses -Wno-unused-variable test.cpp test.cpp:32:1: internal compiler error: in possible_polymorphic_call_targets, at ipa-devirt.c:1557 0x6828cb possible_polymorphic_call_targets(tree_node*, long, ipa_polymorphic_call_context, bool*, void**, int*) ../../gcc-4.9.4/gcc/ipa-devirt.c:1557 0x665cea possible_polymorphic_call_targets(tree_node*, bool*, void**) ../../gcc-4.9.4/gcc/ipa-utils.h:142 0xc87198 gimple_fold_call ../../gcc-4.9.4/gcc/gimple-fold.c:1127 0xc87198 fold_stmt_1 ../../gcc-4.9.4/gcc/gimple-fold.c:1302 0xd909b8 fold_marked_statements ../../gcc-4.9.4/gcc/tree-inline.c:4549 0xd8c2e0 optimize_inline_calls(tree_node*) ../../gcc-4.9.4/gcc/tree-inline.c:4630 0xf48b89 inline_transform(cgraph_node*) ../../gcc-4.9.4/gcc/ipa-inline-transform.c:457 0xd1b58a execute_one_ipa_transform_pass ../../gcc-4.9.4/gcc/passes.c:2066 0xd1b58a execute_all_ipa_transforms() ../../gcc-4.9.4/gcc/passes.c:2107 0xbd8abd expand_function ../../gcc-4.9.4/gcc/cgraphunit.c:1775 0xf99653 expand_all_functions ../../gcc-4.9.4/gcc/cgraphunit.c:1916 0xf99653 compile() ../../gcc-4.9.4/gcc/cgraphunit.c:2260 0xf98f17 finalize_compilation_unit() ../../gcc-4.9.4/gcc/cgraphunit.c:2337 0xb149dd cp_write_global_declarations() ../../gcc-4.9.4/gcc/cp/decl2.c:4647 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.
[Bug c++/82067] G++ has an internal compiler error in possible_polymorphic_call_targets, at ipa-devirt.c:1557
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82067 --- Comment #3 from jupitercuso4 at gmail dot com --- Created attachment 42101 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42101&action=edit Preprocessed source that triggers the internal error. Preprocessed source attached. Compile it with g++ -std=c++11 -O3 test.i to reproduce the error. Thanks!
[Bug c++/82067] G++ has an internal compiler error in possible_polymorphic_call_targets, at ipa-devirt.c:1557
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82067 --- Comment #5 from jupitercuso4 at gmail dot com --- $ g++ -std=c++11 -O3 --save-temps test.i test.cpp: In constructor 'xtsc_component::xtsc_queue_pin::xtsc_queue_pin(sc_core::sc_module_name, const xtsc_component::xtsc_queue_pin_parms&)': test.cpp:32:1: internal compiler error: in possible_polymorphic_call_targets, at ipa-devirt.c:1557 xtsc_component::xtsc_queue_pin::xtsc_queue_pin(sc_module_name module_name, const xtsc_queue_pin_parms& queue_parms) : ^ 0x6828cb possible_polymorphic_call_targets(tree_node*, long, ipa_polymorphic_call_context, bool*, void**, int*) ../../gcc-4.9.4/gcc/ipa-devirt.c:1557 0x665cea possible_polymorphic_call_targets(tree_node*, bool*, void**) ../../gcc-4.9.4/gcc/ipa-utils.h:142 0xc87198 gimple_fold_call ../../gcc-4.9.4/gcc/gimple-fold.c:1127 0xc87198 fold_stmt_1 ../../gcc-4.9.4/gcc/gimple-fold.c:1302 0xd909b8 fold_marked_statements ../../gcc-4.9.4/gcc/tree-inline.c:4549 0xd8c2e0 optimize_inline_calls(tree_node*) ../../gcc-4.9.4/gcc/tree-inline.c:4630 0xf48b89 inline_transform(cgraph_node*) ../../gcc-4.9.4/gcc/ipa-inline-transform.c:457 0xd1b58a execute_one_ipa_transform_pass ../../gcc-4.9.4/gcc/passes.c:2066 0xd1b58a execute_all_ipa_transforms() ../../gcc-4.9.4/gcc/passes.c:2107 0xbd8abd expand_function ../../gcc-4.9.4/gcc/cgraphunit.c:1775 0xf99653 expand_all_functions ../../gcc-4.9.4/gcc/cgraphunit.c:1916 0xf99653 compile() ../../gcc-4.9.4/gcc/cgraphunit.c:2260 0xf98f17 finalize_compilation_unit() ../../gcc-4.9.4/gcc/cgraphunit.c:2337 0xb149dd cp_write_global_declarations() ../../gcc-4.9.4/gcc/cp/decl2.c:4647 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.
[Bug c++/82067] G++ has an internal compiler error in possible_polymorphic_call_targets, at ipa-devirt.c:1557
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82067 --- Comment #7 from jupitercuso4 at gmail dot com --- $ g++ -std=c++11 -O3 --verbose test.i Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/project/usr-tensilica-RHEL5/stools-8.0-2017-06-05/bin/../libexec/gcc/x86_64-pc-linux-gnu/4.9.4/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-4.9.4/configure --with-checking=release --build=x86_64-pc-linux-gnu --prefix=/usr/xtensa/stools-8.0-2017-06-05 LD_OPTIONS=-R/usr/xtensa/stools-8.0-2017-06-05/lib --with-gmp=/usr/xtensa/stools-8.0-2017-06-05 --with-mpfr=/usr/xtensa/stools-8.0-2017-06-05 --enable-languages=c,c++ --disable-libgcj Thread model: posix gcc version 4.9.4 (GCC) COLLECT_GCC_OPTIONS='-std=c++11' '-O3' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /project/usr-tensilica-RHEL5/stools-8.0-2017-06-05/bin/../libexec/gcc/x86_64-pc-linux-gnu/4.9.4/cc1plus -fpreprocessed test.i -quiet -dumpbase test.i -mtune=generic -march=x86-64 -auxbase test -O3 -std=c++11 -version -o /tmp/cc6LMkmh.s GNU C++ (GCC) version 4.9.4 (x86_64-pc-linux-gnu) compiled by GNU C version 4.9.4, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.9.4 (x86_64-pc-linux-gnu) compiled by GNU C version 4.9.4, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: e4a50cb5767031363285860fcbf01e45 test.cpp: In constructor 'xtsc_component::xtsc_queue_pin::xtsc_queue_pin(sc_core::sc_module_name, const xtsc_component::xtsc_queue_pin_parms&)': test.cpp:32:1: internal compiler error: in possible_polymorphic_call_targets, at ipa-devirt.c:1557 xtsc_component::xtsc_queue_pin::xtsc_queue_pin(sc_module_name module_name, const xtsc_queue_pin_parms& queue_parms) : ^ 0x6828cb possible_polymorphic_call_targets(tree_node*, long, ipa_polymorphic_call_context, bool*, void**, int*) ../../gcc-4.9.4/gcc/ipa-devirt.c:1557 0x665cea possible_polymorphic_call_targets(tree_node*, bool*, void**) ../../gcc-4.9.4/gcc/ipa-utils.h:142 0xc87198 gimple_fold_call ../../gcc-4.9.4/gcc/gimple-fold.c:1127 0xc87198 fold_stmt_1 ../../gcc-4.9.4/gcc/gimple-fold.c:1302 0xd909b8 fold_marked_statements ../../gcc-4.9.4/gcc/tree-inline.c:4549 0xd8c2e0 optimize_inline_calls(tree_node*) ../../gcc-4.9.4/gcc/tree-inline.c:4630 0xf48b89 inline_transform(cgraph_node*) ../../gcc-4.9.4/gcc/ipa-inline-transform.c:457 0xd1b58a execute_one_ipa_transform_pass ../../gcc-4.9.4/gcc/passes.c:2066 0xd1b58a execute_all_ipa_transforms() ../../gcc-4.9.4/gcc/passes.c:2107 0xbd8abd expand_function ../../gcc-4.9.4/gcc/cgraphunit.c:1775 0xf99653 expand_all_functions ../../gcc-4.9.4/gcc/cgraphunit.c:1916 0xf99653 compile() ../../gcc-4.9.4/gcc/cgraphunit.c:2260 0xf98f17 finalize_compilation_unit() ../../gcc-4.9.4/gcc/cgraphunit.c:2337 0xb149dd cp_write_global_declarations() ../../gcc-4.9.4/gcc/cp/decl2.c:4647 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.