r264167 - ObjC: Handle boolean fixed type for enum.

Manman Ren via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 23 09:28:29 PDT 2016


Author: mren
Date: Wed Mar 23 11:28:28 2016
New Revision: 264167

URL: http://llvm.org/viewvc/llvm-project?rev=264167&view=rev
Log:
ObjC: Handle boolean fixed type for enum.

Before this commit, we assert failure in ImplicitCastExpr
"unheralded conversion to bool". This commit fixes the assertion by using
the correct cast type when the fixed type is boolean.

This commit also fixes the behavior for Microsoft mode as well, since
Obj-C and Microsoft mode share the same code path.

rdar://24999533

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaObjC/enum-fixed-type.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=264167&r1=264166&r2=264167&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 23 11:28:28 2016
@@ -14146,7 +14146,10 @@ EnumConstantDecl *Sema::CheckEnumConstan
             } else
               Diag(IdLoc, diag::err_enumerator_too_large) << EltTy;
           } else
-            Val = ImpCastExprToType(Val, EltTy, CK_IntegralCast).get();
+            Val = ImpCastExprToType(Val, EltTy,
+                                    EltTy->isBooleanType() ?
+                                    CK_IntegralToBoolean : CK_IntegralCast)
+                    .get();
         } else if (getLangOpts().CPlusPlus) {
           // C++11 [dcl.enum]p5:
           //   If the underlying type is not fixed, the type of each enumerator

Modified: cfe/trunk/test/SemaObjC/enum-fixed-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/enum-fixed-type.m?rev=264167&r1=264166&r2=264167&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/enum-fixed-type.m (original)
+++ cfe/trunk/test/SemaObjC/enum-fixed-type.m Wed Mar 23 11:28:28 2016
@@ -38,3 +38,8 @@ int arr3[(long long)Bar == (long long)-1
 
 typedef enum : Integer { BaseElem } BaseEnum;
 typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}}
+
+// <rdar://problem/24999533>
+enum MyEnum : _Bool {
+  MyThing = 0
+};




More information about the cfe-commits mailing list