FP: destructor with 'noreturn' for delete and temporaries
| Bugzilla Link | 15599 |
| Version | 3.2 |
| OS | All |
| CC | @devincoughlin,@belkadan,@labath,@zygoloid |
Extended Description
I appear to be getting a false positive null dereference warning when running 'clang --analyze' on the following code segment:
#include <stdlib.h>
class Test { public: Test() {} attribute((noreturn)) ~Test(){ abort(); } };
attribute((noreturn)) void test () { abort(); }
void myfunc(int * t) { if (t == nullptr) { Test a(); // causes null dereference warning below on '*t = 4' //test(); // works } *t = 4; }
Since the destructor aborts, it appears (unless I'm missing something) that the program could never actually dereference a null.
mentioned in issue llvm/llvm-bugzilla-archive#16331
I committed a patch to prevent these false positives in r290140. It stops exploration after evaluating a constructor on a temporary object with a no-return destructor when the CFG was built without temporary destructors. This will result in some loss of coverage (especially for life-time extended temporaries) but should avoid the pernicious false positives when no-return temporary destructors are used within assertion macros.
See also llvm/llvm-project#7256 and llvm/llvm-project#9971 for past instances of this code causing trouble for analysis-based warnings.
*** Bug llvm/llvm-bugzilla-archive#16331 has been marked as a duplicate of this bug. ***
Noreturn destructors for temporaries cloned to rdar://problem/13522876
Yes, we don't have proper CFG support for
- delete rdar://problem/12180983
- destructors of temporary objects (no bug yet, but a Hard Problem because of lifetime extension)
For the record, we do handle the simplest possible test case:
void myfunc(int * t) { if (t == nullptr) { Test a; // destructor fires here } *t = 4; }
Also, the following causes the same behavior:
void myfunc(int * t) { if (t == nullptr) { Test *a = new Test; delete a; // causes null dereference warning below //test(); // works } *t = 4; }
Ah, sorry. Same thing happens with:
void myfunc(int * t) { if (t == nullptr) { Test(); // causes null dereference warning below on '*t = 4' //test(); // works } *t = 4; }
Test a();
That is a function declaration.
Also, I came across this when using the 'CHECK' macros in the google-glog library. I essentially had code like the following which would trigger the null-dereference warning:
#include <glog/logging.h>
void func (int * a) { CHECK(a); // use a }
assigned to @tkremenek