<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 - Clang can not detect binding to null pointer"
   href="https://bugs.llvm.org/show_bug.cgi?id=46089">46089</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang can not detect binding to null pointer
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>haoxintu@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>This simple case test.cc

#include<iostream>

int main(){
    int &x = *(int *)nullptr; // Error: null reference
    std::cout << "ok" << std::endl;
    return 0;
}

In clang-trunk, clang-10, clang-9 can not detect runtime error, while clang-8
and lower version does.

$clang++-trunk -fsanitize=null test.cc ; ./a.out
test.cc:4:14: warning: binding dereferenced null pointer to reference has
undefined behavior [-Wnull-dereference]
    int &x = *(int *)nullptr;
             ^~~~~~~~~~~~~~~
1 warning generated.
ok

$clang++-8 -w -fsanitize=null test.cc ; ./a.out
test.cc:4:14: warning: binding dereferenced null pointer to reference has
undefined behavior [-Wnull-dereference]
    int &x = *(int *)nullptr;
             ^~~~~~~~~~~~~~~
1 warning generated.
test.cc:4:14: runtime error: reference binding to null pointer of type 'int'
ok

My clang-trunk version is

$clang++-trunk --version
clang version 11.0.0 (<a href="https://github.com/llvm/llvm-project">https://github.com/llvm/llvm-project</a>
210616bd38d589020b45f8cbbf9f9ef1296f2729)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/compilers/llvm-clang/llvm-project/build/bin

Is clang delete runtime error message when "-fsanitize=null" is used in new
recent versions after clang-8? If not, I think there something wrong with the
above case.</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>