Skip to content

Commit

Permalink
Clean up gcc attributes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dgibson committed Mar 6, 2017
1 parent 49300f2 commit 672ac09
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
8 changes: 2 additions & 6 deletions checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions dtc-lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);

%}

Expand Down
1 change: 0 additions & 1 deletion dtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#define debug(...)
#endif


#define DEFAULT_FDT_VERSION 17

/*
Expand Down
11 changes: 5 additions & 6 deletions srcpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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

struct srcfile_state {
FILE *f;
Expand Down Expand Up @@ -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);

Expand Down
30 changes: 14 additions & 16 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 672ac09

Please sign in to comment.