Skip to content

in C double and _Float64 mist be destinct types (and float and _Float32) #50110

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

Closed
llvmbot opened this issue Jun 18, 2021 · 2 comments
Closed
Labels
bugzilla Issues migrated from bugzilla c invalid Resolved as invalid, i.e. not a bug

Comments

@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2021

Bugzilla Link 50766
Version 12.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@zygoloid

Extended Description

In C double and _Float64 are destinct types always.

In C float and _Float32 are destinct types always.

In _Float32 must NOT promote to double.

I have the definitive response from the sc22wg14 mailing list confirming
above statements.

Since the mailing list is not public I cannot sent the answer here.

x86-64 clang 12.0.0, icc 19.01 and tcc (unknown version) fail to compile
following program, but gcc 9.2.1 succeeds:

#include <stdio.h>
#include <math.h>

#define PGFN(name) _Generic((name),
float: printf("%s():" #name "=%f\n",func,name),
double: printf("%s():" #name "=%f\n",func,name),
default: printf("%s():" #name "=[unknown type]\n",func),
_Float32:printf("%s():" #name "=%f\n",func,((double)name)),
_Float64:printf("%s():" #name "=%f\n",func,name)
)

int main(int argc,char *argv[]){
float f=4.0;
double d=8.0;
_Float32 f32=32.0;
_Float64 f64=64.0;
(void)argc,(void)argv;
PGFN(f);
PGFN(d);
PGFN(f32);
PGFN(f64);
return 0;
}

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@AaronBallman AaronBallman added the confirmed Verified by a second party label May 5, 2022
@AaronBallman
Copy link
Collaborator

According to TS 18661-3 X.2.1p3: "Each interchange floating type is not compatible with any other type." so I can confirm that this is incorrect in Clang.

@AaronBallman AaronBallman added invalid Resolved as invalid, i.e. not a bug and removed confirmed Verified by a second party labels May 5, 2022
@AaronBallman
Copy link
Collaborator

Whoops, I confirmed too soon! Clang itself has no support for _Float32 or _Float64 yet (though we do have support for _Float16 from TS18661-3). These are coming from glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=bits/floatn-common.h;h=92982d64601bc562733ffd64f9e88854407c16c7;hb=refs/heads/master#l214 (Note: #define __HAVE_DISTINCT_FLOAT32 0 is also specified by glibc.)

So this is not actually a Clang bug, we don't claim to support TS 18661-3 (we don't define __STDC_IEC_60559_TYPES). You can verify this yourself by doing a -E compilation and noting where the typedef comes from. For me, that's:

# 214 "/usr/include/x86_64-linux-gnu/bits/floatn-common.h" 3 4
typedef float _Float32;
# 251 "/usr/include/x86_64-linux-gnu/bits/floatn-common.h" 3 4
typedef double _Float64;

Closing as invalid since this is a glibc behavior.

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 invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

2 participants