<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">You're probably barking up the wrong
      tree; the problem has nothing to do with code generation. 
      Consider the following testcase:<br>
      <br>
      template<typename T> struct Z {<br>
        T t;<br>
        Z(const Z&) { throw 1; }<br>
        ~Z() { *t = 10; }<br>
      };<br>
      struct X {<br>
         Z<int> x;<br>
         Z<int> y;<br>
      };<br>
      void foo(Z<int>& a) {<br>
         new X{a, a};<br>
      }<br>
      <br>
      This should emit an error because "t" can't be dereferenced.  gcc
      correctly the error; clang doesn't.<br>
      <br>
      Not exactly sure why the destructor doesn't get marked odr-used,
      but I'd start with Sema::BuildCXXNew.<br>
      <br>
      -Eli<br>
      <br>
      On 5/1/2018 11:40 PM, Keith Wyss via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAFAoezAryfa4do40Au2XQ8q62OBcu9i_xcGnXOgfDBymRtopTQ@mail.gmail.com">
      <div dir="ltr">Hmmm... It seems like I should check out how the
        UseList on Value (and its child BasicBlock) work.</div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Tue, May 1, 2018 at 8:34 PM, Keith
          Wyss <span dir="ltr"><<a href="mailto:wyssman@gmail.com"
              target="_blank" moz-do-not-send="true">wyssman@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">Hi,
              <div><br>
              </div>
              <div>I'm trying to understand how clang keeps track of
                which declarations are called within a translation unit
                and decides to codegen their definitions.</div>
              <div><br>
              </div>
              <div>DeclBase.h has a markUsed to keep track of ODR use,
                and I think that the decl can be found from the symbol
                table via ASTContext.h (for example looking up a
                template via GetQualifiedTemplateName ->
                getAsTemplateDecl -> setIsUsed ). This is just a
                result of fumbling around in the dark, I could be
                totally wrong.</div>
              <div><br>
              </div>
              <div>I'd like to know what part of the system is
                responsible for tracking usage, and whether that's the
                same mechanism that decides whether to CodeGen basic
                blocks with function definitions.</div>
              <div><br>
              </div>
              <div>Particularly, I'm curious about how the decision
                should be made whether to emit a definition for a
                destructor that it is only called in a cleanup block
                that's only invoked during unwinding. I don't actually
                understand how or whether the control flow for unwinding
                is expressed in the AST at all. I can't see anything
                related to unwinding control flow with -ast-dump for
                instance.</div>
              <div><br>
              </div>
              <div>I've been spending some time debugging a particular
                test program at <a
                  href="https://bugs.llvm.org/show_bug.cgi?id=33778"
                  target="_blank" moz-do-not-send="true">bug 33778</a>
                that fails to link because a block only referenced from
                an LSDA contains a call instruction to a destructor that
                has no generated definition. I'm hitting a wall because
                I'm pretty ignorant of the structure of the codebase and
                any guidance would be appreciated.</div>
              <div><br>
              </div>
              <div>Any general guidance or documentation to help find my
                way around clang would be awesome too.</div>
              <div><br>
              </div>
              <div>Thanks,</div>
              <div>Keith</div>
              <div><br>
              </div>
              <div>P.S. The program that doesn't link without
                -fno-exceptions:</div>
              <div><br>
              </div>
              <div>#include <functional></div>
              <div><br>
              </div>
              <div>struct X {</div>
              <div>   std::function<int()> F;</div>
              <div>   std::function<int()> G;</div>
              <div>};</div>
              <div><br>
              </div>
              <div>void foo(const std::function<int()>& a) {</div>
              <div>   new X{a, a};</div>
              <div>}</div>
              <div><br>
              </div>
              <div>int main() {</div>
              <div>  return 0;</div>
              <div>}</div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <p><br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
  </body>
</html>