[clang] 49832b7 - Stop trying to fixup 'overloadable' prototypeless functions.

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 15 12:11:02 PDT 2022


Author: Erich Keane
Date: 2022-09-15T12:10:54-07:00
New Revision: 49832b7a928d4971417d8dba9aba932d62e447e3

URL: https://github.com/llvm/llvm-project/commit/49832b7a928d4971417d8dba9aba932d62e447e3
DIFF: https://github.com/llvm/llvm-project/commit/49832b7a928d4971417d8dba9aba932d62e447e3.diff

LOG: Stop trying to fixup 'overloadable' prototypeless functions.

While investigating something else, I discovered that a prototypeless
function with 'overloadable' was having the attribute left on the
declaration, which caused 'ambiguous' call errors later on. This lead to
some confusion.  This patch removes the 'overloadable' attribute from
the declaration and leaves it as prototypeless, instead of trying to
make it variadic.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaDecl.cpp
    clang/test/Sema/overloadable.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0680aa56db0b7..f897c68b2c87c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@ Bug Fixes
   `Issue 57169 <https://github.com/llvm/llvm-project/issues/57169>`_
 - Clang configuration files are now read through the virtual file system
   rather than the physical one, if these are 
diff erent.
+- Clang will now no longer treat a C 'overloadable' function without a prototype as
+  a variadic function with the attribute.  This should make further diagnostics more
+  clear.
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e4bd827b38d39..d1e1d8a523925 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10372,16 +10372,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
     Diag(NewFD->getLocation(),
          diag::err_attribute_overloadable_no_prototype)
       << NewFD;
-
-    // Turn this into a variadic function with no parameters.
-    const auto *FT = NewFD->getType()->castAs<FunctionType>();
-    FunctionProtoType::ExtProtoInfo EPI(
-        Context.getDefaultCallingConvention(true, false));
-    EPI.Variadic = true;
-    EPI.ExtInfo = FT->getExtInfo();
-
-    QualType R = Context.getFunctionType(FT->getReturnType(), None, EPI);
-    NewFD->setType(R);
+    NewFD->dropAttr<OverloadableAttr>();
   }
 
   // If there's a #pragma GCC visibility in scope, and this isn't a class

diff  --git a/clang/test/Sema/overloadable.c b/clang/test/Sema/overloadable.c
index ebd9ad1b6d2aa..42d04a52f8c7c 100644
--- a/clang/test/Sema/overloadable.c
+++ b/clang/test/Sema/overloadable.c
@@ -74,6 +74,16 @@ void test() {
   f1();
 }
 
+// Validate that the invalid function doesn't stay overloadable. 
+int __attribute__((overloadable)) invalid(); // expected-error{{'overloadable' function 'invalid' must have a prototype}}
+int __attribute__((overloadable)) invalid(int); // expected-error{{redeclaration of 'invalid' must not have the 'overloadable' attribute}}
+                                                // expected-note at -2{{previous unmarked overload of function is here}}
+void use_invalid(void) {
+  invalid(); // expected-error{{too few arguments to function call, expected 1, have 0}}
+             // expected-note at -4{{'invalid' declared here}}
+  invalid(1);
+}
+
 void before_local_1(int) __attribute__((overloadable));
 void before_local_2(int); // expected-note {{here}}
 void before_local_3(int) __attribute__((overloadable));


        


More information about the cfe-commits mailing list