<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 - Mishandling SEH filters for available_externally functions"
   href="https://bugs.llvm.org/show_bug.cgi?id=35142">35142</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Mishandling SEH filters for available_externally functions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Core LLVM classes
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>peter@pcc.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat 1.cc
static void try_body(int numerator, int denominator, int *myres) {
  *myres = numerator / denominator;
}

inline int safe_div(int numerator, int denominator, int *res) {
  int myres = 0;
  int success = 1;
  __try {
    try_body(numerator, denominator, &myres);
  } __except (1) {
    success = -42;
  }
  *res = myres;
  return success;
}

void *f() { return (void *)&safe_div; }
$ cat 2.cc
static void try_body(int numerator, int denominator, int *myres) {
  *myres = numerator / denominator;
}

inline int safe_div(int numerator, int denominator, int *res) {
  int myres = 0;
  int success = 1;
  __try {
    try_body(numerator, denominator, &myres);
  } __except (1) {
    success = -42;
  }
  *res = myres;
  return success;
}

void *g() { return (void *)&safe_div; }
$ clang-cl /c 1.cc 2.cc -flto=thin -m32
$ lld-link 1.obj 2.obj /nodefaultlib /entry:f /opt:lldlto=0 /lldsavetemps
LLVM ERROR: assembler label 'L?safe_div@@YAHHHPAH@Z$parent_frame_offset' can
not be undefined

What's going on here is that the linker is choosing 1.obj's definition of
safe_div as prevailing, and requesting that 2.obj's definition be dropped. It
does this by setting linkage to available_externally. This reveals two bugs.
The first is that the localrecover check in Verifier.cpp is insufficient; under
the current semantics it would need to account for available_externally linkage
by calling isDeclarationForLinker instead of isDeclaration.

Even if we did that, though, we'd still hit a verifier check for this test
case, and the fix for that bug is unclear. At the object file level, 2.obj
contains an SEH filter with information about the non-prevailing definition of
safe_seh. The fix I have in mind is that because it is impossible for there to
be an active stack frame for said non-prevailing definition, the behaviour of
the SEH filter is undefined, and we can simply treat the intrinsic call as
equivalent to unreachable if it refers to an undefined function.</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>