<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 - 7.1 2.2 Example does not work properly after disabling -fmerge-all-constants"
   href="https://bugs.llvm.org/show_bug.cgi?id=37058">37058</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>7.1 2.2 Example does not work properly after disabling -fmerge-all-constants
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ilia.taraban@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This test starts failing after disabling -fmerge-all-constants:

================= nice.cpp ============

const char * goo (const char * s1, const char * s2)
{
    const char * p;
    if (* s2 == '\0') 
        return 0;
    p = 0;
    return 0;
}
void foo (const char * s)
{
    const char * p = goo(0, "S");
    int i;
}
struct S { int n; };
auto f ()
{
    S x = { 1 };
    constexpr S y = { 2 };
    return [&](bool b) { return (b ? y : x).n;
    };
}
auto g = f();
int main (int argc, char * argv [])
{
    foo(0);
    int n = g(true);  // OK, according to 7.1 2.2
    return 2 - n;   
}


=======================================

<span class="quote">>>> clang -v</span >
clang version 7.0.0 (trunk 329586)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...

<span class="quote">>>> clang++ -o nice.exe nice.cpp
>>> nice.exe</span >
2
<span class="quote">>>> clang++ -o nice.exe nice.cpp -fmerge-all-constants
>>> nice.exe</span >
0

 So after disabling this option current test (which is similar to Example from
7.1 2.2) giving wrong result. Now x and y behave similar.
<span class="quote">>>> @_ZZ3maxvE1a = private unnamed_addr constant %struct.A { i32 1 }, align 4
>>> @_ZZ3maxvE1b = private unnamed_addr constant %struct.A { i32 2 }, align 4</span ></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>