[clang-tools-extra] r176551 - Fixed Use-Nullptr when replacing return(0)

Edwin Vane edwin.vane at intel.com
Wed Mar 6 06:51:34 PST 2013


Author: revane
Date: Wed Mar  6 08:51:34 2013
New Revision: 176551

URL: http://llvm.org/viewvc/llvm-project?rev=176551&view=rev
Log:
Fixed Use-Nullptr when replacing return(0)

Before fix, the paren expression was being replaced resulting in returnnullptr.
ParenExpr and implicit casts now ignored so we get return(nullptr) instead.

Added new test cases.

Fixes PR15398

Author: Ariel Bernal <ariel.j.bernal at intel.com>

Modified:
    clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
    clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp

Modified: clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp?rev=176551&r1=176550&r2=176551&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.cpp Wed Mar  6 08:51:34 2013
@@ -110,8 +110,10 @@ void NullptrFixer::run(const ast_matcher
 
   const CastExpr *Cast = Result.Nodes.getNodeAs<CastExpr>(ImplicitCastNode);
   if (Cast) {
-    SourceLocation StartLoc = Cast->getLocStart();
-    SourceLocation EndLoc = Cast->getLocEnd();
+    const Expr *E = Cast->IgnoreParenImpCasts();
+
+    SourceLocation StartLoc = E->getLocStart();
+    SourceLocation EndLoc = E->getLocEnd();
 
     // If the start/end location is a macro, get the expansion location.
     StartLoc = SM.getFileLoc(StartLoc);

Modified: clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp?rev=176551&r1=176550&r2=176551&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/UseNullptr/basic.cpp Wed Mar  6 08:51:34 2013
@@ -204,3 +204,34 @@ void test_function_like_macro2() {
   // CHECK: my_macro(p != nullptr);
 #undef my_macro
 }
+
+// Test parentheses expressions resulting in a nullptr.
+int *test_parentheses_expression1() {
+  return(0);
+  // CHECK: return(nullptr);
+}
+
+int *test_parentheses_expression2() {
+  return(int(0.f));
+  // CHECK: return(nullptr);
+}
+
+int *test_nested_parentheses_expression() {
+  return((((0))));
+  // CHECK: return((((nullptr))));
+}
+
+void *test_parentheses_explicit_cast() {
+  return(static_cast<void*>(0));
+  // CHECK: return(nullptr);
+}
+
+void *test_parentheses_explicit_cast_sequence1() {
+  return(static_cast<void*>(static_cast<int*>((void*)NULL)));
+  // CHECK: return(nullptr);
+}
+
+void *test_parentheses_explicit_cast_sequence2() {
+  return(static_cast<void*>(reinterpret_cast<int*>((float*)int(0.f))));
+  // CHECK: return(nullptr);
+}





More information about the cfe-commits mailing list