Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlib's trigonometric functions won't compile by Clang #584

Open
abrodkin opened this issue Nov 24, 2023 · 2 comments
Open

Newlib's trigonometric functions won't compile by Clang #584

abrodkin opened this issue Nov 24, 2023 · 2 comments
Labels
bug component: newlib upstreaming: needed This items needs to be solved in corresponding upstream project.

Comments

@abrodkin
Copy link
Member

Consider a very simple example:

#include <tgmath.h>

float f1, f = 0.5f;

int main(void)
{
        f1 = acos(f);
}

Compile with a full GNU toolchain:

arc-elf32-gcc -c test.c

Compile with a full Clang/LLVM tollchain:

clang -c test.c

Now let's try to compile with Clang and headers of Newlib:

clang -c test.c -I.../newlib/install/arc/include
test.c:8:14: error: '__builtin_choose_expr' requires a constant expression
        f1 = acos(f);
             ^~~~~~~
.../newlib/install/arc/include/tgmath.h:111:20: note: expanded from macro 'acos'
#define acos(__x)               __tg_full(__x, acos)
                                ^~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:107:2: note: expanded from macro '__tg_full'
        __tg_impl_full(__x, __x, __x, __fn, __fn##f, __fn##l, c##__fn, c##__fn##f, c##__fn##l, __x)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:96:6: note: expanded from macro '__tg_impl_full'
            __tg_impl_simple(__x, __y, __z, __cfn, __cfnf, __cfnl, __VA_ARGS__),        \
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:86:3: note: expanded from macro '__tg_impl_simple'
                __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:71:2: note: expanded from macro '__tg_type_corr'
        (__tg_type3(__e1, __e2, __e3, __t) ||                           \
        ^
1 error generated.

Any ideas on how to fix that? Is that a problem in Newlib or Clang?

@abrodkin
Copy link
Member Author

Hm, looks like we don't need these headers in Newlib in the first place, as compilers provide its own versions which are known to work for them. See picolibc/picolibc@7c9e9c3 & picolibc/picolibc@e6a8fc6.

abrodkin added a commit to foss-for-synopsys-dwc-arc-processors/newlib that referenced this issue Nov 24, 2023
Inspired by picolibc/picolibc@7c9e9c3

As per Keth Packard: "These are provided by the compiler and
shouldn't be replaced with our versions."

And indeed, an attempt to use these Newlib's headers with Clang-based compilers
lead to compilation error:
---------------------->8---------------------
clang -c test.c -I.../newlib/install/arc/include
test.c:8:14: error: '__builtin_choose_expr' requires a constant expression
        f1 = acos(f);
             ^~~~~~~
.../newlib/install/arc/include/tgmath.h:111:20: note: expanded from macro 'acos'
                                ^~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:107:2: note: expanded from macro '__tg_full'
        __tg_impl_full(__x, __x, __x, __fn, __fn##f, __fn##l, c##__fn, c##__fn##f, c##__fn##l, __x)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:96:6: note: expanded from macro '__tg_impl_full'
            __tg_impl_simple(__x, __y, __z, __cfn, __cfnf, __cfnl, __VA_ARGS__),        \
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:86:3: note: expanded from macro '__tg_impl_simple'
                __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:71:2: note: expanded from macro '__tg_type_corr'
        (__tg_type3(__e1, __e2, __e3, __t) ||                           \
        ^
1 error generated.
---------------------->8---------------------

See foss-for-synopsys-dwc-arc-processors/toolchain#584

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
@abrodkin abrodkin added bug component: newlib upstreaming: needed This items needs to be solved in corresponding upstream project. labels Nov 24, 2023
@claziss
Copy link
Contributor

claziss commented Nov 27, 2023

Maybe this is an issue which you can discuss it with upstream Newlib maintainers. I see no problem with GNU toolchain.

@claziss claziss removed their assignment Nov 27, 2023
abrodkin added a commit to foss-for-synopsys-dwc-arc-processors/newlib that referenced this issue Nov 27, 2023
Inspired by picolibc/picolibc@7c9e9c3

As per Keth Packard: "These are provided by the compiler and
shouldn't be replaced with our versions."

And indeed, an attempt to use these Newlib's headers with Clang-based compilers
lead to compilation error:
---------------------->8---------------------
clang -c test.c -I.../newlib/install/arc/include
test.c:8:14: error: '__builtin_choose_expr' requires a constant expression
        f1 = acos(f);
             ^~~~~~~
.../newlib/install/arc/include/tgmath.h:111:20: note: expanded from macro 'acos'
                                ^~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:107:2: note: expanded from macro '__tg_full'
        __tg_impl_full(__x, __x, __x, __fn, __fn##f, __fn##l, c##__fn, c##__fn##f, c##__fn##l, __x)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:96:6: note: expanded from macro '__tg_impl_full'
            __tg_impl_simple(__x, __y, __z, __cfn, __cfnf, __cfnl, __VA_ARGS__),        \
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:86:3: note: expanded from macro '__tg_impl_simple'
                __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../newlib/install/arc/include/tgmath.h:71:2: note: expanded from macro '__tg_type_corr'
        (__tg_type3(__e1, __e2, __e3, __t) ||                           \
        ^
1 error generated.
---------------------->8---------------------

See foss-for-synopsys-dwc-arc-processors/toolchain#584

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component: newlib upstreaming: needed This items needs to be solved in corresponding upstream project.
Projects
None yet
Development

No branches or pull requests

2 participants