diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 26a6b9b06e67f..077f4311ed729 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5551,16 +5551,6 @@ bool Sema::BuiltinComplex(CallExpr *TheCall) { << Real->getSourceRange() << Imag->getSourceRange(); } - // We don't allow _Complex _Float16 nor _Complex __fp16 as type specifiers; - // don't allow this builtin to form those types either. - // FIXME: Should we allow these types? - if (Real->getType()->isFloat16Type()) - return Diag(TheCall->getBeginLoc(), diag::err_invalid_complex_spec) - << "_Float16"; - if (Real->getType()->isHalfType()) - return Diag(TheCall->getBeginLoc(), diag::err_invalid_complex_spec) - << "half"; - TheCall->setType(Context.getComplexType(Real->getType())); return false; } diff --git a/clang/test/CodeGen/complex_Float16.c b/clang/test/CodeGen/complex_Float16.c new file mode 100644 index 0000000000000..d2552074bc7cd --- /dev/null +++ b/clang/test/CodeGen/complex_Float16.c @@ -0,0 +1,22 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s + +// CHECK-LABEL: define dso_local <2 x half> @builtin_complex( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[RETVAL:%.*]] = alloca { half, half }, align 2 +// CHECK-NEXT: [[A:%.*]] = alloca half, align 2 +// CHECK-NEXT: store half 0xH0000, ptr [[A]], align 2 +// CHECK-NEXT: [[TMP0:%.*]] = load half, ptr [[A]], align 2 +// CHECK-NEXT: [[TMP1:%.*]] = load half, ptr [[A]], align 2 +// CHECK-NEXT: [[RETVAL_REALP:%.*]] = getelementptr inbounds nuw { half, half }, ptr [[RETVAL]], i32 0, i32 0 +// CHECK-NEXT: [[RETVAL_IMAGP:%.*]] = getelementptr inbounds nuw { half, half }, ptr [[RETVAL]], i32 0, i32 1 +// CHECK-NEXT: store half [[TMP0]], ptr [[RETVAL_REALP]], align 2 +// CHECK-NEXT: store half [[TMP1]], ptr [[RETVAL_IMAGP]], align 2 +// CHECK-NEXT: [[TMP2:%.*]] = load <2 x half>, ptr [[RETVAL]], align 2 +// CHECK-NEXT: ret <2 x half> [[TMP2]] +// +_Complex _Float16 builtin_complex(void) { + _Float16 a = 0; + return __builtin_complex(a, a); +} diff --git a/clang/test/Sema/Float16.c b/clang/test/Sema/Float16.c index 2830213b6099f..b104cf907b3e9 100644 --- a/clang/test/Sema/Float16.c +++ b/clang/test/Sema/Float16.c @@ -14,9 +14,10 @@ _Float16 f; #ifdef HAVE +// expected-no-diagnostics _Complex _Float16 a; void builtin_complex(void) { _Float16 a = 0; - (void)__builtin_complex(a, a); // expected-error {{'_Complex _Float16' is invalid}} + (void)__builtin_complex(a, a); } #endif diff --git a/clang/test/Sema/fp16-sema.c b/clang/test/Sema/fp16-sema.c index f5406c519159d..493672791c54a 100644 --- a/clang/test/Sema/fp16-sema.c +++ b/clang/test/Sema/fp16-sema.c @@ -28,10 +28,3 @@ extern __fp16 *(*gf1) (void); typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}} typedef __fp16 *(*tg1) (void); - -void testComplex() { - // FIXME: Should these be valid? - _Complex __fp16 a; // expected-error {{'_Complex half' is invalid}} - __fp16 b; - a = __builtin_complex(b, b); // expected-error {{'_Complex half' is invalid}} -} diff --git a/clang/test/Sema/riscv-fp16.c b/clang/test/Sema/riscv-fp16.c index 7c39f9f9e7fbc..1e83ffe46ace1 100644 --- a/clang/test/Sema/riscv-fp16.c +++ b/clang/test/Sema/riscv-fp16.c @@ -29,10 +29,3 @@ extern __fp16 *(*gf1) (void); typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}} typedef __fp16 *(*tg1) (void); - -void testComplex() { - // FIXME: Should these be valid? - _Complex __fp16 a; // expected-error {{'_Complex half' is invalid}} - __fp16 b; - a = __builtin_complex(b, b); // expected-error {{'_Complex half' is invalid}} -}