<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a question about the IR model for SEH filters (as I want to use the same model for CLR filters). In particular, when an outer filter is invoked before entering an inner finally, which piece of IR reflects the filter's side-effects?
To take a concrete example, consider this C code:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">void foo() {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> int x;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> __try {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> x = 0;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> __try {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> x = 2;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> may_throw();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> __finally {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> if (x == 1) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> printf("correct\n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> else {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> printf("incorrect\n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> __except (x = 1) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The IR for the path from "x = 2" to the load of x in the __finally (via the exception edge) looks like so:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> store i32 2, i32* %x, align 4<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> invoke void bitcast (void (...)* @may_throw to void ()*)() #4<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> to label %invoke.cont unwind label %lpad<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">lpad: ; preds = %entry<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> cleanup<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@foo@@" to i8*)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> %2 = extractvalue { i8*, i32 } %1, 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> store i8* %2, i8** %exn.slot<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> %3 = extractvalue { i8*, i32 } %1, 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> store i32 %3, i32* %ehselector.slot<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> store i8 1, i8* %abnormal.termination.slot<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> br label %__finally<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">__finally: ; preds = %lpad, %invoke.cont<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> %0 = load i32, i32* %x, align 4<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What I'm wondering is where exactly this models the call to @"\01?filt$0@0@foo@@" and its store to x. Is it implicitly part of the execution of the landingpad instruction itself? Or of the invoke?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks<o:p></o:p></p>
<p class="MsoNormal">-Joseph<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>