<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -O1,2,3 + const inline value = SLOW"
   href="https://bugs.llvm.org/show_bug.cgi?id=52548">52548</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-O1,2,3 + const inline value = SLOW
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>2.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>johannes.fieres@volumegraphics.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25458" name="attach_25458" title="Reproducing example (cpp file)">attachment 25458</a> <a href="attachment.cgi?id=25458&action=edit" title="Reproducing example (cpp file)">[details]</a></span>
Reproducing example (cpp file)

Hi,

the c++17 construct "inline const var = initializer;" causes the optimizer to
run very long even if there is nothing obvious to optimize. 

I have prepared a simple test "program" (a.cpp) which does nothing but declare
and initialize 1000 constants in this manner. 

clang++ -std=c++17 -O0 -c a.cpp -o o # takes 0.31 seconds
clang++ -std=c++17 -O1 -c a.cpp -o o # takes 1.14 seconds

Somebody in our company had the idea to change all our global enum header from
"extern const int" (with initialization in a separate source) to "inline const
int" (with initialization in the header). This causes my build times rise from
25 to 40 minutes in Release mode :-( With cl.exe and gcc we see a similar
effect but by far not as severe.

I can see that "inline const int" is much more costly to compile compared to
"extern const int", because you need to be able to deduplicate the constants
and their initialization later.

However, it's obscure to me why the optimizer should have anything to do in the
reproducing example, except to find out that there is nothing to optimize (note
that the initializer function itself is just declared, not defined, in this
example).

Thanks!</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>