Skip to content

Commit 62447ef

Browse files
authored
[Clang] Permit half precision in __builtin_complex (#156479)
Summary: This was forbidden previously, which made us divergent with the GCC implementation. Permit this by simply removing this Sema check. Fixes: #156463
1 parent 96e4caa commit 62447ef

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5551,16 +5551,6 @@ bool Sema::BuiltinComplex(CallExpr *TheCall) {
55515551
<< Real->getSourceRange() << Imag->getSourceRange();
55525552
}
55535553

5554-
// We don't allow _Complex _Float16 nor _Complex __fp16 as type specifiers;
5555-
// don't allow this builtin to form those types either.
5556-
// FIXME: Should we allow these types?
5557-
if (Real->getType()->isFloat16Type())
5558-
return Diag(TheCall->getBeginLoc(), diag::err_invalid_complex_spec)
5559-
<< "_Float16";
5560-
if (Real->getType()->isHalfType())
5561-
return Diag(TheCall->getBeginLoc(), diag::err_invalid_complex_spec)
5562-
<< "half";
5563-
55645554
TheCall->setType(Context.getComplexType(Real->getType()));
55655555
return false;
55665556
}

clang/test/CodeGen/complex_Float16.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s
3+
4+
// CHECK-LABEL: define dso_local <2 x half> @builtin_complex(
5+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
6+
// CHECK-NEXT: [[ENTRY:.*:]]
7+
// CHECK-NEXT: [[RETVAL:%.*]] = alloca { half, half }, align 2
8+
// CHECK-NEXT: [[A:%.*]] = alloca half, align 2
9+
// CHECK-NEXT: store half 0xH0000, ptr [[A]], align 2
10+
// CHECK-NEXT: [[TMP0:%.*]] = load half, ptr [[A]], align 2
11+
// CHECK-NEXT: [[TMP1:%.*]] = load half, ptr [[A]], align 2
12+
// CHECK-NEXT: [[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { half, half }, ptr [[RETVAL]], i32 0, i32 0
13+
// CHECK-NEXT: [[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { half, half }, ptr [[RETVAL]], i32 0, i32 1
14+
// CHECK-NEXT: store half [[TMP0]], ptr [[RETVAL_REALP]], align 2
15+
// CHECK-NEXT: store half [[TMP1]], ptr [[RETVAL_IMAGP]], align 2
16+
// CHECK-NEXT: [[TMP2:%.*]] = load <2 x half>, ptr [[RETVAL]], align 2
17+
// CHECK-NEXT: ret <2 x half> [[TMP2]]
18+
//
19+
_Complex _Float16 builtin_complex(void) {
20+
_Float16 a = 0;
21+
return __builtin_complex(a, a);
22+
}

clang/test/Sema/Float16.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
_Float16 f;
1515

1616
#ifdef HAVE
17+
// expected-no-diagnostics
1718
_Complex _Float16 a;
1819
void builtin_complex(void) {
1920
_Float16 a = 0;
20-
(void)__builtin_complex(a, a); // expected-error {{'_Complex _Float16' is invalid}}
21+
(void)__builtin_complex(a, a);
2122
}
2223
#endif

clang/test/Sema/fp16-sema.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,3 @@ extern __fp16 *(*gf1) (void);
2828

2929
typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}}
3030
typedef __fp16 *(*tg1) (void);
31-
32-
void testComplex() {
33-
// FIXME: Should these be valid?
34-
_Complex __fp16 a; // expected-error {{'_Complex half' is invalid}}
35-
__fp16 b;
36-
a = __builtin_complex(b, b); // expected-error {{'_Complex half' is invalid}}
37-
}

clang/test/Sema/riscv-fp16.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,3 @@ extern __fp16 *(*gf1) (void);
2929

3030
typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}}
3131
typedef __fp16 *(*tg1) (void);
32-
33-
void testComplex() {
34-
// FIXME: Should these be valid?
35-
_Complex __fp16 a; // expected-error {{'_Complex half' is invalid}}
36-
__fp16 b;
37-
a = __builtin_complex(b, b); // expected-error {{'_Complex half' is invalid}}
38-
}

0 commit comments

Comments
 (0)