All of lore.kernel.org
 help / color / mirror / Atom feed
From: klammerj@a1.net (Johann Klammer)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Q: stdint format specifiers
Date: Thu, 04 Aug 2016 18:46:45 +0200	[thread overview]
Message-ID: <57A37175.7070801@a1.net> (raw)
In-Reply-To: <alpine.DEB.2.10.1608041833290.7967@hadrien>

On 08/04/2016 06:33 PM, Julia Lawall wrote:
> On Thu, 4 Aug 2016, Johann Klammer wrote:
> 
>> Does anyone have a coccinelle script to fixup *printf format specifiers to
>> those pesky PRI*** ones? I could not find one on coccinellery <http://coccinellery.org/>.
> 
> Could you give a more precise example of what you want to do?
> 
> thanks,
> julia

I was getting a gcc warning:

> make[1]: Entering directory '/home/klammerj/projects/FPGA/src/fpgatools/libs'
>   CC        floorplan.o
> floorplan.c: In function ?printf_LOGIC?:
> floorplan.c:369:17: warning: format ?%lX? expects argument of type ?long unsigned int?, but argument 6 has type ?uint64_t {aka long long unsigned int}? [-Wformat=]
>       fprintf(f, "%s%s\"%c6_lut_val\" : \"0x%016lX\" }",

I've fixed those by hand, but I think not all cases will give 
warnings, because int etc are often aliases for those stdint things. 
..same width signedness..
Thus I'd like to run coccinelle on the .c files, to look for printfs 
which have uintxx intxx type arguments and replace the corresponding
specifiers by the ones suggested in the C standard:



> 7.8.1 Macros for format specifiers
> 1 Each of the following object-like macros expands to a character string literal containing a
> conversion specifier, possibly modified by a length modifier, suitable for use within the
> format argument of a formatted input/output function when converting the corresponding
> integer type. These macro names have the general form of PRI (character string literals
> for the fprintf and fwprintf family) or SCN (character string literals for the
> fscanf and fwscanf family), 220) followed by the conversion specifier, followed by a
> name corresponding to a similar type name in 7.20.1. In these names, N represents the
> width of the type as described in 7.20.1. For example, PRIdFAST32 can be used in a
> format string to print the value of an integer of type int_fast32_t.
> 2 The fprintf macros for signed integers are:
> PRIdN
> PRIiN
> 3
> PRIdFASTN
> PRIiFASTN
> PRIdMAX
> PRIiMAX PRIdPTR
> PRIiPTR
> PRIoMAX
> PRIuMAX
> PRIxMAX
> PRIXMAX PRIoPTR
> PRIuPTR
> PRIxPTR
> PRIXPTR
> The fprintf macros for unsigned integers are:
> PRIoN
> PRIuN
> PRIxN
> PRIXN
> 4
> PRIdLEASTN
> PRIiLEASTN
> PRIoLEASTN
> PRIuLEASTN
> PRIxLEASTN
> PRIXLEASTN
> PRIoFASTN
> PRIuFASTN
> PRIxFASTN
> PRIXFASTN
> The fscanf macros for signed integers are:
[...]

result something along the lines of:

> diff --git a/libs/floorplan.c b/libs/floorplan.c
> index 2b9b27a..fb27edb 100644
> --- a/libs/floorplan.c
> +++ b/libs/floorplan.c
> @@ -366,7 +366,7 @@ int printf_LOGIC(FILE* f, struct fpga_model* model,
>                         if (cfg->a2d[j].flags & LUT6VAL_SET) {
>                                 RC_ASSERT(model, !ULL_HIGH32(cfg->a2d[j].lut6_val));
>                                 if (print_hex_vals)
> -                                       fprintf(f, "%s%s\"%c6_lut_val\" : \"0x%016lX\" }",
> +                                       fprintf(f, "%s%s\"%c6_lut_val\" : \"0x%016"PRIX64"\" }",
>                                                 first_line ? "" : ",\n", pref, 'A'+j, cfg->a2d[j].lut6_val);
>                                 else {
>                                         str = bool_bits2str(cfg->a2d[j].lut6_val, 32);
> @@ -389,7 +389,7 @@ int printf_LOGIC(FILE* f, struct fpga_model* model,
>                 } else {
>                         if (cfg->a2d[j].flags & LUT6VAL_SET) {
>                                 if (print_hex_vals)
> -                                       fprintf(f, "%s%s\"%c6_lut_val\" : \"0x%016lX\" }",
> +                                       fprintf(f, "%s%s\"%c6_lut_val\" : \"0x%016"PRIX64"\" }",
>                                                 first_line ? "" : ",\n", pref, 'A'+j, cfg->a2d[j].lut6_val);
>                                 else {
>                                         str = bool_bits2str(cfg->a2d[j].lut6_val, 64);

  reply	other threads:[~2016-08-04 16:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 16:30 [Cocci] Q: stdint format specifiers Johann Klammer
2016-08-04 16:33 ` Julia Lawall
2016-08-04 16:46   ` Johann Klammer [this message]
2016-08-04 17:10     ` Julia Lawall
2016-08-04 20:55       ` Johann Klammer
2016-08-04 21:11         ` Julia Lawall
2016-08-07 22:35           ` [Cocci] [Solved] " Johann Klammer
     [not found]             ` <alpine.DEB.2.10.1608080744490.3335@hadrien>
2016-08-08 10:48               ` Johann Klammer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57A37175.7070801@a1.net \
    --to=klammerj@a1.net \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.