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

tgmath.h broken when compiling C with clang-cl #45552

Open
llvmbot opened this issue Jun 4, 2020 · 4 comments · May be fixed by #121650
Open

tgmath.h broken when compiling C with clang-cl #45552

llvmbot opened this issue Jun 4, 2020 · 4 comments · May be fixed by #121650
Labels
bugzilla Issues migrated from bugzilla c clang:headers Headers provided by Clang, e.g. for intrinsics platform:windows

Comments

@llvmbot
Copy link
Member

llvmbot commented Jun 4, 2020

Bugzilla Link 46207
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @CaseyCarter,@zmodem

Extended Description

The Universal CRT does not have a conforming complex.h. The tgmath.h header in Clang (https://github.com/llvm/llvm-project/blob/4cf5743b7784b2c2bff8be82e1a5cc37f8c68a36/clang/lib/Headers/tgmath.h) assumes a conforming complex.h and therefore cannot be compiled by clang-cl when building as C.

Repro:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.0-pre.3.0
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

C:\Users\stwish\source>set "PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\bin;%PATH%"

C:\Users\stwish\source>type tgmath_repro.c
#include <tgmath.h>

int main()
{
    return 0;
}

C:\Users\stwish\source>clang-cl tgmath_repro.c -ferror-limit=1
In file included from tgmath_repro.c:1:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\lib\clang\10.0.0\include\tgmath.h(72,50): error: passing
      '_Complex float' to parameter of incompatible type '_Fcomplex' (aka 'struct _C_float_complex')
    __tg_acos(float _Complex __x) {return cacosf(__x);}
                                                 ^~~
C:\Program Files (x86)\Windows Kits\10\include\10.0.19620.0\ucrt\complex.h(98,50): note: passing argument to parameter '_Z' here
_ACRTIMP _Fcomplex __cdecl cacosf(_In_ _Fcomplex _Z);
                                                 ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 errors generated.
@zmodem
Copy link
Collaborator

zmodem commented Jun 5, 2020

I'm not sure what the best way forward is here.

If we make Clang's tgmath.h defer to the UCRT tgmath.h, that avoids the current compile error. But it doesn't help users who actually want to use the type-generic macros.

And if the UCRT tgmath.h later implements support for type-generic macros, it's not clear that it would work with Clang since the implementation might be closely tied to the compiler.

Is there anything blocking the UCRT's complex.h from changing to be more conforming? Wouldn't that be beneficial in itself, that is, it would be good for developers using complex.h?

@sivachandra
Copy link
Collaborator

I do not think this is related to the libc project.

@Endilll Endilll changed the title tgmath.h broken when compiling C with clang-cl tgmath.h broken when compiling C with clang-cl Jul 18, 2024
@Endilll Endilll added the clang:to-be-triaged Should not be used for new issues label Jul 18, 2024
@frederick-vs-ja
Copy link
Contributor

Is there anything blocking the UCRT's complex.h from changing to be more conforming?

The blocker is lack of implementation of _Complex in MSVC.

Looks like that __builtin_bit_cast can be used as a workaround. Godbolt link.

@frederick-vs-ja frederick-vs-ja added clang:headers Headers provided by Clang, e.g. for intrinsics platform:windows c and removed clang:to-be-triaged Should not be used for new issues labels Jan 2, 2025
@llvmbot
Copy link
Member Author

llvmbot commented Jan 2, 2025

@llvm/issue-subscribers-c

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [46207](https://llvm.org/bz46207) | | Version | trunk | | OS | Windows NT | | Reporter | LLVM Bugzilla Contributor | | CC | @CaseyCarter,@zmodem |

Extended Description

The Universal CRT does not have a conforming complex.h. The tgmath.h header in Clang (https://github.com/llvm/llvm-project/blob/4cf5743b7784b2c2bff8be82e1a5cc37f8c68a36/clang/lib/Headers/tgmath.h) assumes a conforming complex.h and therefore cannot be compiled by clang-cl when building as C.

Repro:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.7.0-pre.3.0
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

C:\Users\stwish\source&gt;set "PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\bin;%PATH%"

C:\Users\stwish\source&gt;type tgmath_repro.c
#include &lt;tgmath.h&gt;

int main()
{
    return 0;
}

C:\Users\stwish\source&gt;clang-cl tgmath_repro.c -ferror-limit=1
In file included from tgmath_repro.c:1:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\lib\clang\10.0.0\include\tgmath.h(72,50): error: passing
      '_Complex float' to parameter of incompatible type '_Fcomplex' (aka 'struct _C_float_complex')
    __tg_acos(float _Complex __x) {return cacosf(__x);}
                                                 ^~~
C:\Program Files (x86)\Windows Kits\10\include\10.0.19620.0\ucrt\complex.h(98,50): note: passing argument to parameter '_Z' here
_ACRTIMP _Fcomplex __cdecl cacosf(_In_ _Fcomplex _Z);
                                                 ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 errors generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c clang:headers Headers provided by Clang, e.g. for intrinsics platform:windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants