[clang] a1a14e8 - [Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.
Cyndy Ishida via cfe-commits
cfe-commits at lists.llvm.org
Tue May 24 08:46:34 PDT 2022
Author: Cyndy Ishida
Date: 2022-05-24T08:43:31-07:00
New Revision: a1a14e817eeb5a0663b1342a125674348b8aac06
URL: https://github.com/llvm/llvm-project/commit/a1a14e817eeb5a0663b1342a125674348b8aac06
DIFF: https://github.com/llvm/llvm-project/commit/a1a14e817eeb5a0663b1342a125674348b8aac06.diff
LOG: [Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.
Clang has recently started diagnosing prototype redeclaration errors like [rG385e7df33046](https://reviews.llvm.org/rG385e7df33046d7292612ee1e3ac00a59d8bc0441)
This flagged legitimate issues in a codebase but was confusing to resolve because it actually conflicted with a function declaration from a system header and not from the one emitted with "note: ".
This patch updates the error handling to use the canonical declaration's source location instead to avoid misleading errors like the one described.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D126258
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 df3e8804c7d55..b150a88e0aa21 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3911,6 +3911,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
// ASTContext::typesAreCompatible().
if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn &&
Old->getNumParams() != New->getNumParams()) {
+ if (Old->hasInheritedPrototype())
+ Old = Old->getCanonicalDecl();
Diag(New->getLocation(), diag::err_conflicting_types) << New;
Diag(Old->getLocation(), PrevDiag) << Old << Old->getType();
return true;
diff --git a/clang/test/Sema/prototype-redecls.c b/clang/test/Sema/prototype-redecls.c
index ca3355f79d69a..ed569b5223ce2 100644
--- a/clang/test/Sema/prototype-redecls.c
+++ b/clang/test/Sema/prototype-redecls.c
@@ -12,6 +12,10 @@ void blarg() {} // expected-error {{conflicting types for 'blarg'}}
void blerp(short); // expected-note {{previous}}
void blerp(x) int x; {} // expected-error {{conflicting types for 'blerp'}}
+void foo(int); // expected-note {{previous}}
+void foo();
+void foo() {} // expected-error {{conflicting types for 'foo'}}
+
void glerp(int);
void glerp(x) short x; {} // Okay, promoted type is fine
More information about the cfe-commits
mailing list