Author: hokein Date: Wed Aug 28 06:45:53 2019 New Revision: 370200 URL: http://llvm.org/viewvc/llvm-project?rev=370200&view=rev Log: [clang-tidy] Fix the potential infinite loop in recordIsTriviallyDefaultConstructible.
Summary: The recordIsTriviallyDefaultConstructible may cause an infinite loop when running on an ill-formed decl. Reviewers: gribozavr Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66874 Added: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp Modified: clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp Modified: clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp?rev=370200&r1=370199&r2=370200&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/utils/TypeTraits.cpp Wed Aug 28 06:45:53 2019 @@ -54,6 +54,10 @@ bool recordIsTriviallyDefaultConstructib // Non-C++ records are always trivially constructible. if (!ClassDecl) return true; + // It is impossible to detemine whether an ill-formed decl is trivially + // constructible. + if (RecordDecl.isInvalidDecl()) + return false; // A class with a user-provided default constructor is not trivially // constructible. if (ClassDecl->hasUserProvidedDefaultConstructor()) Added: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp?rev=370200&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp (added) +++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp Wed Aug 28 06:45:53 2019 @@ -0,0 +1,7 @@ +// RUN: %check_clang_tidy -expect-clang-tidy-error %s cppcoreguidelines-pro-type-member-init %t + +struct X { + X x; + // CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'X' [clang-diagnostic-error] + int a = 10; +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits