Skip to content

Commit 5e5d901

Browse files
committed
[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
1 parent 0a89825 commit 5e5d901

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ Bug Fixes
359359

360360
Improvements to Clang's diagnostics
361361
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
362+
- Disabled FIT-IT suggested for a case of bad conversion in system headers.
362363
- Clang will now check compile-time determinable string literals as format strings.
363364
Fixes `Issue 55805: <https://github.com/llvm/llvm-project/issues/55805>`_.
364365
- ``-Wformat`` now recognizes ``%b`` for the ``printf``/``scanf`` family of

clang/lib/Sema/SemaOverload.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10917,10 +10917,13 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
1091710917
<< ToTy << (unsigned)isObjectArgument << I + 1
1091810918
<< (unsigned)(Cand->Fix.Kind);
1091910919

10920-
// If we can fix the conversion, suggest the FixIts.
10921-
for (std::vector<FixItHint>::iterator HI = Cand->Fix.Hints.begin(),
10922-
HE = Cand->Fix.Hints.end(); HI != HE; ++HI)
10923-
FDiag << *HI;
10920+
// Check that location of Fn is not in system header.
10921+
if (!S.SourceMgr.isInSystemHeader(Fn->getLocation())) {
10922+
// If we can fix the conversion, suggest the FixIts.
10923+
for (const FixItHint &HI : Cand->Fix.Hints)
10924+
FDiag << HI;
10925+
}
10926+
1092410927
S.Diag(Fn->getLocation(), FDiag);
1092510928

1092610929
MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);

clang/test/Index/fixit-sys-header.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma clang system_header
2+
3+
int func_in_sys_header(char * s, unsigned long len)
4+
{
5+
return 0;
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: c-index-test -test-load-source all %s 2>&1 | FileCheck %s
2+
3+
#include "fixit-sys-header.h"
4+
#include "fixit-user-header.h"
5+
6+
int main(int argc, char const *argv[])
7+
{
8+
char* str;{};
9+
10+
func_in_sys_header(str, str + 10);
11+
// CHECK: Number FIX-ITs = 0
12+
// CHECK-NEXT: candidate function not viable: no known conversion from 'char *' to 'unsigned long' for 2nd argument; dereference the argument with *
13+
// CHECK-NEXT: Number FIX-ITs = 0
14+
15+
func_in_user_header(str, str + 10);
16+
// CHECK: Number FIX-ITs = 0
17+
// CHECK-NEXT: candidate function not viable: no known conversion from 'char *' to 'unsigned long' for 2nd argument; dereference the argument with *
18+
// CHECK-NEXT: Number FIX-ITs = 2
19+
20+
return 0;
21+
}

clang/test/Index/fixit-user-header.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int func_in_user_header(char * s, unsigned long len)
2+
{
3+
return 0;
4+
}

0 commit comments

Comments
 (0)