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 | 2fb8b91f6f96363b87e9a501260343c664701ff4 (patch) | |
| tree | b4cf1e55ae72e8062c96673d456be3c7df9bb58f /clang/lib/Sema | |
| parent | 83320e03e6fdcbf2aff73f72c78edeffbbd878ef (diff) | |
| download | bcm5719-llvm-2fb8b91f6f96363b87e9a501260343c664701ff4.tar.gz bcm5719-llvm-2fb8b91f6f96363b87e9a501260343c664701ff4.zip | |
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.
llvm-svn: 145930
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index c90b7492a2f..cc8ec878ccb 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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; |

