diff options
author | Hans Wennborg <hans@hanshq.net> | 2011-12-06 09:46:12 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2011-12-06 09:46:12 +0000 |
commit | 122de3e131a6902d22c97471520ec9005cca6f03 (patch) | |
tree | e7a6ee7ebd0d081839ec5a5d20dfb1dce33217af /lib/Sema/SemaDecl.cpp | |
parent | d64251fd56577dd5c78903454632361e094c6dc1 (diff) |
Suggest typo corrections for implicit function declarations.
A mistyped function call becomes an inmplicit function declaration in C.
Suggest typo correction when one can be found.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c90b7492a2..cc8ec878cc 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7262,14 +7262,38 @@ NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, return Pos->second; } + // See if we can find a typo correction. + TypoCorrection Corrected; + FunctionDecl *Func = 0; + std::string CorrectedStr; + std::string CorrectedQuotedStr; + if (S && (Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc), + LookupOrdinaryName, S, 0))) { + // Since this is an implicit function declaration, we are only + // interested in a potential typo for a function name. + if ((Func = dyn_cast_or_null<FunctionDecl>( + Corrected.getCorrectionDecl()))) { + CorrectedStr = Corrected.getAsString(getLangOptions()); + CorrectedQuotedStr = Corrected.getQuoted(getLangOptions()); + } + } + // Extension in C99. Legal in C90, but warn about it. if (II.getName().startswith("__builtin_")) - Diag(Loc, diag::warn_builtin_unknown) << &II; + Diag(Loc, diag::err_builtin_unknown) << &II; else if (getLangOptions().C99) Diag(Loc, diag::ext_implicit_function_decl) << &II; else Diag(Loc, diag::warn_implicit_function_decl) << &II; + if (Func) { + // If we found a typo correction, then suggest that. + Diag(Loc, diag::note_function_suggestion) << CorrectedQuotedStr + << FixItHint::CreateReplacement(Loc, CorrectedStr); + if (Func->getLocation().isValid() && !II.getName().startswith("__builtin_")) + Diag(Func->getLocation(), diag::note_previous_decl) << CorrectedQuotedStr; + } + // Set a Declarator for the implicit definition: int foo(); const char *Dummy; AttributeFactory attrFactory; |