Author: hokein Date: Tue May 28 04:54:01 2019 New Revision: 361809 URL: http://llvm.org/viewvc/llvm-project?rev=361809&view=rev Log: [clang-tidy] Fix null pointer dereference in readability-identifier-naming
Summary: readability-identifier-naming causes a null pointer dereference when checking an identifier introduced by a structured binding whose right hand side is an undeclared identifier. Running the check on a file that is just the following results in a crash: ``` auto [left] = right; ``` Patch by Mark Stegeman! Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: hokein, aaron.ballman Subscribers: madsravn, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D62404 Added: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-bugfix.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=361809&r1=361808&r2=361809&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp Tue May 28 04:54:01 2019 @@ -800,10 +800,11 @@ void IdentifierNamingCheck::check(const // Fix type aliases in value declarations if (const auto *Value = Result.Nodes.getNodeAs<ValueDecl>("decl")) { - if (const auto *Typedef = - Value->getType().getTypePtr()->getAs<TypedefType>()) { - addUsage(NamingCheckFailures, Typedef->getDecl(), - Value->getSourceRange()); + if (const auto *TypePtr = Value->getType().getTypePtrOrNull()) { + if (const auto *Typedef = TypePtr->getAs<TypedefType>()) { + addUsage(NamingCheckFailures, Typedef->getDecl(), + Value->getSourceRange()); + } } } Added: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-bugfix.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-bugfix.cpp?rev=361809&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-bugfix.cpp (added) +++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-bugfix.cpp Tue May 28 04:54:01 2019 @@ -0,0 +1,5 @@ +// RUN: %check_clang_tidy -expect-clang-tidy-error %s readability-identifier-naming %t + +// This used to cause a null pointer dereference. +auto [left] = right; +// CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'right' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits