Author: Aaron Ballman Date: 2022-04-15T11:46:13-04:00 New Revision: c7d4a05228090cb6b1b7f6e5d300f197897ac756
URL: https://github.com/llvm/llvm-project/commit/c7d4a05228090cb6b1b7f6e5d300f197897ac756 DIFF: https://github.com/llvm/llvm-project/commit/c7d4a05228090cb6b1b7f6e5d300f197897ac756.diff LOG: Properly identify builtins in a diagnostic note When emitting a "conflicting types" warning for a function declaration, it's more clear to diagnose the previous declaration specifically as being a builtin if it one. Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/Sema/prototype-redecls.c Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0708e687c5752..76bf67397a6ee 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3256,6 +3256,10 @@ getNoteDiagForInvalidRedeclaration(const T *Old, const T *New) { PrevDiag = diag::note_previous_definition; else if (Old->isImplicit()) { PrevDiag = diag::note_previous_implicit_declaration; + if (const auto *FD = dyn_cast<FunctionDecl>(Old)) { + if (FD->getBuiltinID()) + PrevDiag = diag::note_previous_builtin_declaration; + } if (OldLocation.isInvalid()) OldLocation = New->getLocation(); } else diff --git a/clang/test/Sema/prototype-redecls.c b/clang/test/Sema/prototype-redecls.c index 9b85753cbbb5b..ca3355f79d69a 100644 --- a/clang/test/Sema/prototype-redecls.c +++ b/clang/test/Sema/prototype-redecls.c @@ -22,3 +22,10 @@ void derp(x) int x; {} void garp(int); void garp(); void garp(x) int x; {} + +// Ensure redeclarations that conflict with a builtin use a note which makes it +// clear that the previous declaration was a builtin. +float rintf() { // expected-error {{conflicting types for 'rintf'}} \ + expected-note {{'rintf' is a builtin with type 'float (float)'}} + return 1.0f; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits