[clang-tools-extra] r287540 - readability-redundant-declaration: Fix crash

Daniel Marjamaki via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 21 06:29:53 PST 2016


Author: danielmarjamaki
Date: Mon Nov 21 08:29:53 2016
New Revision: 287540

URL: http://llvm.org/viewvc/llvm-project?rev=287540&view=rev
Log:
readability-redundant-declaration: Fix crash

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


Modified:
    clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp?rev=287540&r1=287539&r2=287540&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantDeclarationCheck.cpp Mon Nov 21 08:29:53 2016
@@ -28,6 +28,8 @@ void RedundantDeclarationCheck::check(co
   const auto *Prev = D->getPreviousDecl();
   if (!Prev)
     return;
+  if (!Prev->getLocation().isValid())
+    return;
   if (Prev->getLocation() == D->getLocation())
     return;
 

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp?rev=287540&r1=287539&r2=287540&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-redundant-declaration.cpp Mon Nov 21 08:29:53 2016
@@ -21,3 +21,10 @@ static int f();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration
 // CHECK-FIXES: {{^}}{{$}}
 static int f() {}
+
+// Original check crashed for the code below.
+namespace std {
+  typedef long unsigned int size_t;
+}
+void* operator new(std::size_t) __attribute__((__externally_visible__));
+void* operator new[](std::size_t) __attribute__((__externally_visible__));




More information about the cfe-commits mailing list