[clang] 1534b04 - Fix caret position to be on the non null parameter

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 24 05:38:38 PDT 2022


Author: Arthur Grillo
Date: 2022-10-24T08:38:21-04:00
New Revision: 1534b048d6fdd7cf5f7dd5d3b8c6876b7cdad184

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

LOG: Fix caret position to be on the non null parameter

When checking for non null arguments the wrong SourceLocation was given,
this fix to pass the proper argument's location.

Fixes #58273

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

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaChecking.cpp
    clang/test/Sema/non-null-warning.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0dec5de56d38f..68cee534513a5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,9 @@ Improvements to Clang's diagnostics
   pointers is improved to include the type of the array and whether it's cast
   to another type. This should improve comprehension for why an index is
   out-of-bounds.
+- Clang now correctly point to the problematic parameter for the ``-Wnonnull``
+  warning.
+  This fixes `Issue 58273 <https://github.com/llvm/llvm-project/issues/58273>`_.
 
 Non-comprehensive list of changes in this release
 -------------------------------------------------

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0727433fbc43c..fe0d1af25b32c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5639,7 +5639,7 @@ static void CheckNonNullArguments(Sema &S,
   for (unsigned ArgIndex = 0, ArgIndexEnd = NonNullArgs.size();
        ArgIndex != ArgIndexEnd; ++ArgIndex) {
     if (NonNullArgs[ArgIndex])
-      CheckNonNullArgument(S, Args[ArgIndex], CallSiteLoc);
+      CheckNonNullArgument(S, Args[ArgIndex], Args[ArgIndex]->getExprLoc());
   }
 }
 

diff  --git a/clang/test/Sema/non-null-warning.c b/clang/test/Sema/non-null-warning.c
index 1e99dee25067e..d8369a5fee217 100644
--- a/clang/test/Sema/non-null-warning.c
+++ b/clang/test/Sema/non-null-warning.c
@@ -37,9 +37,16 @@ int * ret_nonnull(void) {
   return 0; // expected-warning {{null returned from function that requires a non-null return value}}
 }
 
+int foo4(int * _Nonnull x, int * y) {
+  return 0;
+}
+
 #define SAFE_CALL(X) if (X) foo(X)
 int main (void) {
   foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
   (void)sizeof(foo(0)); // expect no diagnostic in unevaluated context.
   SAFE_CALL(0); // expect no diagnostic for unreachable code.
+  foo4(
+       0, // expected-warning {{null passed to a callee that requires a non-null argument}}
+       0);
 }


        


More information about the cfe-commits mailing list