[cfe-dev] Fwd: Library calls for complex types and terminate scopes.

Samuel F Antao via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 17 16:43:07 PST 2015


Hi all,

I came across an issue that happens to trigger an assertion in clang if an
operation with type type is implemented in a scope that happens to install
a terminate scope in the exceptions stack. I see the issue while using
complex arithmetic in OpenMP regions, but I believe that could also be a
problem for non-openMP codes.

The problem happens in `ComplexExprEmitter::EmitComplexBinOpLibCall` and is
caused by an assertion in:

```
  RValue Res = CGF.EmitCall(FuncInfo, Func, ReturnValueSlot(), Args,
                            nullptr, &Call);
  cast<llvm::CallInst>(Call)->setCallingConv(CGF.CGM.getBuiltinCC());
  cast<llvm::CallInst>(Call)->setDoesNotThrow();
```

`EHStack.requiresLandingPad()` is used by `EmitCall` and is true if we have
a scope installed in the exceptions stack. This causes `EmitCall` to
produce an invoke instruction instead of a call instruction.

One of the ways to tackle the issue is use the proper attributes for the
library function (e.g. no unwind). Is this the right thing to do? Or can
these library calls throw in some cases?

Any thoughts?

Here is a simple code that replicates the problem:
```
int main (int argc, char *argv[]){
  double _Complex dc = (double)argc + 3*I;

  dc *= dc;
  #pragma omp parallel
  {
    dc *= dc;
  }
  printf("%lf %lf\n",creal(dc),cimag(dc));
  return 0;
}
```

Thanks!
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151117/14bbb7c1/attachment.html>


More information about the cfe-dev mailing list