<html><body><p>Hi John,<br><br><tt>John McCall <rjmccall@gmail.com> wrote on 11/17/2015 09:50:20 PM:<br><br>> From: John McCall <rjmccall@gmail.com></tt><br><tt>> To: Samuel F Antao/Watson/IBM@IBMUS</tt><br><tt>> Cc: Alexey Bataev <a.bataev@hotmail.com>, cfe-dev <cfe-<br>> dev@lists.llvm.org>, Hal Finkel <hfinkel@anl.gov>, Reid Kleckner <br>> <rnk@google.com></tt><br><tt>> Date: 11/17/2015 09:50 PM</tt><br><tt>> Subject: Re: [cfe-dev] Fwd: Library calls for complex types and <br>> terminate scopes.</tt><br><tt>> <br>> Oops!  Sorry, I forgot about a layer of abstraction here.  It turns <br>> out that we have this information on the ExtProtoInfo, but not the <br>> ordinary ExtInfo, and we only find it for normal calls by examining <br>> the called Decl.</tt><br><tt>> <br>> Putting an attribute on the Function isn't going to help, <br>> unfortunately; you'll need some way to propagate this down to <br>> ConstructAttributeList.  I see two options here.</tt><br><tt>> <br>> The first option is just to construct a FunctionDecl with the <br>> appropriate FunctionProtoType that includes a noexcept specification<br>> or a nothrow attribute or something.  This is probably the easiest <br>> thing to do, and if done properly it would solve any potential <br>> problems with fetching the global declaration as well.</tt><br><tt>> <br>> The second option — and this is more involved — is that it would <br>> generally make sense to have a better abstraction for the abstract <br>> callee.  Right now, we're just passing around a Decl*, but that has <br>> some significant drawbacks.  First, it glosses over some very <br>> important differences, like the difference between a direct call and<br>> a virtual call to the same C++ member function.  Second, it means we<br>> lose the ability to remember anything interesting about callees that<br>> (as here) aren't tied to specific declarations.  An example of the <br>> latter issue that's closely related to this one is that you can make<br>> a function pointer type in C++ with an exception specification, and <br>> it's intended to be illegal (under C++'s weird informal type system <br>> around exception specifications; [except.spec]p6) for a call to a <br>> value of such a type to violate the specification, but we don't take<br>> advantage of that in IRGen because we tie these things purely to <br>> calls; whereas we totally could take advantage of it if you could <br>> define an abstract callee with just a FunctionProtoType.</tt><br><br><tt>I'm doing an attempt on the second option in </tt><a href="http://reviews.llvm.org/D14796"><tt>http://reviews.llvm.org/D14796</tt></a><tt>. Hope this is more or less what you had in mind. It probably needs to be extended to cover all the possible patterns, but I think it is possible first step. Let me know your comments/remarks.</tt><br><br><tt>Thanks!</tt><br><tt>Samuel</tt><br><br><br><tt>> <br>> I would prefer to solve this the second way, but I can sympathize if<br>> you see that as out-of-scope for your patch.</tt><br><tt>> <br>> John.</tt><br><tt>> <br>> On Tue, Nov 17, 2015 at 5:58 PM, Samuel F Antao <sfantao@us.ibm.com> wrote:</tt><br><tt>> Reid, John,<br>> <br>> Thanks for the feedback!<br>> <br>> John McCall <rjmccall@gmail.com> wrote on 11/17/2015 08:34:18 PM:<br>> <br>> > From: John McCall <rjmccall@gmail.com><br>> > To: Reid Kleckner <rnk@google.com><br>> > Cc: Samuel F Antao/Watson/IBM@IBMUS, cfe-dev <cfe-<br>> > dev@lists.llvm.org>, Alexey Bataev <a.bataev@hotmail.com>, Hal <br>> > Finkel <hfinkel@anl.gov><br>> > Date: 11/17/2015 08:34 PM<br>> > Subject: Re: [cfe-dev] Fwd: Library calls for complex types and <br>> > terminate scopes.<br>> > <br>> > On Tue, Nov 17, 2015 at 4:54 PM, Reid Kleckner <rnk@google.com> wrote:<br>> > Maybe you could mark the runtime function nounwind when you get its <br>> > declaration here:<br>> >   llvm::Constant *Func = CGF.CGM.CreateBuiltinFunction(FTy, <br>> > LibCallName /*pass an AttributeSet here*/);<br>> > <br>> > Then you won't have to call setDoesNotThrow() later.<br>> > <br>> > The by-design way to do this is to add a noexcept specification to <br>> > the ExtInfo being passed to arrangeFreeFunctionCall.<br>> <br>> Just to make sure I get it right. You'd like me to add a new bit to <br>> ExtInfo and use it instead of the check of the nounwind attribute in<br>> EmitCall, right?<br>> <br>> I'd probably keep the check of the attribute anyway as there may be <br>> other places that are already relying on the attribute, do you agree?<br>> <br>> Thanks again,<br>> Samuel</tt><br><tt>> <br>> <br>> <br>> > <br>> > John.<br>> > <br>> > On Tue, Nov 17, 2015 at 4:43 PM, Samuel F Antao via cfe-dev <cfe-<br>> > dev@lists.llvm.org> wrote:<br>> > Hi all,<br>> > <br>> > I came across an issue that happens to trigger an assertion in clang<br>> > if an operation with type type is implemented in a scope that <br>> > happens to install a terminate scope in the exceptions stack. I see <br>> > the issue while using complex arithmetic in OpenMP regions, but I <br>> > believe that could also be a problem for non-openMP codes. <br>> > <br>> > The problem happens in `ComplexExprEmitter::EmitComplexBinOpLibCall`<br>> > and is caused by an assertion in:<br>> > <br>> > ```<br>> >   RValue Res = CGF.EmitCall(FuncInfo, Func, ReturnValueSlot(), Args,<br>> >                             nullptr, &Call);<br>> >   cast<llvm::CallInst>(Call)->setCallingConv(CGF.CGM.getBuiltinCC());<br>> >   cast<llvm::CallInst>(Call)->setDoesNotThrow();<br>> > ```<br>> > <br>> > `EHStack.requiresLandingPad()` is used by `EmitCall` and is true if <br>> > we have a scope installed in the exceptions stack. This causes <br>> > `EmitCall` to produce an invoke instruction instead of a call instruction. <br>> > <br>> > One of the ways to tackle the issue is use the proper attributes for<br>> > the library function (e.g. no unwind). Is this the right thing to <br>> > do? Or can these library calls throw in some cases?<br>> > <br>> > Any thoughts?<br>> > <br>> > Here is a simple code that replicates the problem:<br>> > ```<br>> > int main (int argc, char *argv[]){<br>> >   double _Complex dc = (double)argc + 3*I;<br>> > <br>> >   dc *= dc;<br>> >   #pragma omp parallel<br>> >   {<br>> >     dc *= dc;<br>> >   }<br>> >   printf("%lf %lf\n",creal(dc),cimag(dc));<br>> >   return 0;<br>> > }<br>> > ``` <br>> > <br>> > Thanks!<br>> > Samuel<br>> > <br>> > _______________________________________________<br>> > cfe-dev mailing list<br>> > cfe-dev@lists.llvm.org<br>> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>> <br>> > <br>> > <br>> <br>> > <br>> > -- <br>> > I suppose you'd like my real thoughts as well.</tt><br><tt>> <br></tt><br><tt>> <br>> -- </tt><br><tt>> I suppose you'd like my real thoughts as well.</tt><BR>
</body></html>