<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 - [coverage][windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl"
   href="https://bugs.llvm.org/show_bug.cgi?id=32761">32761</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[coverage][windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>adamf88@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18334" name="attach_18334" title="Test + My fix.">attachment 18334</a> <a href="attachment.cgi?id=18334&action=edit" title="Test + My fix.">[details]</a></span>
Test + My fix.

In function CodeGenPGO::skipRegionMappingForDecl there is possible NULL pointer
dereference on line:
auto Loc = D->getBody()->getLocStart();
Value returned by getBody may be nullptr. 

(minor)
The variable SkipCoverageMapping in the same function has always value false.
Shouldn't it be removed ?

In attachment I have added my sample fix and test to reproduce the bug. In the
patch I have also removed the variable mentioned above. 
To fix this issue check: "if(!D->hasBody()) return true;" should be enough.

Sample code to reproduce the problem:
class A
{
public:
  A();
  virtual ~A();
};

class B : public A
{
public:
  B(const A& base)
    : A(base)
  {}
};

void Test()
{
  A a;
  B b(a);
}

Compile command:
clang++ -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj
-fprofile-instrument=clang -std=c++14 -fcoverage-mapping -dump-coverage-mapping
-emit-llvm-only -main-file-name empty-destructor.cpp -o - empty-destructor.cpp

Effect:
Crash.</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>