[PATCH] D49158: [clang-tidy] Fixing segfault when there's no IdentifierInfo
Julie Hockett via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 10 15:06:33 PDT 2018
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, hokein, ilya-biryukov.
juliehockett added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.
Bug 36150 found a segfault on mac when a CXXRecordDecl has no IdentifierInfo, this fixes it.
https://reviews.llvm.org/D49158
Files:
clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
Index: clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -30,21 +30,27 @@
// previously.
void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node,
bool isInterface) {
- StringRef Name = Node->getIdentifier()->getName();
- InterfaceMap.insert(std::make_pair(Name, isInterface));
+ if (const auto *Id = Node->getIdentifier()) {
+ StringRef Name = Id->getName();
+ InterfaceMap.insert(std::make_pair(Name, isInterface));
+ }
}
// Returns "true" if the boolean "isInterface" has been set to the
// interface status of the current Node. Return "false" if the
// interface status for the current node is not yet known.
bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node,
bool &isInterface) const {
- StringRef Name = Node->getIdentifier()->getName();
- llvm::StringMapConstIterator<bool> Pair = InterfaceMap.find(Name);
- if (Pair == InterfaceMap.end())
- return false;
- isInterface = Pair->second;
- return true;
+ if (!Node) return false;
+ if (const auto *Id = Node->getIdentifier()) {
+ StringRef Name = Id->getName();
+ llvm::StringMapConstIterator<bool> Pair = InterfaceMap.find(Name);
+ if (Pair == InterfaceMap.end())
+ return false;
+ isInterface = Pair->second;
+ return true;
+ }
+ return false;
}
bool MultipleInheritanceCheck::isCurrentClassInterface(
@@ -104,7 +110,7 @@
const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition());
if (!isInterface(Base)) NumConcrete++;
}
-
+
// Check virtual bases to see if there is more than one concrete
// non-virtual base.
for (const auto &V : D->vbases()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49158.154891.patch
Type: text/x-patch
Size: 1992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180710/40632720/attachment.bin>
More information about the cfe-commits
mailing list