[llvm-bugs] [Bug 30761] New: Windows x64 SEH __except inside __finally the finally runs twice
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Oct 21 06:36:11 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=30761
Bug ID: 30761
Summary: Windows x64 SEH __except inside __finally the finally
runs twice
Product: new-bugs
Version: 3.9
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: nb at ravenbrook.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 17474
--> https://llvm.org/bugs/attachment.cgi?id=17474&action=edit
C source, with disassembly and comparison to code generated by Visual Studio
Using Clang 3.9.0 for x64 on Windows:
int f(int x)
{
__try {
__try {
x = g(x);
} __except((x == 42) ? EXCEPTION_EXECUTE_HANDLER :
EXCEPTION_CONTINUE_SEARCH) {
++x;
}
} __finally {
x *= 2;
}
return x;
}
if called with x == 42, and g raises an exception, then f returns 170 and not
86 as it should. The finally clause is run twice, once as a "cleanup" function
called from __C_specific_handler, after the filter fires but before the
handler, and once in the continuation from the try clause. It is incorrect for
the cleanup function to be called in this case.
Looking through the generated code, and comparing with that produced by Visual
Studio, the problem seems to be that the data produced by Clang doesn't trigger
the EXCEPTION_TARGET_UNWIND case inside __C_specific_handler. That case
specifically prevents cleanup functions from being called if the TargetIP is in
the ScopeRecord's range. However, the TargetIP in this case is the address of
the handler continuation, and the handler continuation has not been placed in
the range of the scope record.
The attachment here has a detailed disassembly and commentary on the unwind
data etc, and a comparison with code generated by Visual Studio.
Clang generates a good filter function and continuation code for the __except
clause, and also generates a cleanup function for the __finally clause.
--
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/20161021/2b1cdf63/attachment.html>
More information about the llvm-bugs
mailing list