From ae66045705bf62ee881848b1bc9b28178b2176c8 Mon Sep 17 00:00:00 2001 From: Daniel Marjamaki Date: Mon, 21 Nov 2016 14:29:53 +0000 Subject: [PATCH] readability-redundant-declaration: Fix crash Differential Revision: https://reviews.llvm.org/D26911 llvm-svn: 287540 --- .../clang-tidy/readability/RedundantDeclarationCheck.cpp | 2 ++ .../test/clang-tidy/readability-redundant-declaration.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp index ea7d816..10ba122 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp @@ -28,6 +28,8 @@ void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) { const auto *Prev = D->getPreviousDecl(); if (!Prev) return; + if (!Prev->getLocation().isValid()) + return; if (Prev->getLocation() == D->getLocation()) return; diff --git a/clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp b/clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp index 7c58596..adb7c4d 100644 --- a/clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-redundant-declaration.cpp @@ -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__)); -- 2.7.4