]> granicus.if.org Git - clang/commitdiff
Make type-traits reflect that Clang's vectors act like scalar types.
authorChandler Carruth <chandlerc@gmail.com>
Sat, 30 Apr 2011 10:46:26 +0000 (10:46 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 30 Apr 2011 10:46:26 +0000 (10:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130606 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Type.cpp
test/SemaCXX/literal-type.cpp
test/SemaCXX/type-traits.cpp

index ae52ff06faf7ebc3236ef84121a6b01af06a2f10..59cd5a3dc7cf4ee57cc4a821b64c4dd569b6a2f4 100644 (file)
@@ -891,7 +891,8 @@ bool Type::isLiteralType() const {
   // C++0x [basic.types]p10:
   //   A type is a literal type if it is:
   //    -- a scalar type; or
-  if (BaseTy->isScalarType()) return true;
+  // As an extension, Clang treats vector types as Scalar types.
+  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
   //    -- a reference type; or
   if (BaseTy->isReferenceType()) return true;
   //    -- a class type that has all of the following properties:
@@ -936,7 +937,8 @@ bool Type::isTrivialType() const {
   if (BaseTy->isIncompleteType())
     return false;
 
-  if (BaseTy->isScalarType()) return true;
+  // As an extension, Clang treats vector types as Scalar types.
+  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
   if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
     if (const CXXRecordDecl *ClassDecl =
         dyn_cast<CXXRecordDecl>(RT->getDecl())) {
@@ -970,7 +972,8 @@ bool Type::isStandardLayoutType() const {
   if (BaseTy->isIncompleteType())
     return false;
 
-  if (BaseTy->isScalarType()) return true;
+  // As an extension, Clang treats vector types as Scalar types.
+  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
   if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
     if (const CXXRecordDecl *ClassDecl =
         dyn_cast<CXXRecordDecl>(RT->getDecl()))
@@ -1005,7 +1008,8 @@ bool Type::isCXX11PODType() const {
   if (BaseTy->isIncompleteType())
     return false;
 
-  if (BaseTy->isScalarType()) return true;
+  // As an extension, Clang treats vector types as Scalar types.
+  if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
   if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
     if (const CXXRecordDecl *ClassDecl =
         dyn_cast<CXXRecordDecl>(RT->getDecl())) {
index 19f07d390b66796ba8c528230e5fc242ff91bd18..6a61823adb282af9f0096e88802e2bfcd31a2610 100644 (file)
@@ -8,6 +8,10 @@ static_assert(__is_literal(E), "fail");
 static_assert(__is_literal(decltype(E1)), "fail");
 typedef int IAR[10];
 static_assert(__is_literal(IAR), "fail");
+typedef int Vector __attribute__((vector_size(16)));
+typedef int VectorExt __attribute__((ext_vector_type(4)));
+static_assert(__is_literal(Vector), "fail");
+static_assert(__is_literal(VectorExt), "fail");
 
 // C++0x [basic.types]p10:
 //   A type is a literal type if it is:
index c45adecf66568cc1149cb368101ee1a932735318..a4ed500a804a7b09467eaf260331ec93d3371315 100644 (file)
@@ -27,6 +27,9 @@ struct HasAnonymousUnion {
   };
 };
 
+typedef int Vector __attribute__((vector_size(16)));
+typedef int VectorExt __attribute__((ext_vector_type(4)));
+
 // Not PODs
 typedef const void cvoid;
 struct Derives : POD {};
@@ -104,6 +107,8 @@ void is_pod()
   { int arr[T(__is_pod(HasAssign))]; }
   { int arr[T(__is_pod(IntArNB))]; }
   { int arr[T(__is_pod(HasAnonymousUnion))]; }
+  { int arr[T(__is_pod(Vector))]; }
+  { int arr[T(__is_pod(VectorExt))]; }
 
   { int arr[F(__is_pod(Derives))]; }
   { int arr[F(__is_pod(DerivesAr))]; }
@@ -942,6 +947,8 @@ void is_standard_layout()
   int t04[T(__is_standard_layout(CStruct))];
   int t05[T(__is_standard_layout(CppStructStandard))];
   int t06[T(__is_standard_layout(CppStructStandardAr))];
+  int t07[T(__is_standard_layout(Vector))];
+  int t08[T(__is_standard_layout(VectorExt))];
 
   typedef CppStructNonStandardByBase CppStructNonStandardByBaseAr[4];
 
@@ -1447,6 +1454,8 @@ void is_trivial()
   { int arr[T(__is_trivial(HasProt))]; }
   { int arr[T(__is_trivial(DerivesHasPriv))]; }
   { int arr[T(__is_trivial(DerivesHasProt))]; }
+  { int arr[T(__is_trivial(Vector))]; }
+  { int arr[T(__is_trivial(VectorExt))]; }
 
   { int arr[F(__is_trivial(HasCons))]; }
   { int arr[F(__is_trivial(HasCopyAssign))]; }