[LLVMbugs] [Bug 20952] New: Clang should warn when using pointer to dead scoped variable within the same function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Sep 15 15:18:42 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20952

            Bug ID: 20952
           Summary: Clang should warn when using pointer to dead scoped
                    variable within the same function
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jacob.benoit.1 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13044
  --> http://llvm.org/bugs/attachment.cgi?id=13044&action=edit
testcase

Consider this testcase:

int foo(int i)
{
  int *p = 0;

  if (i)
  {
    int k = i;
    p = &k;
  } /* end of nested scope, k dies, p becomes a dangling pointer */

  return p ? *p : 0; /* the compiler should warn that p points to dead k */
}

Neither Clang 3.4 nor GCC 4.8 currently generate a warning. Yet, since all is
local to this function, it seems like something that a compiler could easily
warn against, and that would have saved me some time today!

-- 
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/20140915/ec78437b/attachment.html>


More information about the llvm-bugs mailing list