[PATCH] D61861: DeleteNullPointerCheck now deletes until the end brace of the condition
Jonathan Camilleri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 13:06:02 PDT 2019
J-Camilleri updated this revision to Diff 199315.
J-Camilleri added a comment.
Added a new unit test and restored the modified test as it was.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61861/new/
https://reviews.llvm.org/D61861
Files:
clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
clang-tools-extra/test/clang-tidy/readability-delete-null-pointer.cpp
Index: clang-tools-extra/test/clang-tidy/readability-delete-null-pointer.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/readability-delete-null-pointer.cpp
+++ clang-tools-extra/test/clang-tidy/readability-delete-null-pointer.cpp
@@ -3,6 +3,15 @@
#define NULL 0
void f() {
+ int *ps = 0;
+ if (ps /**/) // #0
+ delete ps;
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
+
+ // CHECK-FIXES: int *ps = 0;
+ // CHECK-FIXES-NEXT: {{^ }}// #0
+ // CHECK-FIXES-NEXT: delete ps;
+
int *p = 0;
// #1
Index: clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "DeleteNullPointerCheck.h"
+#include "../utils/LexerUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
@@ -62,9 +63,11 @@
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
IfWithDelete->getBeginLoc(),
- Lexer::getLocForEndOfToken(IfWithDelete->getCond()->getEndLoc(), 0,
- *Result.SourceManager,
- Result.Context->getLangOpts())));
+ utils::lexer::getPreviousToken(IfWithDelete->getThen()->getBeginLoc(),
+ *Result.SourceManager,
+ Result.Context->getLangOpts())
+ .getLocation()));
+
if (Compound) {
Diag << FixItHint::CreateRemoval(
CharSourceRange::getTokenRange(Compound->getLBracLoc()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61861.199315.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190513/271ae02e/attachment.bin>
More information about the cfe-commits
mailing list