[clang-tools-extra] b810244 - [clang-tidy] Avoid binding nullptr to a reference

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 21 06:56:42 PST 2022


Author: Benjamin Kramer
Date: 2022-01-21T15:55:17+01:00
New Revision: b8102449a72c5144cb75cfca46e78b517d7f6606

URL: https://github.com/llvm/llvm-project/commit/b8102449a72c5144cb75cfca46e78b517d7f6606
DIFF: https://github.com/llvm/llvm-project/commit/b8102449a72c5144cb75cfca46e78b517d7f6606.diff

LOG: [clang-tidy] Avoid binding nullptr to a reference

That's undefined behavior. Found by -fsanitize=null.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
index 0e91451211aed..6e7d28b2974f7 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -68,9 +68,9 @@ void MoveConstArgCheck::registerMatchers(MatchFinder *Finder) {
 }
 
 bool IsRValueReferenceParam(const Expr *Invocation,
-                            const QualType &InvocationParmType,
+                            const QualType *InvocationParmType,
                             const Expr *Arg) {
-  if (Invocation && InvocationParmType->isRValueReferenceType() &&
+  if (Invocation && (*InvocationParmType)->isRValueReferenceType() &&
       Arg->isLValue()) {
     if (!Invocation->getType()->isRecordType())
       return true;
@@ -138,7 +138,7 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) {
     // std::move shouldn't be removed when an lvalue wrapped by std::move is
     // passed to the function with an rvalue reference parameter.
     bool IsRVRefParam =
-        IsRValueReferenceParam(ReceivingExpr, *InvocationParmType, Arg);
+        IsRValueReferenceParam(ReceivingExpr, InvocationParmType, Arg);
     const auto *Var =
         IsVariable ? dyn_cast<DeclRefExpr>(Arg)->getDecl() : nullptr;
 


        


More information about the cfe-commits mailing list