[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

Youngsuk Kim via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 05:31:01 PDT 2024


================
@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
 
   NamedDecl *ChosenDecl =
       Correction.isKeyword() ? nullptr : Correction.getFoundDecl();
+
+  // For builtin functions which aren't declared anywhere in source,
+  // don't emit the "declared here" note.
+  if (const auto *FD = dyn_cast_if_present<FunctionDecl>(ChosenDecl);
+      FD && FD->getBuiltinID() &&
+      PrevNote.getDiagID() == diag::note_previous_decl &&
+      Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {
----------------
JOE1994 wrote:

This location checking was motivated by test failure of `Clang :: Sema/implicit-decl.c`.

https://github.com/llvm/llvm-project/blob/8760d4ba4cb12d5cac2469f26cd09a2b3acd3c50/clang/test/Sema/implicit-decl.c#L13

I added this check to let Clang emit a **"declared here"** note for a "builtin" function (one with non-zero BuiltinID) that has an explicit declaration.

https://github.com/llvm/llvm-project/pull/93394


More information about the cfe-commits mailing list