Skip to content

Commit

Permalink
Make predefined FLT16 macros conditional on support for the type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nemanjai committed Feb 20, 2019
1 parent 31823fb commit 1e25464
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
3 changes: 2 additions & 1 deletion clang/lib/Frontend/InitPreprocessor.cpp
Expand Up @@ -830,7 +830,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);

DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
if (TI.hasFloat16Type())
DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
Expand Down
12 changes: 8 additions & 4 deletions clang/test/Headers/float16.c
@@ -1,7 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -ffreestanding %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -x c++ -ffreestanding %s
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify -std=c89 \
// RUN: -ffreestanding %s
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify \
// RUN: -std=c99 -ffreestanding %s
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify -std=c11 \
// RUN: -ffreestanding %s
// RUN: %clang_cc1 -triple=aarch64-none-none -fsyntax-only -verify \
// RUN: -std=c++11 -x c++ -ffreestanding %s
// expected-no-diagnostics

#define __STDC_WANT_IEC_60559_TYPES_EXT__
Expand Down
28 changes: 14 additions & 14 deletions clang/test/Preprocessor/init.c
Expand Up @@ -9166,20 +9166,20 @@
// WEBASSEMBLY-NOT:#define __ELF__
// WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
// WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
// WEBASSEMBLY-NEXT:#define __FLT16_DECIMAL_DIG__ 5
// WEBASSEMBLY-NEXT:#define __FLT16_DENORM_MIN__ 5.9604644775390625e-8F16
// WEBASSEMBLY-NEXT:#define __FLT16_DIG__ 3
// WEBASSEMBLY-NEXT:#define __FLT16_EPSILON__ 9.765625e-4F16
// WEBASSEMBLY-NEXT:#define __FLT16_HAS_DENORM__ 1
// WEBASSEMBLY-NEXT:#define __FLT16_HAS_INFINITY__ 1
// WEBASSEMBLY-NEXT:#define __FLT16_HAS_QUIET_NAN__ 1
// WEBASSEMBLY-NEXT:#define __FLT16_MANT_DIG__ 11
// WEBASSEMBLY-NEXT:#define __FLT16_MAX_10_EXP__ 4
// WEBASSEMBLY-NEXT:#define __FLT16_MAX_EXP__ 15
// WEBASSEMBLY-NEXT:#define __FLT16_MAX__ 6.5504e+4F16
// WEBASSEMBLY-NEXT:#define __FLT16_MIN_10_EXP__ (-13)
// WEBASSEMBLY-NEXT:#define __FLT16_MIN_EXP__ (-14)
// WEBASSEMBLY-NEXT:#define __FLT16_MIN__ 6.103515625e-5F16
// WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
// WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
// WEBASSEMBLY-NOT:#define __FLT16_DIG__
// WEBASSEMBLY-NOT:#define __FLT16_EPSILON__
// WEBASSEMBLY-NOT:#define __FLT16_HAS_DENORM__
// WEBASSEMBLY-NOT:#define __FLT16_HAS_INFINITY__
// WEBASSEMBLY-NOT:#define __FLT16_HAS_QUIET_NAN__
// WEBASSEMBLY-NOT:#define __FLT16_MANT_DIG__
// WEBASSEMBLY-NOT:#define __FLT16_MAX_10_EXP__
// WEBASSEMBLY-NOT:#define __FLT16_MAX_EXP__
// WEBASSEMBLY-NOT:#define __FLT16_MAX__
// WEBASSEMBLY-NOT:#define __FLT16_MIN_10_EXP__
// WEBASSEMBLY-NOT:#define __FLT16_MIN_EXP__
// WEBASSEMBLY-NOT:#define __FLT16_MIN__
// WEBASSEMBLY-NEXT:#define __FLT_DECIMAL_DIG__ 9
// WEBASSEMBLY-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F
// WEBASSEMBLY-NEXT:#define __FLT_DIG__ 6
Expand Down

0 comments on commit 1e25464

Please sign in to comment.