PR c/43673 - Incorrect warning in dfp printf.

Message ID 1551143599-26436-1-git-send-email-luoxhu@linux.ibm.com
State New
Headers show
Series
  • PR c/43673 - Incorrect warning in dfp printf.
Related show

Commit Message

luoxhu Feb. 26, 2019, 1:13 a.m.
From: Xiong Hu Luo <luoxhu@linux.vnet.ibm.com>


dfp printf/scanf of Ha/HA, Da/DA and DDa/DDA is not set properly, cause
incorrect warning happens:
"use of 'D' length modifier with 'a' type character".

Regression-tested on powerpc64le-linux, OK for trunk and gcc-8?

gcc/c-family/ChangeLog:

2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

	PR c/43673
	* c-format.c (print_char_table, scanf_char_table): Replace BADLEN with
	TEX_D32, TEX_D64 or TEX_D128.

gcc/testsuit/ChangeLog:

2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

	PR c/43673
	* gcc.dg/format-dfp-printf-1.c: New test.
	* gcc.dg/format-dfp-scanf-1.c: Likewise.
---
 gcc/c-family/c-format.c                    |  4 ++--
 gcc/testsuite/gcc.dg/format/dfp-printf-1.c | 28 ++++++++++++++++++++++++++--
 gcc/testsuite/gcc.dg/format/dfp-scanf-1.c  | 22 ++++++++++++++++++++--
 3 files changed, 48 insertions(+), 6 deletions(-)

-- 
2.7.4

Comments

luoxhu March 4, 2019, 1:13 a.m. | #1
Ping:
https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01949.html

Thanks
Xionghu

On 2019/2/26 AM9:13, luoxhu@linux.ibm.com wrote:
> From: Xiong Hu Luo <luoxhu@linux.vnet.ibm.com>

> 

> dfp printf/scanf of Ha/HA, Da/DA and DDa/DDA is not set properly, cause

> incorrect warning happens:

> "use of 'D' length modifier with 'a' type character".

> 

> Regression-tested on powerpc64le-linux, OK for trunk and gcc-8?

> 

> gcc/c-family/ChangeLog:

> 

> 2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

> 

> 	PR c/43673

> 	* c-format.c (print_char_table, scanf_char_table): Replace BADLEN with

> 	TEX_D32, TEX_D64 or TEX_D128.

> 

> gcc/testsuit/ChangeLog:

> 

> 2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

> 

> 	PR c/43673

> 	* gcc.dg/format-dfp-printf-1.c: New test.

> 	* gcc.dg/format-dfp-scanf-1.c: Likewise.

> ---

>  gcc/c-family/c-format.c                    |  4 ++--

>  gcc/testsuite/gcc.dg/format/dfp-printf-1.c | 28 ++++++++++++++++++++++++++--

>  gcc/testsuite/gcc.dg/format/dfp-scanf-1.c  | 22 ++++++++++++++++++++--

>  3 files changed, 48 insertions(+), 6 deletions(-)

> 

> diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c

> index 9b48ee3..af33ef9 100644

> --- a/gcc/c-family/c-format.c

> +++ b/gcc/c-family/c-format.c

> @@ -674,7 +674,7 @@ static const format_char_info print_char_table[] =

>    { "n",   1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",          "W",  NULL },

>    /* C99 conversion specifiers.  */

>    { "F",   0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64, TEX_D128 }, "-wp0 +#'I", "",   NULL },

> -  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp0 +#",   "",   NULL },

> +  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64,  TEX_D128 }, "-wp0 +#",   "",   NULL },

>    /* X/Open conversion specifiers.  */

>    { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },

>    { "S",   1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "R",  NULL },

> @@ -847,7 +847,7 @@ static const format_char_info scan_char_table[] =

>    { "n",     1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",     "W",   NULL },

>    /* C99 conversion specifiers.  */

>    { "F",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64, TEX_D128 }, "*w'",  "W",   NULL },

> -  { "aA",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w'",  "W",   NULL },

> +  { "aA",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32,  TEX_D64,  TEX_D128 }, "*w'",  "W",   NULL },

>    /* X/Open conversion specifiers.  */

>    { "C",     1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*mw",   "W",   NULL },

>    { "S",     1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*amw",  "W",   NULL },

> diff --git a/gcc/testsuite/gcc.dg/format/dfp-printf-1.c b/gcc/testsuite/gcc.dg/format/dfp-printf-1.c

> index e92f161..a290895 100644

> --- a/gcc/testsuite/gcc.dg/format/dfp-printf-1.c

> +++ b/gcc/testsuite/gcc.dg/format/dfp-printf-1.c

> @@ -17,6 +17,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>  

>    /* Check lack of warnings for valid usage.  */

>  

> +  printf ("%Ha\n", x);

> +  printf ("%HA\n", x);

>    printf ("%Hf\n", x);

>    printf ("%HF\n", x);

>    printf ("%He\n", x);

> @@ -24,6 +26,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%Hg\n", x);

>    printf ("%HG\n", x);

>  

> +  printf ("%Da\n", y);

> +  printf ("%DA\n", y);

>    printf ("%Df\n", y);

>    printf ("%DF\n", y);

>    printf ("%De\n", y);

> @@ -31,6 +35,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%Dg\n", y);

>    printf ("%DG\n", y);

>  

> +  printf ("%DDa\n", z);

> +  printf ("%DDA\n", z);

>    printf ("%DDf\n", z);

>    printf ("%DDF\n", z);

>    printf ("%DDe\n", z);

> @@ -43,12 +49,16 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>  

>    /* Check warnings for type mismatches.  */

>  

> +  printf ("%Ha\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  printf ("%HA\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%Hf\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%HF\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%He\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%HE\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%Hg\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%HG\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  printf ("%Ha\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  printf ("%HA\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%Hf\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%HF\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%He\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

> @@ -56,12 +66,16 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%Hg\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%HG\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>  

> +  printf ("%Da\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

> +  printf ("%DA\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%Df\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%DF\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%De\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%DE\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%Dg\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%DG\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

> +  printf ("%Da\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

> +  printf ("%DA\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%Df\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%DF\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%De\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

> @@ -69,12 +83,16 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%Dg\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    printf ("%DG\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>  

> +  printf ("%DDa\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

> +  printf ("%DDA\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDf\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDF\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDe\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDE\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDg\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDG\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

> +  printf ("%DDa\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

> +  printf ("%DDA\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDf\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDF\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    printf ("%DDe\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

> @@ -90,8 +108,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%Hu\n", j);	/* { dg-warning "length" "bad use of %H" } */

>    printf ("%Hx\n", j);	/* { dg-warning "length" "bad use of %H" } */

>    printf ("%HX\n", j);	/* { dg-warning "length" "bad use of %H" } */

> -  printf ("%Ha\n", d);	/* { dg-warning "length" "bad use of %H" } */

> -  printf ("%HA\n", d);	/* { dg-warning "length" "bad use of %H" } */

> +  printf ("%Ha\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  printf ("%HA\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

>    printf ("%Hc\n", i);	/* { dg-warning "length" "bad use of %H" } */

>    printf ("%Hs\n", p);	/* { dg-warning "length" "bad use of %H" } */

>    printf ("%Hp\n", p);	/* { dg-warning "length" "bad use of %H" } */

> @@ -100,6 +118,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    /* Sanity checks for flags, field width, and precision in formats for

>       DFP types.  */

>  

> +  printf ("%-Ha\n", x);

> +  printf ("%+HA\n", x);

>    printf ("%-Hf\n", x);

>    printf ("%+HF\n", x);

>    printf ("% He\n", x);

> @@ -107,6 +127,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%0Hg\n", x);

>    printf ("%#0HG\n", x);

>  

> +  printf ("%0#Da\n", y);

> +  printf ("%0DA\n", y);

>    printf ("%0#Df\n", y);

>    printf ("%0DF\n", y);

>    printf ("%#De\n", y);

> @@ -114,6 +136,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>    printf ("%-#0Dg\n", y);  /* { dg-warning "flag ignored" "ignore flag" } */

>    printf ("%0+ DG\n", y);  /* { dg-warning "flag ignored" "ignore flag" } */

>  

> +  printf ("%DDa\n", z);

> +  printf ("%0DDA\n", z);

>    printf ("%DDf\n", z);

>    printf ("%0DDF\n", z);

>    printf ("%#0DDe\n", z);

> diff --git a/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c b/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c

> index ffa12a8..6df3bc6 100644

> --- a/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c

> +++ b/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c

> @@ -17,6 +17,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>  

>    /* Check lack of warnings for valid usage.  */

>  

> +  scanf ("%Ha", x);

> +  scanf ("%HA", x);

>    scanf ("%Hf", x);

>    scanf ("%HF", x);

>    scanf ("%He", x);

> @@ -24,6 +26,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>    scanf ("%Hg", x);

>    scanf ("%HG", x);

>  

> +  scanf ("%Da", y);

> +  scanf ("%DA", y);

>    scanf ("%Df", y);

>    scanf ("%DF", y);

>    scanf ("%De", y);

> @@ -31,6 +35,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>    scanf ("%Dg", y);

>    scanf ("%DG", y);

>  

> +  scanf ("%DDa", z);

> +  scanf ("%DDA", z);

>    scanf ("%DDf", z);

>    scanf ("%DDF", z);

>    scanf ("%DDe", z);

> @@ -43,12 +49,16 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>  

>    /* Check warnings for type mismatches.  */

>  

> +  scanf ("%Ha", y);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  scanf ("%HA", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%Hf", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%HF", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%He", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%HE", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%Hg", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%HG", y);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  scanf ("%Ha", z);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  scanf ("%HA", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%Hf", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%HF", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%He", z);	/* { dg-warning "expects argument" "bad use of %H" } */

> @@ -56,12 +66,16 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>    scanf ("%Hg", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%HG", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>  

> +  scanf ("%Da", x);	/* { dg-warning "expects argument" "bad use of %D" } */

> +  scanf ("%DA", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%Df", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%DF", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%De", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%DE", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%Dg", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%DG", x);	/* { dg-warning "expects argument" "bad use of %D" } */

> +  scanf ("%Da", z);	/* { dg-warning "expects argument" "bad use of %D" } */

> +  scanf ("%DA", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%Df", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%DF", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%De", z);	/* { dg-warning "expects argument" "bad use of %D" } */

> @@ -69,12 +83,16 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>    scanf ("%Dg", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>    scanf ("%DG", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>  

> +  scanf ("%DDa", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

> +  scanf ("%DDA", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDf", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDF", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDe", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDE", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDg", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDG", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

> +  scanf ("%DDa", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

> +  scanf ("%DDA", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDf", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDF", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>    scanf ("%DDe", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

> @@ -90,8 +108,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>    scanf ("%Hu\n", j);	/* { dg-warning "length" "bad use of %H" } */

>    scanf ("%Hx\n", j);	/* { dg-warning "length" "bad use of %H" } */

>    scanf ("%HX\n", j);	/* { dg-warning "length" "bad use of %H" } */

> -  scanf ("%Ha\n", d);	/* { dg-warning "length" "bad use of %H" } */

> -  scanf ("%HA\n", d);	/* { dg-warning "length" "bad use of %H" } */

> +  scanf ("%Ha\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

> +  scanf ("%HA\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

>    scanf ("%Hc\n", i);	/* { dg-warning "length" "bad use of %H" } */

>    scanf ("%Hs\n", p);	/* { dg-warning "length" "bad use of %H" } */

>    scanf ("%Hp\n", p);	/* { dg-warning "length" "bad use of %H" } */

>
luoxhu May 21, 2019, 12:56 a.m. | #2
Ping for GCC-10.


Thanks

Xionghu

On 2019/3/4 09:13, Xiong Hu Luo wrote:
> Ping:

> https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01949.html

>

> Thanks

> Xionghu

>

> On 2019/2/26 AM9:13, luoxhu@linux.ibm.com wrote:

>> From: Xiong Hu Luo <luoxhu@linux.vnet.ibm.com>

>>

>> dfp printf/scanf of Ha/HA, Da/DA and DDa/DDA is not set properly, cause

>> incorrect warning happens:

>> "use of 'D' length modifier with 'a' type character".

>>

>> Regression-tested on powerpc64le-linux, OK for trunk and gcc-8?

>>

>> gcc/c-family/ChangeLog:

>>

>> 2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

>>

>> 	PR c/43673

>> 	* c-format.c (print_char_table, scanf_char_table): Replace BADLEN with

>> 	TEX_D32, TEX_D64 or TEX_D128.

>>

>> gcc/testsuit/ChangeLog:

>>

>> 2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

>>

>> 	PR c/43673

>> 	* gcc.dg/format-dfp-printf-1.c: New test.

>> 	* gcc.dg/format-dfp-scanf-1.c: Likewise.

>> ---

>>   gcc/c-family/c-format.c                    |  4 ++--

>>   gcc/testsuite/gcc.dg/format/dfp-printf-1.c | 28 ++++++++++++++++++++++++++--

>>   gcc/testsuite/gcc.dg/format/dfp-scanf-1.c  | 22 ++++++++++++++++++++--

>>   3 files changed, 48 insertions(+), 6 deletions(-)

>>

>> diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c

>> index 9b48ee3..af33ef9 100644

>> --- a/gcc/c-family/c-format.c

>> +++ b/gcc/c-family/c-format.c

>> @@ -674,7 +674,7 @@ static const format_char_info print_char_table[] =

>>     { "n",   1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",          "W",  NULL },

>>     /* C99 conversion specifiers.  */

>>     { "F",   0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64, TEX_D128 }, "-wp0 +#'I", "",   NULL },

>> -  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp0 +#",   "",   NULL },

>> +  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64,  TEX_D128 }, "-wp0 +#",   "",   NULL },

>>     /* X/Open conversion specifiers.  */

>>     { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },

>>     { "S",   1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "R",  NULL },

>> @@ -847,7 +847,7 @@ static const format_char_info scan_char_table[] =

>>     { "n",     1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",     "W",   NULL },

>>     /* C99 conversion specifiers.  */

>>     { "F",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64, TEX_D128 }, "*w'",  "W",   NULL },

>> -  { "aA",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w'",  "W",   NULL },

>> +  { "aA",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32,  TEX_D64,  TEX_D128 }, "*w'",  "W",   NULL },

>>     /* X/Open conversion specifiers.  */

>>     { "C",     1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*mw",   "W",   NULL },

>>     { "S",     1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*amw",  "W",   NULL },

>> diff --git a/gcc/testsuite/gcc.dg/format/dfp-printf-1.c b/gcc/testsuite/gcc.dg/format/dfp-printf-1.c

>> index e92f161..a290895 100644

>> --- a/gcc/testsuite/gcc.dg/format/dfp-printf-1.c

>> +++ b/gcc/testsuite/gcc.dg/format/dfp-printf-1.c

>> @@ -17,6 +17,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>   

>>     /* Check lack of warnings for valid usage.  */

>>   

>> +  printf ("%Ha\n", x);

>> +  printf ("%HA\n", x);

>>     printf ("%Hf\n", x);

>>     printf ("%HF\n", x);

>>     printf ("%He\n", x);

>> @@ -24,6 +26,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%Hg\n", x);

>>     printf ("%HG\n", x);

>>   

>> +  printf ("%Da\n", y);

>> +  printf ("%DA\n", y);

>>     printf ("%Df\n", y);

>>     printf ("%DF\n", y);

>>     printf ("%De\n", y);

>> @@ -31,6 +35,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%Dg\n", y);

>>     printf ("%DG\n", y);

>>   

>> +  printf ("%DDa\n", z);

>> +  printf ("%DDA\n", z);

>>     printf ("%DDf\n", z);

>>     printf ("%DDF\n", z);

>>     printf ("%DDe\n", z);

>> @@ -43,12 +49,16 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>   

>>     /* Check warnings for type mismatches.  */

>>   

>> +  printf ("%Ha\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  printf ("%HA\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%Hf\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%HF\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%He\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%HE\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%Hg\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%HG\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  printf ("%Ha\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  printf ("%HA\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%Hf\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%HF\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%He\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>> @@ -56,12 +66,16 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%Hg\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%HG\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>   

>> +  printf ("%Da\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>> +  printf ("%DA\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%Df\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%DF\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%De\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%DE\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%Dg\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%DG\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>> +  printf ("%Da\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>> +  printf ("%DA\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%Df\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%DF\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%De\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>> @@ -69,12 +83,16 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%Dg\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     printf ("%DG\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>   

>> +  printf ("%DDa\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> +  printf ("%DDA\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDf\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDF\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDe\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDE\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDg\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDG\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> +  printf ("%DDa\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> +  printf ("%DDA\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDf\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDF\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     printf ("%DDe\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> @@ -90,8 +108,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%Hu\n", j);	/* { dg-warning "length" "bad use of %H" } */

>>     printf ("%Hx\n", j);	/* { dg-warning "length" "bad use of %H" } */

>>     printf ("%HX\n", j);	/* { dg-warning "length" "bad use of %H" } */

>> -  printf ("%Ha\n", d);	/* { dg-warning "length" "bad use of %H" } */

>> -  printf ("%HA\n", d);	/* { dg-warning "length" "bad use of %H" } */

>> +  printf ("%Ha\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  printf ("%HA\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     printf ("%Hc\n", i);	/* { dg-warning "length" "bad use of %H" } */

>>     printf ("%Hs\n", p);	/* { dg-warning "length" "bad use of %H" } */

>>     printf ("%Hp\n", p);	/* { dg-warning "length" "bad use of %H" } */

>> @@ -100,6 +118,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     /* Sanity checks for flags, field width, and precision in formats for

>>        DFP types.  */

>>   

>> +  printf ("%-Ha\n", x);

>> +  printf ("%+HA\n", x);

>>     printf ("%-Hf\n", x);

>>     printf ("%+HF\n", x);

>>     printf ("% He\n", x);

>> @@ -107,6 +127,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%0Hg\n", x);

>>     printf ("%#0HG\n", x);

>>   

>> +  printf ("%0#Da\n", y);

>> +  printf ("%0DA\n", y);

>>     printf ("%0#Df\n", y);

>>     printf ("%0DF\n", y);

>>     printf ("%#De\n", y);

>> @@ -114,6 +136,8 @@ foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,

>>     printf ("%-#0Dg\n", y);  /* { dg-warning "flag ignored" "ignore flag" } */

>>     printf ("%0+ DG\n", y);  /* { dg-warning "flag ignored" "ignore flag" } */

>>   

>> +  printf ("%DDa\n", z);

>> +  printf ("%0DDA\n", z);

>>     printf ("%DDf\n", z);

>>     printf ("%0DDF\n", z);

>>     printf ("%#0DDe\n", z);

>> diff --git a/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c b/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c

>> index ffa12a8..6df3bc6 100644

>> --- a/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c

>> +++ b/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c

>> @@ -17,6 +17,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>   

>>     /* Check lack of warnings for valid usage.  */

>>   

>> +  scanf ("%Ha", x);

>> +  scanf ("%HA", x);

>>     scanf ("%Hf", x);

>>     scanf ("%HF", x);

>>     scanf ("%He", x);

>> @@ -24,6 +26,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>     scanf ("%Hg", x);

>>     scanf ("%HG", x);

>>   

>> +  scanf ("%Da", y);

>> +  scanf ("%DA", y);

>>     scanf ("%Df", y);

>>     scanf ("%DF", y);

>>     scanf ("%De", y);

>> @@ -31,6 +35,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>     scanf ("%Dg", y);

>>     scanf ("%DG", y);

>>   

>> +  scanf ("%DDa", z);

>> +  scanf ("%DDA", z);

>>     scanf ("%DDf", z);

>>     scanf ("%DDF", z);

>>     scanf ("%DDe", z);

>> @@ -43,12 +49,16 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>   

>>     /* Check warnings for type mismatches.  */

>>   

>> +  scanf ("%Ha", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  scanf ("%HA", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%Hf", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%HF", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%He", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%HE", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%Hg", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%HG", y);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  scanf ("%Ha", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  scanf ("%HA", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%Hf", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%HF", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%He", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>> @@ -56,12 +66,16 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>     scanf ("%Hg", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%HG", z);	/* { dg-warning "expects argument" "bad use of %H" } */

>>   

>> +  scanf ("%Da", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>> +  scanf ("%DA", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%Df", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%DF", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%De", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%DE", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%Dg", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%DG", x);	/* { dg-warning "expects argument" "bad use of %D" } */

>> +  scanf ("%Da", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>> +  scanf ("%DA", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%Df", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%DF", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%De", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>> @@ -69,12 +83,16 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>     scanf ("%Dg", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>     scanf ("%DG", z);	/* { dg-warning "expects argument" "bad use of %D" } */

>>   

>> +  scanf ("%DDa", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> +  scanf ("%DDA", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDf", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDF", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDe", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDE", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDg", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDG", x);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> +  scanf ("%DDa", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> +  scanf ("%DDA", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDf", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDF", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>>     scanf ("%DDe", y);	/* { dg-warning "expects argument" "bad use of %DD" } */

>> @@ -90,8 +108,8 @@ voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,

>>     scanf ("%Hu\n", j);	/* { dg-warning "length" "bad use of %H" } */

>>     scanf ("%Hx\n", j);	/* { dg-warning "length" "bad use of %H" } */

>>     scanf ("%HX\n", j);	/* { dg-warning "length" "bad use of %H" } */

>> -  scanf ("%Ha\n", d);	/* { dg-warning "length" "bad use of %H" } */

>> -  scanf ("%HA\n", d);	/* { dg-warning "length" "bad use of %H" } */

>> +  scanf ("%Ha\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

>> +  scanf ("%HA\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */

>>     scanf ("%Hc\n", i);	/* { dg-warning "length" "bad use of %H" } */

>>     scanf ("%Hs\n", p);	/* { dg-warning "length" "bad use of %H" } */

>>     scanf ("%Hp\n", p);	/* { dg-warning "length" "bad use of %H" } */

>>
Jeff Law May 21, 2019, 3:52 p.m. | #3
On 5/20/19 6:56 PM, luoxhu wrote:
> Ping for GCC-10.

I thought this was a NAK in its current form.

See Ryan's c#1 in the BZ.

jeff
Joseph Myers May 23, 2019, 10:26 p.m. | #4
On Tue, 21 May 2019, Jeff Law wrote:

> On 5/20/19 6:56 PM, luoxhu wrote:

> > Ping for GCC-10.

> I thought this was a NAK in its current form.

> 

> See Ryan's c#1 in the BZ.


I don't see that as relevant to this bug report.

That comment is about the question of how GCC can know whether libc's 
printf supports this feature at all (since in principle the warnings are 
meant to relate to the features libc actually supports, unless you make a 
particular format language explicit by specifying gnu_printf rather than 
printf in the format attribute - though in practice it's only for MinGW 
that GCC actually knows about a different set of formats supported by 
default).  That comment suggests a possible answer (testing predefined 
macros after the implicit preinclusion of any implicitly preincluded 
header; note that the macro in question is now __STDC_IEC_60559_DFP__, in 
TS 18661-2 and C2X) - although, while glibc has supported stdc-predef.h 
for some time, current libdfp does not provide such a header.

This bug report is about an issue that, in the case where GCC is accepting 
DFP printf formats, the set of such formats accepted is incomplete.  A fix 
for it should be independent of any fix for the other (harder) issue.  (If 
there is a printf implementation that does in fact support the same subset 
of DFP formats supported by GCC's printf checking, but not the ones that 
are the subject of this bug report, that would complicate things.)

-- 
Joseph S. Myers
joseph@codesourcery.com
Jeff Law May 31, 2019, 6:42 p.m. | #5
On 5/23/19 4:26 PM, Joseph Myers wrote:
> On Tue, 21 May 2019, Jeff Law wrote:

> 

>> On 5/20/19 6:56 PM, luoxhu wrote:

>>> Ping for GCC-10.

>> I thought this was a NAK in its current form.

>>

>> See Ryan's c#1 in the BZ.

> 

> I don't see that as relevant to this bug report.

> 

> That comment is about the question of how GCC can know whether libc's 

> printf supports this feature at all (since in principle the warnings are 

> meant to relate to the features libc actually supports, unless you make a 

> particular format language explicit by specifying gnu_printf rather than 

> printf in the format attribute - though in practice it's only for MinGW 

> that GCC actually knows about a different set of formats supported by 

> default).  That comment suggests a possible answer (testing predefined 

> macros after the implicit preinclusion of any implicitly preincluded 

> header; note that the macro in question is now __STDC_IEC_60559_DFP__, in 

> TS 18661-2 and C2X) - although, while glibc has supported stdc-predef.h 

> for some time, current libdfp does not provide such a header.

> 

> This bug report is about an issue that, in the case where GCC is accepting 

> DFP printf formats, the set of such formats accepted is incomplete.  A fix 

> for it should be independent of any fix for the other (harder) issue.  (If 

> there is a printf implementation that does in fact support the same subset 

> of DFP formats supported by GCC's printf checking, but not the ones that 

> are the subject of this bug report, that would complicate things.)

> 

So your position is that runtime support isn't a factor in whether or
not we issue diagnostics for this stuff?

I guess that makes sense.  While we do have some checks for what the
runtime& target support, they're geared more type compatibility &
promotions.  Targets can add additional things via TARGET_FORMAT_TYPES
and friends.

Jeff
Jeff Law May 31, 2019, 6:46 p.m. | #6
On 2/25/19 6:13 PM, luoxhu@linux.ibm.com wrote:
> From: Xiong Hu Luo <luoxhu@linux.vnet.ibm.com>

> 

> dfp printf/scanf of Ha/HA, Da/DA and DDa/DDA is not set properly, cause

> incorrect warning happens:

> "use of 'D' length modifier with 'a' type character".

> 

> Regression-tested on powerpc64le-linux, OK for trunk and gcc-8?

> 

> gcc/c-family/ChangeLog:

> 

> 2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

> 

> 	PR c/43673

> 	* c-format.c (print_char_table, scanf_char_table): Replace BADLEN with

> 	TEX_D32, TEX_D64 or TEX_D128.

> 

> gcc/testsuit/ChangeLog:

> 

> 2019-02-25  Xiong Hu Luo  <luoxhu@linux.ibm.com>

> 

> 	PR c/43673

> 	* gcc.dg/format-dfp-printf-1.c: New test.

> 	* gcc.dg/format-dfp-scanf-1.c: Likewise.

THanks.  Installed on the trunk.

Sorry for the delays and miscommunications.
jeff

Patch

diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 9b48ee3..af33ef9 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -674,7 +674,7 @@  static const format_char_info print_char_table[] =
   { "n",   1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",          "W",  NULL },
   /* C99 conversion specifiers.  */
   { "F",   0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64, TEX_D128 }, "-wp0 +#'I", "",   NULL },
-  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp0 +#",   "",   NULL },
+  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64,  TEX_D128 }, "-wp0 +#",   "",   NULL },
   /* X/Open conversion specifiers.  */
   { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
   { "S",   1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "R",  NULL },
@@ -847,7 +847,7 @@  static const format_char_info scan_char_table[] =
   { "n",     1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",     "W",   NULL },
   /* C99 conversion specifiers.  */
   { "F",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32, TEX_D64, TEX_D128 }, "*w'",  "W",   NULL },
-  { "aA",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w'",  "W",   NULL },
+  { "aA",   1, STD_C99, { T99_F,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  TEX_D32,  TEX_D64,  TEX_D128 }, "*w'",  "W",   NULL },
   /* X/Open conversion specifiers.  */
   { "C",     1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*mw",   "W",   NULL },
   { "S",     1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*amw",  "W",   NULL },
diff --git a/gcc/testsuite/gcc.dg/format/dfp-printf-1.c b/gcc/testsuite/gcc.dg/format/dfp-printf-1.c
index e92f161..a290895 100644
--- a/gcc/testsuite/gcc.dg/format/dfp-printf-1.c
+++ b/gcc/testsuite/gcc.dg/format/dfp-printf-1.c
@@ -17,6 +17,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
 
   /* Check lack of warnings for valid usage.  */
 
+  printf ("%Ha\n", x);
+  printf ("%HA\n", x);
   printf ("%Hf\n", x);
   printf ("%HF\n", x);
   printf ("%He\n", x);
@@ -24,6 +26,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%Hg\n", x);
   printf ("%HG\n", x);
 
+  printf ("%Da\n", y);
+  printf ("%DA\n", y);
   printf ("%Df\n", y);
   printf ("%DF\n", y);
   printf ("%De\n", y);
@@ -31,6 +35,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%Dg\n", y);
   printf ("%DG\n", y);
 
+  printf ("%DDa\n", z);
+  printf ("%DDA\n", z);
   printf ("%DDf\n", z);
   printf ("%DDF\n", z);
   printf ("%DDe\n", z);
@@ -43,12 +49,16 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
 
   /* Check warnings for type mismatches.  */
 
+  printf ("%Ha\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HA\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%Hf\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%HF\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%He\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%HE\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%Hg\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%HG\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%Ha\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HA\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%Hf\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%HF\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%He\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
@@ -56,12 +66,16 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%Hg\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%HG\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
 
+  printf ("%Da\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DA\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%Df\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%DF\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%De\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%DE\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%Dg\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%DG\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%Da\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DA\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%Df\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%DF\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%De\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
@@ -69,12 +83,16 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%Dg\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   printf ("%DG\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
 
+  printf ("%DDa\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDA\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDf\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDF\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDe\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDE\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDg\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDG\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDa\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDA\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDf\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDF\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
   printf ("%DDe\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
@@ -90,8 +108,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%Hu\n", j);	/* { dg-warning "length" "bad use of %H" } */
   printf ("%Hx\n", j);	/* { dg-warning "length" "bad use of %H" } */
   printf ("%HX\n", j);	/* { dg-warning "length" "bad use of %H" } */
-  printf ("%Ha\n", d);	/* { dg-warning "length" "bad use of %H" } */
-  printf ("%HA\n", d);	/* { dg-warning "length" "bad use of %H" } */
+  printf ("%Ha\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HA\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */
   printf ("%Hc\n", i);	/* { dg-warning "length" "bad use of %H" } */
   printf ("%Hs\n", p);	/* { dg-warning "length" "bad use of %H" } */
   printf ("%Hp\n", p);	/* { dg-warning "length" "bad use of %H" } */
@@ -100,6 +118,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   /* Sanity checks for flags, field width, and precision in formats for
      DFP types.  */
 
+  printf ("%-Ha\n", x);
+  printf ("%+HA\n", x);
   printf ("%-Hf\n", x);
   printf ("%+HF\n", x);
   printf ("% He\n", x);
@@ -107,6 +127,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%0Hg\n", x);
   printf ("%#0HG\n", x);
 
+  printf ("%0#Da\n", y);
+  printf ("%0DA\n", y);
   printf ("%0#Df\n", y);
   printf ("%0DF\n", y);
   printf ("%#De\n", y);
@@ -114,6 +136,8 @@  foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j,
   printf ("%-#0Dg\n", y);  /* { dg-warning "flag ignored" "ignore flag" } */
   printf ("%0+ DG\n", y);  /* { dg-warning "flag ignored" "ignore flag" } */
 
+  printf ("%DDa\n", z);
+  printf ("%0DDA\n", z);
   printf ("%DDf\n", z);
   printf ("%0DDF\n", z);
   printf ("%#0DDe\n", z);
diff --git a/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c b/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c
index ffa12a8..6df3bc6 100644
--- a/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c
+++ b/gcc/testsuite/gcc.dg/format/dfp-scanf-1.c
@@ -17,6 +17,8 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
 
   /* Check lack of warnings for valid usage.  */
 
+  scanf ("%Ha", x);
+  scanf ("%HA", x);
   scanf ("%Hf", x);
   scanf ("%HF", x);
   scanf ("%He", x);
@@ -24,6 +26,8 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
   scanf ("%Hg", x);
   scanf ("%HG", x);
 
+  scanf ("%Da", y);
+  scanf ("%DA", y);
   scanf ("%Df", y);
   scanf ("%DF", y);
   scanf ("%De", y);
@@ -31,6 +35,8 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
   scanf ("%Dg", y);
   scanf ("%DG", y);
 
+  scanf ("%DDa", z);
+  scanf ("%DDA", z);
   scanf ("%DDf", z);
   scanf ("%DDF", z);
   scanf ("%DDe", z);
@@ -43,12 +49,16 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
 
   /* Check warnings for type mismatches.  */
 
+  scanf ("%Ha", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HA", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%Hf", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%HF", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%He", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%HE", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%Hg", y);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%HG", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%Ha", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HA", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%Hf", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%HF", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%He", z);	/* { dg-warning "expects argument" "bad use of %H" } */
@@ -56,12 +66,16 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
   scanf ("%Hg", z);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%HG", z);	/* { dg-warning "expects argument" "bad use of %H" } */
 
+  scanf ("%Da", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DA", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%Df", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%DF", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%De", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%DE", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%Dg", x);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%DG", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%Da", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DA", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%Df", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%DF", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%De", z);	/* { dg-warning "expects argument" "bad use of %D" } */
@@ -69,12 +83,16 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
   scanf ("%Dg", z);	/* { dg-warning "expects argument" "bad use of %D" } */
   scanf ("%DG", z);	/* { dg-warning "expects argument" "bad use of %D" } */
 
+  scanf ("%DDa", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDA", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDf", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDF", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDe", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDE", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDg", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDG", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDa", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDA", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDf", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDF", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
   scanf ("%DDe", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
@@ -90,8 +108,8 @@  voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j,
   scanf ("%Hu\n", j);	/* { dg-warning "length" "bad use of %H" } */
   scanf ("%Hx\n", j);	/* { dg-warning "length" "bad use of %H" } */
   scanf ("%HX\n", j);	/* { dg-warning "length" "bad use of %H" } */
-  scanf ("%Ha\n", d);	/* { dg-warning "length" "bad use of %H" } */
-  scanf ("%HA\n", d);	/* { dg-warning "length" "bad use of %H" } */
+  scanf ("%Ha\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HA\n", d);	/* { dg-warning "expects argument" "bad use of %H" } */
   scanf ("%Hc\n", i);	/* { dg-warning "length" "bad use of %H" } */
   scanf ("%Hs\n", p);	/* { dg-warning "length" "bad use of %H" } */
   scanf ("%Hp\n", p);	/* { dg-warning "length" "bad use of %H" } */