aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-03-14 22:56:43 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-03-14 22:56:43 +0000
commit57f8da506a0db208a936e26a8cb77267f638b26b (patch)
treeaad09d1013d6f2f69af87e0bef0c48c058496d73
parent503836ae835fd27a4c1f1c1b6cbe72dfc5613976 (diff)
Don't try to typo-correct 'super' in an objc method.
This created 2 issues: 1) Performance issue, since typo-correction with PCH/modules is rather expensive. 2) Correctness issue, since if it managed to "correct" 'super' then bogus compiler errors would be emitted, like this: 3.m:8:3: error: unknown type name 'super'; did you mean 'super1'? super.x = 0; ^~~~~ super1 t3.m:5:13: note: 'super1' declared here typedef int super1; ^ t3.m:8:8: error: expected identifier or '(' super.x = 0; ^ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177126 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--include/clang/Sema/Sema.h4
-rw-r--r--lib/Sema/Sema.cpp8
-rw-r--r--lib/Sema/SemaCodeComplete.cpp2
-rw-r--r--lib/Sema/SemaLookup.cpp10
-rw-r--r--test/SemaObjC/typo-correction.m21
6 files changed, 45 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index bd3d1b4e10..470732ce68 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6074,6 +6074,8 @@ def warn_direct_ivar_access : Warning<"instance variable %0 is being "
"directly accessed">, InGroup<DiagGroup<"direct-ivar-access">>, DefaultIgnore;
// Spell-checking diagnostics
+def warn_spellcheck_initiated : Warning<"spell-checking initiated for %0">,
+ InGroup<DiagGroup<"spellcheck">>, DefaultIgnore;
def err_unknown_type_or_class_name_suggest : Error<
"unknown %select{type|class}2 name %0; did you mean %1?">;
def err_unknown_typename_suggest : Error<
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 5f4bb1d840..0f519398b7 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -7430,6 +7430,8 @@ private:
/// The parser maintains this state here.
Scope *CurScope;
+ mutable IdentifierInfo *Ident_super;
+
protected:
friend class Parser;
friend class InitializationSequence;
@@ -7447,6 +7449,8 @@ public:
/// template substitution or instantiation.
Scope *getCurScope() const { return CurScope; }
+ IdentifierInfo *getSuperIdentifier() const;
+
Decl *getObjCDeclContext() const;
DeclContext *getCurLexicalContext() const {
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 0ddd0619f9..4aeb511abd 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -90,7 +90,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
CurrentInstantiationScope(0), TyposCorrected(0),
- AnalysisWarnings(*this)
+ AnalysisWarnings(*this), Ident_super(0)
{
TUScope = 0;
@@ -1302,3 +1302,9 @@ bool Sema::tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD,
E = ExprError();
return true;
}
+
+IdentifierInfo *Sema::getSuperIdentifier() const {
+ if (!Ident_super)
+ Ident_super = &Context.Idents.get("super");
+ return Ident_super;
+}
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 78d8518b23..6bb954315a 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -5315,7 +5315,7 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
} else {
// "super" may be the name of a type or variable. Figure out which
// it is.
- IdentifierInfo *Super = &Context.Idents.get("super");
+ IdentifierInfo *Super = getSuperIdentifier();
NamedDecl *ND = LookupSingleName(S, Super, SuperLoc,
LookupOrdinaryName);
if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index eae6269ca6..86ddad21f5 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -3734,6 +3734,16 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
if (!ActiveTemplateInstantiations.empty())
return TypoCorrection();
+ // Don't try to correct 'super'.
+ if (S && S->isInObjcMethodScope() && Typo == getSuperIdentifier())
+ return TypoCorrection();
+
+ // This is for regression testing. It's disabled by default.
+ if (Diags.getDiagnosticLevel(diag::warn_spellcheck_initiated,
+ TypoName.getLoc()) != DiagnosticsEngine::Ignored)
+ Diag(TypoName.getLoc(), diag::warn_spellcheck_initiated)
+ << TypoName.getName();
+
NamespaceSpecifierSet Namespaces(Context, CurContext, SS);
TypoCorrectionConsumer Consumer(*this, Typo);
diff --git a/test/SemaObjC/typo-correction.m b/test/SemaObjC/typo-correction.m
new file mode 100644
index 0000000000..cb2c91bb76
--- /dev/null
+++ b/test/SemaObjC/typo-correction.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wspellcheck
+
+@interface B
+@property int x;
+@end
+
+@interface S : B
+@end
+
+// Spell-checking 'undefined' is ok.
+undefined var; // expected-warning {{spell-checking initiated}} \
+ // expected-error {{unknown type name}}
+
+typedef int super1;
+@implementation S
+-(void)foo {
+ // Spell-checking 'super' is not ok.
+ super.x = 0;
+ self.x = 0;
+}
+@end