diff mbox

Fix check for whether a function is a variadic function

Message ID 1429487100-12607-1-git-send-email-patrick@parcs.ath.cx
State New
Headers show

Commit Message

Patrick Palka April 19, 2015, 11:45 p.m. UTC
stdarg_p() apparently returns false for a variadic function that has no
concrete parameters, e.g. "void foo (...);".  This patch fixes this
issue by removing the predicate's seemingly bogus "n != NULL_TREE" test.

(Zero-parameter functions like "void bar (void);" will always have a
void_type_node sentinel in their fntype's argument list.)

OK to commit after testing?

gcc/ChangeLog:
	* tree.c (stdarg_p): Return true for variadic functions with no
	concrete parameters.

gcc/testsuite/ChangeLog:
	* g++.dg/variadic-main.C: New test.
---
 gcc/testsuite/g++.dg/variadic-main.C | 7 +++++++
 gcc/tree.c                           | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/variadic-main.C

Comments

Jason Merrill April 20, 2015, 3:17 a.m. UTC | #1
On 04/19/2015 07:45 PM, Patrick Palka wrote:
> stdarg_p() apparently returns false for a variadic function that has no
> concrete parameters, e.g. "void foo (...);".  This patch fixes this
> issue by removing the predicate's seemingly bogus "n != NULL_TREE" test.

What does this do with K&R non-prototype declarations, e.g. "int main();"?

Jason
Patrick Palka April 20, 2015, 1:02 p.m. UTC | #2
On Sun, Apr 19, 2015 at 11:17 PM, Jason Merrill <jason@redhat.com> wrote:
> On 04/19/2015 07:45 PM, Patrick Palka wrote:
>>
>> stdarg_p() apparently returns false for a variadic function that has no
>> concrete parameters, e.g. "void foo (...);".  This patch fixes this
>> issue by removing the predicate's seemingly bogus "n != NULL_TREE" test.
>
>
> What does this do with K&R non-prototype declarations, e.g. "int main();"?

stdarg_p (decl) now returns true when breaking on finish_decl() for
"int main();".  I'm not sure if that's right or not..

But never mind, I'm getting hundreds of failures from C tests that
define main without a parameter list e.g. "int main () { ... }".  This
is an issue not worth fixing..

>
> Jason
>
Jason Merrill April 20, 2015, 2:29 p.m. UTC | #3
On 04/20/2015 09:02 AM, Patrick Palka wrote:
> But never mind, I'm getting hundreds of failures from C tests that
> define main without a parameter list e.g. "int main () { ... }".  This
> is an issue not worth fixing..

Yep, that's what I was wondering.  I think it makes sense to fix this 
testcase in the C++ front end rather than in code shared between front ends.

Jason
diff mbox

Patch

diff --git a/gcc/testsuite/g++.dg/variadic-main.C b/gcc/testsuite/g++.dg/variadic-main.C
new file mode 100644
index 0000000..b262bfd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/variadic-main.C
@@ -0,0 +1,7 @@ 
+/* { dg-options "-Wpedantic" } */
+
+int
+main (...) /* { dg-warning "declared as variadic function" } */
+{
+  return 0;
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 01860af..d388a1c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -11518,7 +11518,7 @@  stdarg_p (const_tree fntype)
       n = t;
     }
 
-  return n != NULL_TREE && n != void_type_node;
+  return n != void_type_node;
 }
 
 /* Return true if TYPE has a prototype.  */