<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 - Compiler "clang" makes optimization error (Ubuntu 20.04.2 LTS, clang version 10.0.0-4ubuntu1)"
   href="https://bugs.llvm.org/show_bug.cgi?id=50581">50581</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compiler "clang" makes optimization error (Ubuntu 20.04.2 LTS, clang version 10.0.0-4ubuntu1)
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>10.0
          </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>release blocker
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>sergkryzh@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Compiler "clang" makes an error when optimizing specific code (please note that
"Apple Clang" has the same problem under macOS). Below are steps to reproduce
the problem.
1. Create file "main.cpp" with such code:
#include <iostream>
class AnyClassOrType {
};
AnyClassOrType * GetPtr() {
    return nullptr;
}
AnyClassOrType & GetRef() {
    return *GetPtr();
}
int main(int argc, const char * argv[]) {
    AnyClassOrType *Ptr = GetPtr();
    AnyClassOrType *RefPtr = &GetRef();
    std::cout << std::boolalpha;
    std::cout << "nullptr == Ptr " << (nullptr == Ptr) << "\n"; // Debug &
Release: true
    std::cout << "nullptr == RefPtr " << (nullptr == RefPtr) << "\n"; // Debug:
true, Release: false (!)
    char Buffer[128];
    sprintf(Buffer, "RefPtr == %p", RefPtr); // Debug & Release: RefPtr ==
(nil)
    std::cout << Buffer << "\n";
    if(Ptr) { // Debug & Release: false
        std::cout << "if(Ptr) == true\n";
    }
    if(RefPtr) { // Debug: false, Release: true (!)
        std::cout << "if(RefPtr) == true\n";
    }
    return 0;
}
2. Build and run unoptimized (debug) and optimized (release) executables:
$ clang++ main.cpp -o debug
$ ./debug
$ clang++ -O2 main.cpp -o release
$ ./release
You will see that the output is different between them.</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>