[PATCH] D131499: Change prototype merging error into a warning for builtins

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 08:05:37 PDT 2022


aaron.ballman created this revision.
aaron.ballman added reviewers: efriedma, jyknight, clang-language-wg.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

As was observed in https://reviews.llvm.org/D123627#3707635, it's confusing that a user can write:

  float rintf(void) {}

and get a warning, but writing:

  float rintf() {}

gives an error. This patch changes the behavior so that both are warnings, so that users who have functions which conflict with a builtin identifier can still use that identifier as they wish.

Note, if we accept this, I would like to backport it to the Clang 15.x branch because the original change was made in Clang 15.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131499

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
@@ -29,7 +29,7 @@
 
 // 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'}} \
+float rintf() { // expected-warning {{incompatible redeclaration of library function 'rintf'}} \
                    expected-note {{'rintf' is a builtin with type 'float (float)'}}
   return 1.0f;
 }
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4042,7 +4042,7 @@
     // default argument promotion rules were already checked by
     // ASTContext::typesAreCompatible().
     if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn &&
-        Old->getNumParams() != New->getNumParams()) {
+        Old->getNumParams() != New->getNumParams() && !Old->isImplicit()) {
       if (Old->hasInheritedPrototype())
         Old = Old->getCanonicalDecl();
       Diag(New->getLocation(), diag::err_conflicting_types) << New;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131499.451155.patch
Type: text/x-patch
Size: 1278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220809/a511b3ec/attachment.bin>


More information about the cfe-commits mailing list