[PATCH] D141868: [Clang] [Sema] Removed a fix-it for system headers

Fahad Nayyar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 19 11:39:36 PST 2023


fahadnayyar updated this revision to Diff 490618.
fahadnayyar added a comment.

Added release notes and changed a normal for-loop to range-based for-loop.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141868/new/

https://reviews.llvm.org/D141868

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaOverload.cpp
  clang/test/Index/fixit-sys-header.h
  clang/test/Index/fixit-sysheader-test.cpp
  clang/test/Index/fixit-user-header.h


Index: clang/test/Index/fixit-user-header.h
===================================================================
--- /dev/null
+++ clang/test/Index/fixit-user-header.h
@@ -0,0 +1,4 @@
+int func_in_user_header(char * s, unsigned long len)
+{
+    return 0;
+}
Index: clang/test/Index/fixit-sysheader-test.cpp
===================================================================
--- /dev/null
+++ clang/test/Index/fixit-sysheader-test.cpp
@@ -0,0 +1,21 @@
+// RUN: c-index-test -test-load-source all %s 2>&1 | FileCheck %s
+
+#include "fixit-sys-header.h"
+#include "fixit-user-header.h"
+
+int main(int argc, char const *argv[])
+{
+    char* str;{};
+    
+    func_in_sys_header(str, str + 10);
+    // CHECK: Number FIX-ITs = 0
+    // CHECK-NEXT: candidate function not viable: no known conversion from 'char *' to 'unsigned long' for 2nd argument; dereference the argument with *
+    // CHECK-NEXT: Number FIX-ITs = 0
+    
+    func_in_user_header(str, str + 10);
+    // CHECK: Number FIX-ITs = 0
+    // CHECK-NEXT: candidate function not viable: no known conversion from 'char *' to 'unsigned long' for 2nd argument; dereference the argument with *
+    // CHECK-NEXT: Number FIX-ITs = 2
+
+    return 0;
+}
Index: clang/test/Index/fixit-sys-header.h
===================================================================
--- /dev/null
+++ clang/test/Index/fixit-sys-header.h
@@ -0,0 +1,6 @@
+#pragma clang system_header
+
+int func_in_sys_header(char * s, unsigned long len)
+{
+    return 0;
+}
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10917,10 +10917,13 @@
         << ToTy << (unsigned)isObjectArgument << I + 1
         << (unsigned)(Cand->Fix.Kind);
 
-  // If we can fix the conversion, suggest the FixIts.
-  for (std::vector<FixItHint>::iterator HI = Cand->Fix.Hints.begin(),
-       HE = Cand->Fix.Hints.end(); HI != HE; ++HI)
-    FDiag << *HI;
+  // Check that location of Fn is not in system header.
+  if (!S.SourceMgr.isInSystemHeader(Fn->getLocation())) {
+    // If we can fix the conversion, suggest the FixIts.
+    for (const FixItHint &HI : Cand->Fix.Hints)
+        FDiag << HI;
+  }
+
   S.Diag(Fn->getLocation(), FDiag);
 
   MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -353,6 +353,7 @@
 
 Improvements to Clang's diagnostics
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Disabled FIT-IT suggested for a case of bad conversion in system headers.
 - Clang will now check compile-time determinable string literals as format strings.
   Fixes `Issue 55805: <https://github.com/llvm/llvm-project/issues/55805>`_.
 - ``-Wformat`` now recognizes ``%b`` for the ``printf``/``scanf`` family of


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141868.490618.patch
Type: text/x-patch
Size: 2931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230119/e7c71256/attachment.bin>


More information about the cfe-commits mailing list