Clang crashes at this test case,
struct I;
int a = __has_trivial_destructor(I[]);
With this error,
clang-5.0: /llvm/tools/clang/include/clang/AST/DeclCXX.h:604: clang::CXXRecordDecl::DefinitionData& clang::CXXRecordDecl::data() const: Assertion `DD && "queried property of class with no definition"' failed.
#9 0xffffffffb737c7c7 clang::CXXRecordDecl::data() const /llvm/tools/clang/include/clang/AST/DeclCXX.h:605:0
#10 0xffffffffb737c877 clang::CXXRecordDecl::hasTrivialDestructor() const /llvm/tools/clang/include/clang/AST/DeclCXX.h:1293:0
#11 0x0a9d3ea2 EvaluateUnaryTypeTrait(clang::Sema&, clang::TypeTrait, clang::SourceLocation, clang::QualType) /llvm/tools/clang/lib/Sema/SemaExprCXX.cpp:4416:0
#12 0x0aa5e589 evaluateTypeTrait(clang::Sema&, clang::TypeTrait, clang::SourceLocation, llvm::ArrayRef<clang::TypeSourceInfo*>, clang::SourceLocation) /llvm/tools/clang/lib/Sema/SemaExprCXX.cpp:4560:0
Analysis:
According to the https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html, __has_trivial_destructor(type) requires type to be a complete type, (possibly cv-qualified) void, or an array of unknown bound.
When we pass an array of unknown bounds of an incomplete type, it crashes because clang is not able to get the DefinitionData of the type which is empty. But an if the type is array of unknown bounds but is complete type, then the DefinitionData is not empty, so there is no crash.
GCC handles this by giving an error if we pass an array of unknown bounds of an incomplete type. This patch is added to give a similar error when compiled with clang, as well.
Thanks,
Puneetha
Please move the UTT_Has* cases up here, since this is the rule that actually applies to them.