Skip to content

Commit 1e25464

Browse files
committed
Make predefined FLT16 macros conditional on support for the type
We unconditionally predefine these macros. However, they may be used to determine if the type is supported. In that case, there are unnecessary failures to compile the code. This is the proposed fix for https://bugs.llvm.org/show_bug.cgi?id=40559 Differential revision: https://reviews.llvm.org/D57577 llvm-svn: 354512
1 parent 31823fb commit 1e25464

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
830830
DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
831831
DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
832832

833-
DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
833+
if (TI.hasFloat16Type())
834+
DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
834835
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
835836
DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
836837
DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");

clang/test/Headers/float16.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -ffreestanding %s
2-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s
3-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
4-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -x c++ -ffreestanding %s
1+
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify -std=c89 \
2+
// RUN: -ffreestanding %s
3+
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify \
4+
// RUN: -std=c99 -ffreestanding %s
5+
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify -std=c11 \
6+
// RUN: -ffreestanding %s
7+
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify \
8+
// RUN: -std=c++11 -x c++ -ffreestanding %s
59
// expected-no-diagnostics
610

711
#define __STDC_WANT_IEC_60559_TYPES_EXT__

clang/test/Preprocessor/init.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9166,20 +9166,20 @@
91669166
// WEBASSEMBLY-NOT:#define __ELF__
91679167
// WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
91689168
// WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
9169-
// WEBASSEMBLY-NEXT:#define __FLT16_DECIMAL_DIG__ 5
9170-
// WEBASSEMBLY-NEXT:#define __FLT16_DENORM_MIN__ 5.9604644775390625e-8F16
9171-
// WEBASSEMBLY-NEXT:#define __FLT16_DIG__ 3
9172-
// WEBASSEMBLY-NEXT:#define __FLT16_EPSILON__ 9.765625e-4F16
9173-
// WEBASSEMBLY-NEXT:#define __FLT16_HAS_DENORM__ 1
9174-
// WEBASSEMBLY-NEXT:#define __FLT16_HAS_INFINITY__ 1
9175-
// WEBASSEMBLY-NEXT:#define __FLT16_HAS_QUIET_NAN__ 1
9176-
// WEBASSEMBLY-NEXT:#define __FLT16_MANT_DIG__ 11
9177-
// WEBASSEMBLY-NEXT:#define __FLT16_MAX_10_EXP__ 4
9178-
// WEBASSEMBLY-NEXT:#define __FLT16_MAX_EXP__ 15
9179-
// WEBASSEMBLY-NEXT:#define __FLT16_MAX__ 6.5504e+4F16
9180-
// WEBASSEMBLY-NEXT:#define __FLT16_MIN_10_EXP__ (-13)
9181-
// WEBASSEMBLY-NEXT:#define __FLT16_MIN_EXP__ (-14)
9182-
// WEBASSEMBLY-NEXT:#define __FLT16_MIN__ 6.103515625e-5F16
9169+
// WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
9170+
// WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
9171+
// WEBASSEMBLY-NOT:#define __FLT16_DIG__
9172+
// WEBASSEMBLY-NOT:#define __FLT16_EPSILON__
9173+
// WEBASSEMBLY-NOT:#define __FLT16_HAS_DENORM__
9174+
// WEBASSEMBLY-NOT:#define __FLT16_HAS_INFINITY__
9175+
// WEBASSEMBLY-NOT:#define __FLT16_HAS_QUIET_NAN__
9176+
// WEBASSEMBLY-NOT:#define __FLT16_MANT_DIG__
9177+
// WEBASSEMBLY-NOT:#define __FLT16_MAX_10_EXP__
9178+
// WEBASSEMBLY-NOT:#define __FLT16_MAX_EXP__
9179+
// WEBASSEMBLY-NOT:#define __FLT16_MAX__
9180+
// WEBASSEMBLY-NOT:#define __FLT16_MIN_10_EXP__
9181+
// WEBASSEMBLY-NOT:#define __FLT16_MIN_EXP__
9182+
// WEBASSEMBLY-NOT:#define __FLT16_MIN__
91839183
// WEBASSEMBLY-NEXT:#define __FLT_DECIMAL_DIG__ 9
91849184
// WEBASSEMBLY-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F
91859185
// WEBASSEMBLY-NEXT:#define __FLT_DIG__ 6

0 commit comments

Comments
 (0)