diff options
author | Karthik Bhat <kv.bhat@samsung.com> | 2017-06-28 08:52:08 +0000 |
---|---|---|
committer | Karthik Bhat <kv.bhat@samsung.com> | 2017-06-28 08:52:08 +0000 |
commit | e1ae1b23c99010db5fb27c00d80fed700a49160f (patch) | |
tree | 5893e7b715ca986f7680b53a176096686b2297fd /clang | |
parent | 002655df17a64a2e57601c7da0d92479d70d15f4 (diff) | |
download | bcm5719-llvm-e1ae1b23c99010db5fb27c00d80fed700a49160f.tar.gz bcm5719-llvm-e1ae1b23c99010db5fb27c00d80fed700a49160f.zip |
Fix crash in clang while handling __has_trivial_destructor.
Fix crash in clang when an array of unknown bounds of an incomplete type is passed to __has_trivial_destructor.
Patch by Puneetha
https://reviews.llvm.org/D34198
llvm-svn: 306519
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 20 | ||||
-rw-r--r-- | clang/test/SemaCXX/type-traits.cpp | 25 |
2 files changed, 34 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 710ead30790..71c4c8070e7 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -4093,15 +4093,9 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT, case UTT_IsStandardLayout: case UTT_IsPOD: case UTT_IsLiteral: - ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0); - LLVM_FALLTHROUGH; - - // C++1z [meta.unary.prop]: - // T shall be a complete type, cv void, or an array of unknown bound. - case UTT_IsDestructible: - case UTT_IsNothrowDestructible: - case UTT_IsTriviallyDestructible: - // Per the GCC type traits documentation, the same constraints apply to these. + // Per the GCC type traits documentation, T shall be a complete type, cv void, + // or an array of unknown bound. But GCC actually imposes the same constraints + // as above. case UTT_HasNothrowAssign: case UTT_HasNothrowMoveAssign: case UTT_HasNothrowConstructor: @@ -4113,6 +4107,14 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT, case UTT_HasTrivialCopy: case UTT_HasTrivialDestructor: case UTT_HasVirtualDestructor: + ArgTy = QualType(ArgTy->getBaseElementTypeUnsafe(), 0); + LLVM_FALLTHROUGH; + + // C++1z [meta.unary.prop]: + // T shall be a complete type, cv void, or an array of unknown bound. + case UTT_IsDestructible: + case UTT_IsNothrowDestructible: + case UTT_IsTriviallyDestructible: if (ArgTy->isIncompleteArrayType() || ArgTy->isVoidType()) return true; diff --git a/clang/test/SemaCXX/type-traits.cpp b/clang/test/SemaCXX/type-traits.cpp index 8a994f01ba1..5879a77dd5a 100644 --- a/clang/test/SemaCXX/type-traits.cpp +++ b/clang/test/SemaCXX/type-traits.cpp @@ -1447,7 +1447,9 @@ void has_trivial_default_constructor() { { int arr[T(__has_trivial_constructor(const Int))]; } { int arr[T(__has_trivial_constructor(AllDefaulted))]; } { int arr[T(__has_trivial_constructor(AllDeleted))]; } + { int arr[T(__has_trivial_constructor(ACompleteType[]))]; } + { int arr[F(__has_trivial_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_constructor(HasCons))]; } { int arr[F(__has_trivial_constructor(HasRef))]; } { int arr[F(__has_trivial_constructor(HasCopy))]; } @@ -1478,7 +1480,9 @@ void has_trivial_move_constructor() { { int arr[T(__has_trivial_move_constructor(HasCons))]; } { int arr[T(__has_trivial_move_constructor(HasStaticMemberMoveCtor))]; } { int arr[T(__has_trivial_move_constructor(AllDeleted))]; } - + { int arr[T(__has_trivial_move_constructor(ACompleteType[]))]; } + + { int arr[F(__has_trivial_move_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_move_constructor(HasVirt))]; } { int arr[F(__has_trivial_move_constructor(DerivesVirt))]; } { int arr[F(__has_trivial_move_constructor(HasMoveCtor))]; } @@ -1508,7 +1512,9 @@ void has_trivial_copy_constructor() { { int arr[T(__has_trivial_copy(AllDeleted))]; } { int arr[T(__has_trivial_copy(DerivesAr))]; } { int arr[T(__has_trivial_copy(DerivesHasRef))]; } + { int arr[T(__has_trivial_copy(ACompleteType[]))]; } + { int arr[F(__has_trivial_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_copy(HasCopy))]; } { int arr[F(__has_trivial_copy(HasTemplateCons))]; } { int arr[F(__has_trivial_copy(VirtAr))]; } @@ -1536,7 +1542,9 @@ void has_trivial_copy_assignment() { { int arr[T(__has_trivial_assign(AllDeleted))]; } { int arr[T(__has_trivial_assign(DerivesAr))]; } { int arr[T(__has_trivial_assign(DerivesHasRef))]; } + { int arr[T(__has_trivial_assign(ACompleteType[]))]; } + { int arr[F(__has_trivial_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_assign(IntRef))]; } { int arr[F(__has_trivial_assign(HasCopyAssign))]; } { int arr[F(__has_trivial_assign(const Int))]; } @@ -1572,8 +1580,10 @@ void has_trivial_destructor() { { int arr[T(__has_trivial_destructor(AllDefaulted))]; } { int arr[T(__has_trivial_destructor(AllDeleted))]; } { int arr[T(__has_trivial_destructor(DerivesHasRef))]; } + { int arr[T(__has_trivial_destructor(ACompleteType[]))]; } { int arr[F(__has_trivial_destructor(HasDest))]; } + { int arr[F(__has_trivial_destructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_destructor(void))]; } { int arr[F(__has_trivial_destructor(cvoid))]; } { int arr[F(__has_trivial_destructor(AllPrivate))]; } @@ -1625,7 +1635,9 @@ void has_nothrow_assign() { { int arr[T(__has_nothrow_assign(AllPrivate))]; } { int arr[T(__has_nothrow_assign(UsingAssign))]; } { int arr[T(__has_nothrow_assign(DerivesAr))]; } + { int arr[T(__has_nothrow_assign(ACompleteType[]))]; } + { int arr[F(__has_nothrow_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_assign(IntRef))]; } { int arr[F(__has_nothrow_assign(HasCopyAssign))]; } { int arr[F(__has_nothrow_assign(HasMultipleCopyAssign))]; } @@ -1650,8 +1662,9 @@ void has_nothrow_move_assign() { { int arr[T(__has_nothrow_move_assign(HasMemberNoThrowMoveAssign))]; } { int arr[T(__has_nothrow_move_assign(HasMemberNoExceptNoThrowMoveAssign))]; } { int arr[T(__has_nothrow_move_assign(AllDeleted))]; } + { int arr[T(__has_nothrow_move_assign(ACompleteType[]))]; } - + { int arr[F(__has_nothrow_move_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_move_assign(HasThrowMoveAssign))]; } { int arr[F(__has_nothrow_move_assign(HasNoExceptFalseMoveAssign))]; } { int arr[F(__has_nothrow_move_assign(HasMemberThrowMoveAssign))]; } @@ -1683,7 +1696,9 @@ void has_trivial_move_assign() { { int arr[T(__has_trivial_move_assign(Int))]; } { int arr[T(__has_trivial_move_assign(HasStaticMemberMoveAssign))]; } { int arr[T(__has_trivial_move_assign(AllDeleted))]; } + { int arr[T(__has_trivial_move_assign(ACompleteType[]))]; } + { int arr[F(__has_trivial_move_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_trivial_move_assign(HasVirt))]; } { int arr[F(__has_trivial_move_assign(DerivesVirt))]; } { int arr[F(__has_trivial_move_assign(HasMoveAssign))]; } @@ -1717,7 +1732,9 @@ void has_nothrow_copy() { { int arr[T(__has_nothrow_copy(HasTemplateCons))]; } { int arr[T(__has_nothrow_copy(AllPrivate))]; } { int arr[T(__has_nothrow_copy(DerivesAr))]; } + { int arr[T(__has_nothrow_copy(ACompleteType[]))]; } + { int arr[F(__has_nothrow_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_copy(HasCopy))]; } { int arr[F(__has_nothrow_copy(HasMultipleCopy))]; } { int arr[F(__has_nothrow_copy(VirtAr))]; } @@ -1743,7 +1760,9 @@ void has_nothrow_constructor() { { int arr[T(__has_nothrow_constructor(HasVirtDest))]; } // { int arr[T(__has_nothrow_constructor(VirtAr))]; } // not implemented { int arr[T(__has_nothrow_constructor(AllPrivate))]; } + { int arr[T(__has_nothrow_constructor(ACompleteType[]))]; } + { int arr[F(__has_nothrow_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[F(__has_nothrow_constructor(HasCons))]; } { int arr[F(__has_nothrow_constructor(HasRef))]; } { int arr[F(__has_nothrow_constructor(HasCopy))]; } @@ -1779,7 +1798,9 @@ void has_virtual_destructor() { { int arr[F(__has_virtual_destructor(HasMoveAssign))]; } { int arr[F(__has_virtual_destructor(IntRef))]; } { int arr[F(__has_virtual_destructor(VirtAr))]; } + { int arr[F(__has_virtual_destructor(ACompleteType[]))]; } + { int arr[F(__has_virtual_destructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}} { int arr[T(__has_virtual_destructor(HasVirtDest))]; } { int arr[T(__has_virtual_destructor(DerivedVirtDest))]; } { int arr[F(__has_virtual_destructor(VirtDestAr))]; } |