[PATCH] D126258: [Clang] Avoid misleading 'conflicting types' diagnostic with no-prototype decls.
Cyndy Ishida via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 23 17:39:58 PDT 2022
cishida updated this revision to Diff 431543.
cishida added a comment.
Restrict using the canonical decl's source location to only when the prototype was inferred from previously seen decl.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126258/new/
https://reviews.llvm.org/D126258
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/prototype-redecls.c
Index: clang/test/Sema/prototype-redecls.c
===================================================================
--- clang/test/Sema/prototype-redecls.c
+++ clang/test/Sema/prototype-redecls.c
@@ -12,6 +12,10 @@
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
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3911,6 +3911,8 @@
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126258.431543.patch
Type: text/x-patch
Size: 1152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220524/c6d6d9e1/attachment.bin>
More information about the cfe-commits
mailing list