[PATCH] D39641: [CodeGen] make cbrt and fma constant (never set errno)

Sanjay Patel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 5 07:18:57 PST 2017


spatel created this revision.
Herald added a subscriber: mcrosier.

Splitting cbrt and fma off from https://reviews.llvm.org/D39611, so we can deal with complex.h separately.

I've also gone ahead with a 'fix' for the fma case in CodeGenFunction::EmitBuiltinExpr(). But as noted previously, there's no test change because we were ignoring the const-ness of something that might have been non-const. Now, we're correctly checking that attribute even though there's no way it can be non-const. So if we change our minds about the fma decision, we'll do it in the right place. :)

Copying from https://reviews.llvm.org/D39611:

1. Cube root

We're going to dismiss POSIX language like this:
"On successful completion, cbrt() returns the cube root of x. If x is NaN, cbrt() returns NaN and errno may be set to [EDOM]. "
http://pubs.opengroup.org/onlinepubs/7908799/xsh/cbrt.html

And favor an interpretation based on the C standard that says:
"Functions with a NaN argument return a NaN result and raise no floating-point exception, except where stated otherwise."

2. Floating multiply-add

The C standard is silent?
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fma.html - clearly says "...then errno shall be set..."
but:
https://linux.die.net/man/3/fma - "These functions do not set errno."

Let's opt for the - hopefully common - implementation where errno is not set. Note that there's no test change because as noted in the earlier discussion, we're ignoring the const attr in CodeGenFunction::EmitBuiltinExpr(). I'll look at what needs fixing in that function next.


https://reviews.llvm.org/D39641

Files:
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/builtin-errno.c
  test/CodeGen/libcalls-errno.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39641.121627.patch
Type: text/x-patch
Size: 5308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171105/cbee5c50/attachment.bin>


More information about the cfe-commits mailing list