[Bug tree-optimization/91901] New: constexpr stack array not optimized away

trass3r at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 25 14:01:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91901

            Bug ID: 91901
           Summary: constexpr stack array not optimized away
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: trass3r at gmail dot com
  Target Milestone: ---

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

#include
<https://github.com/Neargye/magic_enum/raw/master/include/magic_enum.hpp>

enum class E
{
  E00, E01, E02, E03, E04, E05, E06, E07, E08, E09,
  E10, E11, E12, E13, E14, E15, E16, E17, E18, E19,
  E20, E21, E22, E23, E24, E25, E26, E27, E28, E29,
  E30, E31, E32, E33, E34, E35, E36, E37, E38, E39,
  E40, E41, E42, E43, E44, E45, E46, E47, E48, E49,
  E50, E51, E52, E53, E54, E55, E56, E57, E58, E59,
  E60, E61, E62, E63,
};

#include <cstdio>
void test(Color c)
{
    auto name = magic_enum::enum_name(c);
    printf(name.data());
}

$ g++ -O2 -std=c++2a
It generates the lookup table in .rodata but then still copies it to the stack
inside name<E>(E): https://godbolt.org/z/cDp30l

Remove E63 to see the initialization being completely inlined, potentially
resulting in even larger code.


More information about the Gcc-bugs mailing list