From 25df423cfc6689cf21d51a66af84ea1e70d489df Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 30 Apr 2011 10:46:26 +0000 Subject: [PATCH] Make type-traits reflect that Clang's vectors act like scalar types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130606 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Type.cpp | 12 ++++++++---- test/SemaCXX/literal-type.cpp | 4 ++++ test/SemaCXX/type-traits.cpp | 9 +++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index ae52ff06fa..59cd5a3dc7 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -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()) { if (const CXXRecordDecl *ClassDecl = dyn_cast(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()) { if (const CXXRecordDecl *ClassDecl = dyn_cast(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()) { if (const CXXRecordDecl *ClassDecl = dyn_cast(RT->getDecl())) { diff --git a/test/SemaCXX/literal-type.cpp b/test/SemaCXX/literal-type.cpp index 19f07d390b..6a61823adb 100644 --- a/test/SemaCXX/literal-type.cpp +++ b/test/SemaCXX/literal-type.cpp @@ -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: diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index c45adecf66..a4ed500a80 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -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))]; } -- 2.40.0