[clang-tools-extra] r338124 - [clang-tidy] Fix a crash in fuchsia-multiple-inheritance

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 27 07:05:39 PDT 2018


Author: ibiryukov
Date: Fri Jul 27 07:05:39 2018
New Revision: 338124

URL: http://llvm.org/viewvc/llvm-project?rev=338124&view=rev
Log:
[clang-tidy] Fix a crash in fuchsia-multiple-inheritance

Summary: See the test case for a repro.

Reviewers: juliehockett, ioeric, hokein, aaron.ballman

Reviewed By: hokein

Subscribers: lebedev.ri, xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D49862

Modified:
    clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp?rev=338124&r1=338123&r2=338124&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp Fri Jul 27 07:05:39 2018
@@ -30,6 +30,7 @@ AST_MATCHER(CXXRecordDecl, hasBases) {
 // previously.
 void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node,
                                                      bool isInterface) {
+  assert(Node->getIdentifier());
   StringRef Name = Node->getIdentifier()->getName();
   InterfaceMap.insert(std::make_pair(Name, isInterface));
 }
@@ -39,6 +40,7 @@ void MultipleInheritanceCheck::addNodeTo
 // interface status for the current node is not yet known.
 bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node,
                                                   bool &isInterface) const {
+  assert(Node->getIdentifier());
   StringRef Name = Node->getIdentifier()->getName();
   llvm::StringMapConstIterator<bool> Pair = InterfaceMap.find(Name);
   if (Pair == InterfaceMap.end())
@@ -59,6 +61,9 @@ bool MultipleInheritanceCheck::isCurrent
 }
 
 bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) {
+  if (!Node->getIdentifier())
+    return false;
+
   // Short circuit the lookup if we have analyzed this record before.
   bool PreviousIsInterfaceResult;
   if (getInterfaceStatus(Node, PreviousIsInterfaceResult))

Modified: clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp?rev=338124&r1=338123&r2=338124&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp Fri Jul 27 07:05:39 2018
@@ -134,3 +134,14 @@ template<typename T> struct B : virtual
 
 template<typename> struct C {};
 template<typename T> struct D : C<T> {};
+
+// Check clang_tidy does not crash on this code.
+template <class T>
+struct WithTemplBase : T {
+  WithTemplBase();
+};
+
+int test_no_crash() {
+  auto foo = []() {};
+  WithTemplBase<decltype(foo)>();
+}




More information about the cfe-commits mailing list