[clang] 5e5d901 - [Clang] [Sema] Removed a fix-it for system headers
Fahad Nayyar via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 20 13:29:28 PST 2023
Author: Fahad Nayyar
Date: 2023-01-20T21:28:59Z
New Revision: 5e5d901feb3c4522c2b4d748bd52fda18abde821
URL: https://github.com/llvm/llvm-project/commit/5e5d901feb3c4522c2b4d748bd52fda18abde821
DIFF: https://github.com/llvm/llvm-project/commit/5e5d901feb3c4522c2b4d748bd52fda18abde821.diff
LOG: [Clang] [Sema] Removed a fix-it for system headers
Disabled an invalid fix-it which suggested fixes to be applied in system headers for some programs in IDEs like Xcode.
rdar://100890960
Differential Revision: https://reviews.llvm.org/D141868
Added:
clang/test/Index/fixit-sys-header.h
clang/test/Index/fixit-sysheader-test.cpp
clang/test/Index/fixit-user-header.h
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9f9fdc5a97a79..e996858c6830b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -359,6 +359,7 @@ Bug Fixes
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
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 89b5e29ffd614..d68337a26d975 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10917,10 +10917,13 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
<< 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);
diff --git a/clang/test/Index/fixit-sys-header.h b/clang/test/Index/fixit-sys-header.h
new file mode 100644
index 0000000000000..8d7066e767dd8
--- /dev/null
+++ b/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;
+}
diff --git a/clang/test/Index/fixit-sysheader-test.cpp b/clang/test/Index/fixit-sysheader-test.cpp
new file mode 100644
index 0000000000000..45fa5a90145cf
--- /dev/null
+++ b/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;
+}
diff --git a/clang/test/Index/fixit-user-header.h b/clang/test/Index/fixit-user-header.h
new file mode 100644
index 0000000000000..29a3ff2cd3b69
--- /dev/null
+++ b/clang/test/Index/fixit-user-header.h
@@ -0,0 +1,4 @@
+int func_in_user_header(char * s, unsigned long len)
+{
+ return 0;
+}
More information about the cfe-commits
mailing list