forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR tree-optimization/86853 * gimple-ssa-sprintf.c (struct format_result): Rename member. (struct fmtresult): Add member and initialize it in ctors. (format_character): Handle %C. Extend range to NUL. Set MAYFAIL. (format_string): Handle %S the same as %ls. Set MAYFAIL. (format_directive): Set POSUNDER4K when MAYFAIL is set. (parse_directive): Handle %C same as %c. (sprintf_dom_walker::compute_format_length): Adjust. (is_call_safe): Adjust. gcc/testsuite/ChangeLog: PR tree-optimization/86853 * gcc.dg/tree-ssa/builtin-sprintf-10.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-11.c: New test. * gcc.dg/tree-ssa/builtin-sprintf-warn-18.c: Adjust. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263612 138bc75d-0d04-0410-961f-82ee72b054a4
- Loading branch information
law
committed
Aug 17, 2018
1 parent
10f417f
commit 17d7e9f
Showing
6 changed files
with
259 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* PR tree-optimization/86853 - sprintf optimization for wide strings | ||
doesn't account for conversion failure​ | ||
{ dg-do compile } | ||
{ dg-options "-O2 -Wall -fdump-tree-optimized" } */ | ||
|
||
typedef __SIZE_TYPE__ size_t; | ||
typedef __WCHAR_TYPE__ wchar_t; | ||
|
||
extern int snprintf (char*, size_t, const char*, ...); | ||
|
||
#define CONCAT(x, y) x ## y | ||
#define CAT(x, y) CONCAT (x, y) | ||
#define FAILNAME(name) CAT (call_ ## name ##_on_line_, __LINE__) | ||
|
||
#define FAIL(name) do { \ | ||
extern void FAILNAME (name) (void); \ | ||
FAILNAME (name)(); \ | ||
} while (0) | ||
|
||
/* Macro to emit a call to funcation named | ||
call_in_true_branch_not_eliminated_on_line_NNN() | ||
for each call that's expected to be eliminated. The dg-final | ||
scan-tree-dump-time directive at the bottom of the test verifies | ||
that no such call appears in output. */ | ||
#define ELIM(expr) \ | ||
if (!(expr)) FAIL (in_true_branch_not_eliminated); else (void)0 | ||
|
||
/* Macro to emit a call to a function named | ||
call_made_in_{true,false}_branch_on_line_NNN() | ||
for each call that's expected to be retained. The dg-final | ||
scan-tree-dump-time directive at the bottom of the test verifies | ||
that the expected number of both kinds of calls appears in output | ||
(a pair for each line with the invocation of the KEEP() macro. */ | ||
#define KEEP(expr) \ | ||
if (expr) \ | ||
FAIL (made_in_true_branch); \ | ||
else \ | ||
FAIL (made_in_false_branch) | ||
|
||
|
||
extern wchar_t wc; | ||
extern wchar_t ws[]; | ||
|
||
const wchar_t ws3[] = L"12\xff"; | ||
|
||
/* Verify that the following calls are eliminated. */ | ||
|
||
void elim_wide_char_call (void) | ||
{ | ||
ELIM (snprintf (0, 0, "%lc", L'\0')); | ||
ELIM (snprintf (0, 0, "%lc", L'1')); | ||
ELIM (snprintf (0, 0, "%lc", L'a')); | ||
ELIM (snprintf (0, 0, "%lc", ws3[0])); | ||
ELIM (snprintf (0, 0, "%lc", ws3[1])); | ||
ELIM (snprintf (0, 0, "%lc", ws3[3])); | ||
|
||
ELIM (snprintf (0, 0, "%C", L'\0')); | ||
ELIM (snprintf (0, 0, "%C", L'9')); | ||
ELIM (snprintf (0, 0, "%C", L'z')); | ||
ELIM (snprintf (0, 0, "%C", ws3[0])); | ||
ELIM (snprintf (0, 0, "%C", ws3[1])); | ||
ELIM (snprintf (0, 0, "%C", ws3[3])); | ||
|
||
/* Verify an unknown character value within the ASCII range. */ | ||
if (wc < 1 || 127 < wc) | ||
wc = 0; | ||
|
||
ELIM (snprintf (0, 0, "%C", wc)); | ||
ELIM (snprintf (0, 0, "%C", wc)); | ||
} | ||
|
||
void elim_wide_string_call (void) | ||
{ | ||
ELIM (snprintf (0, 0, "%ls", L"")); | ||
} | ||
|
||
|
||
#line 1000 | ||
|
||
/* Verify that the following calls are not eliminated. */ | ||
|
||
void keep_wide_char_call (void) | ||
{ | ||
KEEP (snprintf (0, 0, "%lc", L'\xff')); | ||
KEEP (snprintf (0, 0, "%lc", L'\xffff')); | ||
KEEP (snprintf (0, 0, "%lc", wc)); | ||
KEEP (snprintf (0, 0, "%lc", ws3[2])); | ||
|
||
KEEP (snprintf (0, 0, "%C", L'\xff')); | ||
KEEP (snprintf (0, 0, "%C", L'\xffff')); | ||
KEEP (snprintf (0, 0, "%C", wc)); | ||
KEEP (snprintf (0, 0, "%C", ws3[2])); | ||
|
||
/* Verify an unknown character value outside the ASCII range | ||
(with 128 being the only one). */ | ||
if (wc < 32 || 128 < wc) | ||
wc = 32; | ||
|
||
KEEP (snprintf (0, 0, "%lc", wc)); | ||
KEEP (snprintf (0, 0, "%C", wc)); | ||
} | ||
|
||
void keep_wide_string_call (void) | ||
{ | ||
KEEP (snprintf (0, 0, "%ls", L"\xff")); | ||
KEEP (snprintf (0, 0, "%ls", L"\xffff")); | ||
KEEP (snprintf (0, 0, "%ls", ws)); | ||
KEEP (snprintf (0, 0, "%ls", ws3)); | ||
|
||
KEEP (snprintf (0, 0, "%S", L"\xff")); | ||
KEEP (snprintf (0, 0, "%S", L"\xffff")); | ||
KEEP (snprintf (0, 0, "%S", ws)); | ||
KEEP (snprintf (0, 0, "%S", ws3)); | ||
} | ||
|
||
/* { dg-final { scan-tree-dump-times "call_made_in_true_branch_not_eliminated" 0 "optimized" } } | ||
{ dg-final { scan-tree-dump-times "call_made_in_true_branch_on_line_1\[0-9\]\[0-9\]\[0-9\]" 18 "optimized" } } | ||
{ dg-final { scan-tree-dump-times "call_made_in_false_branch_on_line_1\[0-9\]\[0-9\]\[0-9\]" 18 "optimized" } } */ |
Oops, something went wrong.