[PATCH] D66874: [clang-tidy] Fix the potential infinite loop in recordIsTriviallyDefaultConstructible.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 06:12:06 PDT 2019


hokein updated this revision to Diff 217617.
hokein removed a subscriber: wuzish.
hokein added a comment.

Add newline at end of tile.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66874/new/

https://reviews.llvm.org/D66874

Files:
  clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
  clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp


Index: clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init-no-crash.cpp
@@ -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;
+};
Index: clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
+++ clang-tools-extra/clang-tidy/utils/TypeTraits.cpp
@@ -54,6 +54,11 @@
   // Non-C++ records are always trivially constructible.
   if (!ClassDecl)
     return true;
+  // Don't perform the check on an ill-formed Decl. As we will visit every class
+  // member recursively, an ill-formed Decl may cause an infinite loop during
+  // the runtime.
+  if (RecordDecl.isInvalidDecl())
+    return false;
   // A class with a user-provided default constructor is not trivially
   // constructible.
   if (ClassDecl->hasUserProvidedDefaultConstructor())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66874.217617.patch
Type: text/x-patch
Size: 1248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190828/62e85adb/attachment-0001.bin>


More information about the cfe-commits mailing list