[cfe-commits] r146153 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/c89.c test/Sema/implicit-decl.c
Douglas Gregor
dgregor at apple.com
Thu Dec 8 08:18:59 PST 2011
On Dec 8, 2011, at 7:56 AM, Hans Wennborg wrote:
> Author: hans
> Date: Thu Dec 8 09:56:07 2011
> New Revision: 146153
>
> URL: http://llvm.org/viewvc/llvm-project?rev=146153&view=rev
> Log:
> Only do typo correction for implicit function decls when
> they are treated as errors.
>
> Doing typo correction when these are just warnings slows down the
> compilation of source which deliberately uses implicit function
> declarations.
Thank you, Hans!
- Doug
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/c89.c
> cfe/trunk/test/Sema/implicit-decl.c
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=146153&r1=146152&r2=146153&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec 8 09:56:07 2011
> @@ -7259,36 +7259,36 @@
> 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.
> + unsigned diag_id;
> if (II.getName().startswith("__builtin_"))
> - Diag(Loc, diag::err_builtin_unknown) << &II;
> + diag_id = diag::err_builtin_unknown;
> else if (getLangOptions().C99)
> - Diag(Loc, diag::ext_implicit_function_decl) << &II;
> + diag_id = diag::ext_implicit_function_decl;
> else
> - Diag(Loc, diag::warn_implicit_function_decl) << &II;
> + diag_id = diag::warn_implicit_function_decl;
> + Diag(Loc, diag_id) << &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;
> + // Because typo correction is expensive, only do it if the implicit
> + // function declaration is going to be treated as an error.
> + if (Diags.getDiagnosticLevel(diag_id, Loc) >= DiagnosticsEngine::Error) {
> + TypoCorrection Corrected;
> + if (S && (Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc),
> + LookupOrdinaryName, S, 0))) {
> + NamedDecl *Decl = Corrected.getCorrectionDecl();
> + if (FunctionDecl *Func = dyn_cast_or_null<FunctionDecl>(Decl)) {
> + std::string CorrectedStr = Corrected.getAsString(getLangOptions());
> + std::string CorrectedQuotedStr = Corrected.getQuoted(getLangOptions());
> +
> + 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();
>
> Modified: cfe/trunk/test/Sema/c89.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89.c?rev=146153&r1=146152&r2=146153&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/c89.c (original)
> +++ cfe/trunk/test/Sema/c89.c Thu Dec 8 09:56:07 2011
> @@ -83,9 +83,9 @@
>
> int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
>
> -extern int printf(__const char *__restrict __format, ...); /* expected-note{{'printf' declared here}} */
> +extern int printf(__const char *__restrict __format, ...);
>
> +/* Warn, but don't suggest typo correction. */
> void test16() {
> - printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}}
> - expected-note {{did you mean 'printf'?}} */
> + printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
> }
>
> Modified: cfe/trunk/test/Sema/implicit-decl.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-decl.c?rev=146153&r1=146152&r2=146153&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/implicit-decl.c (original)
> +++ cfe/trunk/test/Sema/implicit-decl.c Thu Dec 8 09:56:07 2011
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 %s -verify -fsyntax-only
> +// RUN: %clang_cc1 %s -verify -fsyntax-only -Werror
>
> typedef int int32_t;
> typedef unsigned char Boolean;
> @@ -10,10 +10,10 @@
> const char compDesc[16 + 1];
> int32_t compCount = 0;
> if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-note {{previous implicit declaration is here}} \
> - expected-warning {{implicit declaration of function '_CFCalendarDecomposeAbsoluteTimeV' is invalid in C99}}
> + expected-error {{implicit declaration of function '_CFCalendarDecomposeAbsoluteTimeV' is invalid in C99}}
> }
>
> - printg("Hello, World!\n"); // expected-warning{{implicit declaration of function 'printg' is invalid in C99}} \
> + printg("Hello, World!\n"); // expected-error{{implicit declaration of function 'printg' is invalid in C99}} \
> // expected-note{{did you mean 'printf'?}}
>
> __builtin_is_les(1, 3); // expected-error{{use of unknown builtin '__builtin_is_les'}} \
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list