llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

FP: destructor with 'noreturn' for delete and temporaries

Open andrewjcg opened this issue 13 years ago • 11 comments

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.

andrewjcg avatar Mar 26 '13 20:03 andrewjcg

mentioned in issue llvm/llvm-bugzilla-archive#16331

llvmbot avatar Nov 26 '21 18:11 llvmbot

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.

devincoughlin avatar Dec 20 '16 06:12 devincoughlin

See also llvm/llvm-project#7256 and llvm/llvm-project#9971 for past instances of this code causing trouble for analysis-based warnings.

llvmbot avatar Jun 17 '13 22:06 llvmbot

*** Bug llvm/llvm-bugzilla-archive#16331 has been marked as a duplicate of this bug. ***

llvmbot avatar Jun 17 '13 21:06 llvmbot

Noreturn destructors for temporaries cloned to rdar://problem/13522876

belkadan avatar Mar 28 '13 03:03 belkadan

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; }

belkadan avatar Mar 27 '13 01:03 belkadan

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; }

andrewjcg avatar Mar 26 '13 21:03 andrewjcg

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; }

andrewjcg avatar Mar 26 '13 21:03 andrewjcg

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 }

andrewjcg avatar Mar 26 '13 20:03 andrewjcg

assigned to @tkremenek

andrewjcg avatar Mar 26 '13 20:03 andrewjcg