fahadnayyar created this revision. Herald added a subscriber: arphaman. Herald added a project: All. fahadnayyar requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Disabled an invalid fix-it which suggested fixes to be applied in system headers for some programs in IDEs like Xcode. rdar://100890960 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D141868 Files: 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,15 @@ << 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 (rdar://100890960). + if (!S.SourceMgr.isInSystemHeader(Fn->getLocation())) { + // 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; + } + S.Diag(Fn->getLocation(), FDiag); MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
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,15 @@ << 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 (rdar://100890960). + if (!S.SourceMgr.isInSystemHeader(Fn->getLocation())) { + // 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; + } + S.Diag(Fn->getLocation(), FDiag); MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits