[llvm-bugs] [Bug 46089] New: Clang can not detect binding to null pointer

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 26 22:41:48 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46089

            Bug ID: 46089
           Summary: Clang can not detect binding to null pointer
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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 (https://github.com/llvm/llvm-project
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200527/23cbbc5c/attachment.html>


More information about the llvm-bugs mailing list