From 1a998fa0b781ba575238b99359d1b848c7ef4ddd Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 24 Jan 2017 01:12:41 +0000 Subject: [PATCH] builtin-sprintf.c: Add test cases. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases. From-SVN: r244848 --- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf.c | 32 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c05ea54..8798d94 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-01-23 Martin Sebor + + * gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases. + 2017-01-23 Richard Biener PR tree-optimization/79088 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf.c index a3a467c..fd0f28f 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf.c @@ -773,6 +773,34 @@ test_s (int i) RNG ( 3, 6, 7, "%-s", i ? "123" : "123456"); } +static void __attribute__ ((noinline, noclone)) +test_n (void) +{ + int n; + EQL ( 0, 1, "%n", &n); + EQL ( 1, 2, "1%n", &n); + EQL ( 2, 3, "12%n", &n); + EQL ( 3, 4, "12%n3", &n); + EQL ( 4, 5, "12%n34", &n); + EQL ( 4, 5, "12%n34%n", &n, &n); + EQL ( 5, 6, "12%n34%n5", &n, &n); + EQL ( 6, 7, "12%n34%n56", &n, &n); + EQL ( 6, 7, "%s%n%s%n%s", "12", &n, "34", &n, "56"); +} + +static void __attribute__ ((noinline, noclone)) +test_percent (void) +{ + /* Provide extra arguments siunce the EQL macro needs at least one. */ + EQL ( 1, 2, "%%", 0); /* { dg-warning "too many arguments" } */ + EQL ( 2, 3, "%%%%", 0); /* { dg-warning "too many arguments" } */ + EQL ( 3, 4, "%%%%%%", 0); /* { dg-warning "too many arguments" } */ + EQL ( 3, 4, "%%%%%%%s", ""); + EQL ( 3, 4, "%%%%%s%%", ""); + EQL ( 3, 4, "%%%s%%%%", ""); + EQL ( 3, 4, "%s%%%%%%", ""); +} + int main (void) { test_c ('?'); @@ -791,6 +819,10 @@ int main (void) test_s (0); + test_n (); + + test_percent (); + if (nfails) { __builtin_printf ("%u out of %u tests failed\n", nfails, ntests); -- 2.7.4