diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 3c9078bcdf811..55590ab76dbc1 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type ----------------------------------------- Clang provides support for C++11 enumerations with a fixed underlying type -within Objective-C. For example, one can write an enumeration type as: +within Objective-C and C `prior to C23 `_. For example, one can write an enumeration type as: .. code-block:: c++ @@ -1996,7 +1996,13 @@ This specifies that the underlying type, which is used to store the enumeration value, is ``unsigned char``. Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed -underlying types is available in Objective-C. +underlying types is available in Objective-C + +Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed +underlying types is available in C prior to C23 + +Use ``__has_feature(c_fixed_enum)`` to determine whether support for fixed +underlying types is available in C23 and later Interoperability with C++11 lambdas ----------------------------------- diff --git a/clang/include/clang/Basic/Features.def b/clang/include/clang/Basic/Features.def index 9088c867d53ce..15c59c6bcdf29 100644 --- a/clang/include/clang/Basic/Features.def +++ b/clang/include/clang/Basic/Features.def @@ -163,6 +163,8 @@ FEATURE(c_atomic, LangOpts.C11) FEATURE(c_generic_selections, LangOpts.C11) FEATURE(c_static_assert, LangOpts.C11) FEATURE(c_thread_local, LangOpts.C11 &&PP.getTargetInfo().isTLSSupported()) +// C23 features +FEATURE(c_fixed_enum, LangOpts.C23) // C++11 features FEATURE(cxx_access_control_sfinae, LangOpts.CPlusPlus11) FEATURE(cxx_alias_templates, LangOpts.CPlusPlus11) @@ -269,6 +271,7 @@ EXTENSION(c_static_assert, true) EXTENSION(c_thread_local, PP.getTargetInfo().isTLSSupported()) // C23 features supported by other languages as extensions EXTENSION(c_attributes, true) +EXTENSION(c_fixed_enum, true) // C++11 features supported by other languages as extensions. EXTENSION(cxx_atomic, LangOpts.CPlusPlus) EXTENSION(cxx_default_function_template_args, LangOpts.CPlusPlus) diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c index 4f6d04ba7f918..f12ce61ac13a6 100644 --- a/clang/test/Sema/enum.c +++ b/clang/test/Sema/enum.c @@ -121,6 +121,17 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1]; enum Color { Red, Green, Blue }; // expected-note{{previous use is here}} typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}} +// Enumerations with a fixed underlying type. +// https://github.com/llvm/llvm-project/issues/116880 +#if __STDC_VERSION__ >= 202311L + static_assert(__has_feature(c_fixed_enum)); + static_assert(__has_extension(c_fixed_enum)); // Matches behavior for c_alignas, etc +#else + _Static_assert(__has_extension(c_fixed_enum), ""); + _Static_assert(!__has_feature(c_fixed_enum), ""); +#endif +typedef enum : unsigned char { Pink, Black, Cyan } Color; // pre-c23-warning {{enumeration types with a fixed underlying type are a C23 extension}} + // PR28903 // In C it is valid to define tags inside enums. struct PR28903 { diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 8fbab337cab6f..105cfe51ec156 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -8404,6 +8404,17 @@ bool TargetLowering::expandUINT_TO_FP(SDNode *Node, SDValue &Result, EVT SrcVT = Src.getValueType(); EVT DstVT = Node->getValueType(0); + if (DstVT == MVT::bf16) { + SDLoc Loc(Node); + SDValue Operand = Node->getOperand(0); + + Result = DAG.getNode( + ISD::FP_ROUND, Loc, MVT::bf16, + DAG.getNode(ISD::UINT_TO_FP, Loc, MVT::f32, Operand), + DAG.getIntPtrConstant(0, Loc)); + return true; + } + // If the input is known to be non-negative and SINT_TO_FP is legal then use // it. if (Node->getFlags().hasNonNeg() &&