[cfe-commits] r120345 - in /cfe/trunk: lib/AST/Type.cpp test/Sema/enum.c

Fariborz Jahanian fjahanian at apple.com
Mon Nov 29 15:18:10 PST 2010


Author: fjahanian
Date: Mon Nov 29 17:18:09 2010
New Revision: 120345

URL: http://llvm.org/viewvc/llvm-project?rev=120345&view=rev
Log:
Incomplete enum types not to be treated as integer type
when checking for integer signed/unsigned-ness. PR8694,
// rdar://8707031

Modified:
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/test/Sema/enum.c

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=120345&r1=120344&r2=120345&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Mon Nov 29 17:18:09 2010
@@ -489,8 +489,12 @@
            BT->getKind() <= BuiltinType::Int128;
   }
 
-  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
-    return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
+    // Incomplete enum types are not treated as integer types.
+    // FIXME: In C++, enum types are never integer types.
+    if (ET->getDecl()->isComplete())
+      return ET->getDecl()->getIntegerType()->isSignedIntegerType();
+  }
 
   return false;
 }
@@ -511,8 +515,12 @@
            BT->getKind() <= BuiltinType::UInt128;
   }
 
-  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
-    return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
+    // Incomplete enum types are not treated as integer types.
+    // FIXME: In C++, enum types are never integer types.
+    if (ET->getDecl()->isComplete())
+      return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
+  }
 
   return false;
 }

Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=120345&r1=120344&r2=120345&view=diff
==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Mon Nov 29 17:18:09 2010
@@ -104,3 +104,16 @@
 }
 
 char test5[__has_feature(enumerator_attributes) ? 1 : -1];
+
+// PR8694
+// rdar://8707031
+void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}}
+{
+}
+
+void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \
+                      // expected-warning {{ISO C forbids forward references to 'enum' types}}
+{
+        PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}}
+}
+





More information about the cfe-commits mailing list