r192334 - Fix getIntegerTypeOrder() to properly handle enums by first unwrapping their underlying integer type. This is a precondition for calling getIntegerRank().
Ted Kremenek
kremenek at apple.com
Wed Oct 9 17:54:01 PDT 2013
Author: kremenek
Date: Wed Oct 9 19:54:01 2013
New Revision: 192334
URL: http://llvm.org/viewvc/llvm-project?rev=192334&view=rev
Log:
Fix getIntegerTypeOrder() to properly handle enums by first unwrapping their underlying integer type. This is a precondition for calling getIntegerRank().
Fixes an assertion failure in a test case involving vectors.
Fixes <rdar://problem/15091442>
Please somebody check this.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/Sema/ext_vector_casts.c
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=192334&r1=192333&r2=192334&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Oct 9 19:54:01 2013
@@ -4417,12 +4417,27 @@ Qualifiers::ObjCLifetime ASTContext::get
return Qualifiers::OCL_None;
}
+static const Type *getIntegerTypeForEnum(const EnumType *ET) {
+ // Incomplete enum types are not treated as integer types.
+ // FIXME: In C++, enum types are never integer types.
+ if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
+ return ET->getDecl()->getIntegerType().getTypePtr();
+ return NULL;
+}
+
/// getIntegerTypeOrder - Returns the highest ranked integer type:
/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If
/// LHS < RHS, return -1.
int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const {
const Type *LHSC = getCanonicalType(LHS).getTypePtr();
const Type *RHSC = getCanonicalType(RHS).getTypePtr();
+
+ // Unwrap enums to their underlying type.
+ if (const EnumType *ET = dyn_cast<EnumType>(LHSC))
+ LHSC = getIntegerTypeForEnum(ET);
+ if (const EnumType *ET = dyn_cast<EnumType>(RHSC))
+ RHSC = getIntegerTypeForEnum(ET);
+
if (LHSC == RHSC) return 0;
bool LHSUnsigned = LHSC->isUnsignedIntegerType();
Modified: cfe/trunk/test/Sema/ext_vector_casts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ext_vector_casts.c?rev=192334&r1=192333&r2=192334&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ext_vector_casts.c (original)
+++ cfe/trunk/test/Sema/ext_vector_casts.c Wed Oct 9 19:54:01 2013
@@ -5,6 +5,9 @@ typedef __attribute__(( ext_vector_type(
typedef __attribute__(( ext_vector_type(8) )) short short8;
typedef __attribute__(( ext_vector_type(4) )) float float4;
typedef float t3 __attribute__ ((vector_size (16)));
+typedef __typeof__(sizeof(int)) size_t;
+typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
+typedef size_t stride4 __attribute__((ext_vector_type(4)));
static void test() {
float2 vec2;
@@ -50,3 +53,24 @@ void inc(float2 f2) {
f2++; // expected-error{{cannot increment value of type 'float2'}}
__real f2; // expected-error{{invalid type 'float2' to __real operator}}
}
+
+typedef enum
+{
+ uchar_stride = 1,
+ uchar4_stride = 4,
+ ushort4_stride = 8,
+ short4_stride = 8,
+ uint4_stride = 16,
+ int4_stride = 16,
+ float4_stride = 16,
+} PixelByteStride;
+
+stride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride);
+stride4 RDar15091442_get_stride4(int4 x, PixelByteStride pixelByteStride)
+{
+ stride4 stride;
+ // This previously caused an assertion failure.
+ stride.lo = ((ulong2) x) * pixelByteStride; // no-warning
+ return stride;
+}
+
More information about the cfe-commits
mailing list