Introduce -f{no-}spell-checking options to enable/disable
spell-checking. By default, spell-checking is enabled for Clang
(obviously) but disabled in CIndex for performance reasons.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107992 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index c4f3688..bbcceb7 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -102,6 +102,8 @@
unsigned InlineVisibilityHidden : 1; // Whether inline C++ methods have
// hidden visibility by default.
+ unsigned SpellChecking : 1; // Whether to perform spell-checking for error
+ // recovery.
// FIXME: This is just a temporary option, for testing purposes.
unsigned NoBitFieldTypeAlign : 1;
@@ -179,6 +181,7 @@
CatchUndefined = 0;
DumpRecordLayouts = 0;
DumpVTableLayouts = 0;
+ SpellChecking = 1;
NoBitFieldTypeAlign = 0;
}
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 51695a0..7076f30 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -411,6 +411,8 @@
HelpText<"Do not treat C++ operator name keywords as synonyms for operators">;
def fno_signed_char : Flag<"-fno-signed-char">,
HelpText<"Char is unsigned">;
+def fno_spell_checking : Flag<"-fno-spell-checking">,
+ HelpText<"Disable spell-checking">;
def fno_use_cxa_atexit : Flag<"-fno-use-cxa-atexit">,
HelpText<"Don't use __cxa_atexit for calling destructors">;
def fconstant_string_class : Separate<"-fconstant-string-class">,
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index b12f5be..96ec122 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -326,6 +326,7 @@
def fno_rtti : Flag<"-fno-rtti">, Group<f_Group>;
def fno_show_column : Flag<"-fno-show-column">, Group<f_Group>;
def fno_show_source_location : Flag<"-fno-show-source-location">, Group<f_Group>;
+def fno_spell_checking : Flag<"-fno-spell-checking">, Group<f_Group>;
def fno_stack_protector : Flag<"-fno-stack-protector">, Group<f_Group>;
def fno_strict_aliasing : Flag<"-fno-strict-aliasing">, Group<clang_ignored_f_Group>;
def fno_threadsafe_statics : Flag<"-fno-threadsafe-statics">, Group<f_Group>;
@@ -365,6 +366,7 @@
def fshort_wchar : Flag<"-fshort-wchar">, Group<f_Group>;
def fshow_overloads_EQ : Joined<"-fshow-overloads=">, Group<f_Group>;
def fshow_source_location : Flag<"-fshow-source-location">, Group<f_Group>;
+def fspell_checking : Flag<"-fspell-checking">, Group<f_Group>;
def fsigned_bitfields : Flag<"-fsigned-bitfields">, Group<f_Group>;
def fsigned_char : Flag<"-fsigned-char">, Group<f_Group>;
def fstack_protector_all : Flag<"-fstack-protector-all">, Group<f_Group>;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 296d541..9e03a18 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1401,6 +1401,10 @@
options::OPT_fno_show_source_location))
CmdArgs.push_back("-fno-show-source-location");
+ if (!Args.hasFlag(options::OPT_fspell_checking,
+ options::OPT_fno_spell_checking))
+ CmdArgs.push_back("-fno-spell-checking");
+
if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ))
A->render(Args, CmdArgs);
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 239283a..418d25b 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1321,6 +1321,7 @@
Opts.Static = Args.hasArg(OPT_static_define);
Opts.DumpRecordLayouts = Args.hasArg(OPT_fdump_record_layouts);
Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
+ Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking);
Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
Opts.OptimizeSize = 0;
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 6acfdb2..b452a0d 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -124,6 +124,7 @@
PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl);
PARSE_LANGOPT_BENIGN(CatchUndefined);
PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors);
+ PARSE_LANGOPT_BENIGN(SpellChecking);
#undef PARSE_LANGOPT_IMPORTANT
#undef PARSE_LANGOPT_BENIGN
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 18ceef9..47347ca 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -869,6 +869,7 @@
Record.push_back(LangOpts.OpenCL);
Record.push_back(LangOpts.CatchUndefined);
Record.push_back(LangOpts.ElideConstructors);
+ Record.push_back(LangOpts.SpellChecking);
Stream.EmitRecord(pch::LANGUAGE_OPTIONS, Record);
}
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index c11e3b3..2e65183 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -2726,7 +2726,7 @@
bool EnteringContext,
CorrectTypoContext CTC,
const ObjCObjectPointerType *OPT) {
- if (Diags.hasFatalErrorOccurred())
+ if (Diags.hasFatalErrorOccurred() || !getLangOptions().SpellChecking)
return DeclarationName();
// Provide a stop gap for files that are just seriously broken. Trying
diff --git a/test/FixIt/no-typo.c b/test/FixIt/no-typo.c
new file mode 100644
index 0000000..05947e8
--- /dev/null
+++ b/test/FixIt/no-typo.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -fno-spell-checking -verify %s
+typedef struct {
+ float x, y;
+} Point;
+
+point p1; // expected-error{{unknown type name 'point'}}
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index ce9357d..ee2e45f 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -1184,6 +1184,7 @@
// in the actual argument list.
if (source_filename)
Args.push_back(source_filename);
+ Args.push_back("-fno-spell-checking");
Args.insert(Args.end(), command_line_args,
command_line_args + num_command_line_args);
Args.push_back("-Xclang");
@@ -1247,6 +1248,7 @@
argv.push_back("-o");
char astTmpFile[L_tmpnam];
argv.push_back(tmpnam(astTmpFile));
+ argv.push_back("-fno-spell-checking");
// Remap any unsaved files to temporary files.
std::vector<llvm::sys::Path> TemporaryFiles;