Browse Source

Clean up gcc attributes

We have a number of explicit __GNUC__ conditionals to tell if we want to
use some gcc extensions for extra warnings.  This cleans this up to use
a single conditional, defining convenience macros for those attributes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 8 years ago
parent
commit
672ac09ea0
  1. 8
      checks.c
  2. 7
      dtc-lexer.l
  3. 1
      dtc.h
  4. 11
      srcpos.h
  5. 30
      util.h

8
checks.c

@ -72,12 +72,8 @@ struct check { @@ -72,12 +72,8 @@ struct check {
#define CHECK(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, false, false, __VA_ARGS__)

#ifdef __GNUC__
static inline void check_msg(struct check *c, struct dt_info *dti,
const char *fmt, ...) __attribute__((format (printf, 3, 4)));
#endif
static inline void check_msg(struct check *c, struct dt_info *dti,
const char *fmt, ...)
static inline void PRINTF(3, 4) check_msg(struct check *c, struct dt_info *dti,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

7
dtc-lexer.l

@ -62,12 +62,7 @@ static int dts_version = 1; @@ -62,12 +62,7 @@ static int dts_version = 1;

static void push_input_file(const char *filename);
static bool pop_input_file(void);
#ifdef __GNUC__
static void lexical_error(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));
#else
static void lexical_error(const char *fmt, ...);
#endif
static void PRINTF(1, 2) lexical_error(const char *fmt, ...);

%}


1
dtc.h

@ -43,7 +43,6 @@ @@ -43,7 +43,6 @@
#define debug(...)
#endif


#define DEFAULT_FDT_VERSION 17

/*

11
srcpos.h

@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@

#include <stdio.h>
#include <stdbool.h>
#include "util.h"

struct srcfile_state {
FILE *f;
@ -106,12 +107,10 @@ extern void srcpos_update(struct srcpos *pos, const char *text, int len); @@ -106,12 +107,10 @@ extern void srcpos_update(struct srcpos *pos, const char *text, int len);
extern struct srcpos *srcpos_copy(struct srcpos *pos);
extern char *srcpos_string(struct srcpos *pos);

extern void srcpos_verror(struct srcpos *pos, const char *prefix,
const char *fmt, va_list va)
__attribute__((format(printf, 3, 0)));
extern void srcpos_error(struct srcpos *pos, const char *prefix,
const char *fmt, ...)
__attribute__((format(printf, 3, 4)));
extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
const char *fmt, va_list va);
extern void PRINTF(3, 4) srcpos_error(struct srcpos *pos, const char *prefix,
const char *fmt, ...);

extern void srcpos_set_line(char *f, int l);


30
util.h

@ -25,15 +25,17 @@ @@ -25,15 +25,17 @@
* USA
*/

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

#ifdef __GNUC__
static inline void
__attribute__((noreturn)) __attribute__((format (printf, 1, 2)))
die(const char *str, ...)
#define PRINTF(i, j) __attribute__((format (printf, i, j)))
#define NORETURN __attribute__((noreturn))
#else
static inline void die(const char *str, ...)
#define PRINTF(i, j)
#define NORETURN
#endif

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

static inline void NORETURN PRINTF(1, 2) die(const char *str, ...)
{
va_list ap;

@ -66,12 +68,7 @@ static inline void *xrealloc(void *p, size_t len) @@ -66,12 +68,7 @@ static inline void *xrealloc(void *p, size_t len)

extern char *xstrdup(const char *s);

#ifdef __GNUC__
extern int __attribute__((format (printf, 2, 3)))
xasprintf(char **strp, const char *fmt, ...);
#else
extern int xasprintf(char **strp, const char *fmt, ...);
#endif
extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...);
extern char *join_path(const char *path, const char *name);

/**
@ -200,7 +197,7 @@ void utilfdt_print_data(const char *data, int len); @@ -200,7 +197,7 @@ void utilfdt_print_data(const char *data, int len);
/**
* Show source version and exit
*/
void util_version(void) __attribute__((noreturn));
void NORETURN util_version(void);

/**
* Show usage and exit
@ -214,9 +211,10 @@ void util_version(void) __attribute__((noreturn)); @@ -214,9 +211,10 @@ void util_version(void) __attribute__((noreturn));
* @param long_opts The structure of long options
* @param opts_help An array of help strings (should align with long_opts)
*/
void util_usage(const char *errmsg, const char *synopsis,
const char *short_opts, struct option const long_opts[],
const char * const opts_help[]) __attribute__((noreturn));
void NORETURN util_usage(const char *errmsg, const char *synopsis,
const char *short_opts,
struct option const long_opts[],
const char * const opts_help[]);

/**
* Show usage and exit

Loading…
Cancel
Save