Skip to contentSkip to conversation

Remove pre ANSI c89 code

PATCH In review Juan Quintela 5 participants 14 messages Sep 22, 2009 – Sep 29, 2009

lore
Share & tools
lore
#0 lore raw

cover Remove pre ANSI c89 code

Hi

In commemoration of the 20th anniversary of the c89 standard, this brings qemu codebase to c89. How do I know?

Previous to last patch adds to QEMU_CFLAGS:
-Wold-style-declaration -Wold-style-definition

Why?
- typedef abuse for the 1st patch. How that ever worked, I don't know.
- gcc gets picky, and you have to declare functions as:
static inline void f(...)
inline static void f(...)
but
static void inline f(...)
gets warnings. Just move the few functions that have the third format to the 1st one.
- bring alpha-dis.c and sh4-dis.c to ansi c89 function declaration.
- static + const: gcc wants you to use:
static const
and gives a warning for
const static
- same for static + __thread (only 1 occurrence)
- last patch removes PARAMS() from dis-asm.h
last users were alpha-dis.c and sh4-dis.c (do you start to see a pattern here).

Last one is not required, but as qemu is not going to compile in pre-c89 compiler any time soon, it is better to also apply it.

Later, Juan.

Juan Quintela (7):
Use proper typedef syntax
static and inline should came before the type of the functions Bring two last users of K&R definitions to ANSI c89 gcc wants 1st static and then const
__thread should be before real type
Add -Wold-style-declaration -Wold-style-definition to QEMU_CFLAGS Remove PARAMS() macro

 alpha-dis.c                       |  116 ++++++++++++-------------------------
 configure                         |    1 +
 dis-asm.h                         |  102 ++++++++++++++++-----------------
 gen-icount.h                      |    2 +-
 hw/g364fb.c                       |    4 +-
 hw/pflash_cfi01.c                 |    2 +-
 hw/serial.c                       |    4 +-
 hw/sh7750.c                       |    2 +-
 hw/usb-bt.c                       |    2 +-
 hw/xen_blkif.h                    |    4 +-
 linux-user/arm/nwfpe/fpa11_cprt.c |    2 +-
 linux-user/mmap.c                 |    2 +-
 sh4-dis.c                         |   32 +++-------
 target-i386/kvm.c                 |    2 +-
 target-microblaze/translate.c     |    4 +-
 target-ppc/translate.c            |    8 +-
 16 files changed, 116 insertions(+), 173 deletions(-)
#1 lore raw

PATCH 1/7 Use proper typedef syntax

Why this ever compiled is a mistery to me.

---
 hw/serial.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/serial.c +2 -2
index a22770f..6e8c6e1 100644
@@ -98,13 +98,13 @@
 #define RECV_FIFO           1
 #define MAX_XMIT_RETRY      4
 
-struct SerialFIFO {
+typedef struct SerialFIFO {
     uint8_t data[UART_FIFO_LENGTH];
     uint8_t count;
     uint8_t itl;                        /* Interrupt Trigger Level */
     uint8_t tail;
     uint8_t head;
-} typedef SerialFIFO;
+} SerialFIFO;
 
 struct SerialState {
     uint16_t divider;
Signature · 1 line
1.6.2.5
#2 lore raw

[Qemu-devel] Re: [PATCH 1/7] Use proper typedef syntax

Quoted 14 lines · Juan Quintela

Why this ever compiled is a mistery to me.

---
 hw/serial.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/serial.c +0 -0
index a22770f..6e8c6e1 100644
@@ -98,13 +98,13 @@
 #define RECV_FIFO           1
 #define MAX_XMIT_RETRY      4

hw/serial.c line 107

Quoted 10 lines
hw/serial.c +2 -2
 
-struct SerialFIFO {
+typedef struct SerialFIFO {
     uint8_t data[UART_FIFO_LENGTH];
     uint8_t count;
     uint8_t itl;                        /* Interrupt Trigger Level */
     uint8_t tail;
     uint8_t head;
-} typedef SerialFIFO;
+} SerialFIFO;

Syntactically, typedef is a storage class specifier just like static or extern, and the entire struct { } block is type specifier like int or float. The order of type specifiers and storage class specifiers is not important. The above construct is thus perfectly valid, albeit unusual, C code.

That said, I'm all in favour of changing it to the more common style.

Signature · 2 lines
Måns Rullgård
[email protected]
#3 lore raw

PATCH 2/7 static and inline should came before the type of the functions

In reply to Juan Quintela
---
 gen-icount.h                      |    2 +-
 hw/g364fb.c                       |    2 +-
 hw/pflash_cfi01.c                 |    2 +-
 hw/sh7750.c                       |    2 +-
 hw/usb-bt.c                       |    2 +-
 hw/xen_blkif.h                    |    4 ++--
 linux-user/arm/nwfpe/fpa11_cprt.c |    2 +-
 target-ppc/translate.c            |    8 ++++----
 8 files changed, 12 insertions(+), 12 deletions(-)
gen-icount.h +1 -1
index d4524d6..01face2 100644
@@ -40,7 +40,7 @@ static void gen_icount_end(TranslationBlock *tb, int num_insns)
     }
 }
 
-static void inline gen_io_start(void)
+static inline void gen_io_start(void)
 {
     TCGv_i32 tmp = tcg_const_i32(1);
     tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUState, can_do_io));
hw/g364fb.c +1 -1
index d44fcc2..88e3048 100644
@@ -268,7 +268,7 @@ static void g364fb_update_display(void *opaque)
     qemu_irq_raise(s->irq);
 }
 
-static void inline g364fb_invalidate_display(void *opaque)
+static inline void g364fb_invalidate_display(void *opaque)
 {
     G364State *s = opaque;
     int i;
hw/pflash_cfi01.c +1 -1
index 6ba496e..dfdced9 100644
@@ -195,7 +195,7 @@ static void pflash_update(pflash_t *pfl, int offset,
     }
 }
 
-static void inline pflash_data_write(pflash_t *pfl, target_phys_addr_t offset,
+static inline void pflash_data_write(pflash_t *pfl, target_phys_addr_t offset,
                           uint32_t value, int width)
 {
     uint8_t *p = pfl->storage;
hw/sh7750.c +1 -1
index cf9cf16..933bbc0 100644
@@ -69,7 +69,7 @@ typedef struct SH7750State {
     struct intc_desc intc;
 } SH7750State;
 
-static int inline has_bcr3_and_bcr4(SH7750State * s)
+static inline int has_bcr3_and_bcr4(SH7750State * s)
 {
 	return (s->cpu->features & SH_FEATURE_BCR3_AND_BCR4);
 }
hw/usb-bt.c +1 -1
index 4c60d42..70fd4dd 100644
@@ -363,7 +363,7 @@ static inline int usb_bt_fifo_dequeue(struct usb_hci_in_fifo_s *fifo,
     return len;
 }
 
-static void inline usb_bt_fifo_out_enqueue(struct USBBtState *s,
+static inline void usb_bt_fifo_out_enqueue(struct USBBtState *s,
                 struct usb_hci_out_fifo_s *fifo,
                 void (*send)(struct HCIInfo *, const uint8_t *, int),
                 int (*complete)(const uint8_t *, int),
hw/xen_blkif.h +2 -2
index 738b8fe..c0f4136 100644
@@ -70,7 +70,7 @@ enum blkif_protocol {
 	BLKIF_PROTOCOL_X86_64 = 3,
 };
 
-static void inline blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_request_t *src)
+static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_request_t *src)
 {
 	int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
 
@@ -85,7 +85,7 @@ static void inline blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_reque
 		dst->seg[i] = src->seg[i];
 }
 
-static void inline blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_request_t *src)
+static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_request_t *src)
 {
 	int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
 
linux-user/arm/nwfpe/fpa11_cprt.c +1 -1
index fafa120..c80b124 100644
@@ -147,7 +147,7 @@ unsigned int PerformFIX(const unsigned int opcode)
 }
 
 
-static unsigned int __inline__
+static __inline unsigned int
 PerformComparisonOperation(floatx80 Fn, floatx80 Fm)
 {
    FPA11 *fpa11 = GET_FPA11();
target-ppc/translate.c +4 -4
index c8e8b6a..8844ad2 100644
@@ -2814,7 +2814,7 @@ static void gen_std(DisasContext *ctx)
 #endif
 /***                Integer load and store with byte reverse               ***/
 /* lhbrx */
-static void inline gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
+static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
 {
     tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
     if (likely(!ctx->le_mode)) {
@@ -2824,7 +2824,7 @@ static void inline gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
 
 /* lwbrx */
-static void inline gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
+static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
 {
     tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
     if (likely(!ctx->le_mode)) {
@@ -2834,7 +2834,7 @@ static void inline gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
 
 /* sthbrx */
-static void inline gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
+static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
 {
     if (likely(!ctx->le_mode)) {
         TCGv t0 = tcg_temp_new();
@@ -2849,7 +2849,7 @@ static void inline gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
 
 /* stwbrx */
-static void inline gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
+static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
 {
     if (likely(!ctx->le_mode)) {
         TCGv t0 = tcg_temp_new();
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 3/7 Bring two last users of K&R definitions to ANSI c89

In reply to Juan Quintela
---
 alpha-dis.c |   76 +++++++++++++---------------------------------------------
 sh4-dis.c   |   24 ++++--------------
 2 files changed, 23 insertions(+), 77 deletions(-)
alpha-dis.c +17 -59
index 097f06b..2f67c76 100644
@@ -434,18 +434,13 @@ const unsigned alpha_num_operands = sizeof(alpha_operands)/sizeof(*alpha_operand
 
 /*ARGSUSED*/
 static unsigned
-insert_rba(insn, value, errmsg)
-     unsigned insn;
-     int value ATTRIBUTE_UNUSED;
-     const char **errmsg ATTRIBUTE_UNUSED;
+insert_rba(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
 {
   return insn | (((insn >> 21) & 0x1f) << 16);
 }
 
 static int
-extract_rba(insn, invalid)
-     unsigned insn;
-     int *invalid;
+extract_rba(unsigned insn, int *invalid)
 {
   if (invalid != (int *) NULL
       && ((insn >> 21) & 0x1f) != ((insn >> 16) & 0x1f))
@@ -458,18 +453,13 @@ extract_rba(insn, invalid)
 
 /*ARGSUSED*/
 static unsigned
-insert_rca(insn, value, errmsg)
-     unsigned insn;
-     int value ATTRIBUTE_UNUSED;
-     const char **errmsg ATTRIBUTE_UNUSED;
+insert_rca(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
 {
   return insn | ((insn >> 21) & 0x1f);
 }
 
 static int
-extract_rca(insn, invalid)
-     unsigned insn;
-     int *invalid;
+extract_rca(unsigned insn, int *invalid)
 {
   if (invalid != (int *) NULL
       && ((insn >> 21) & 0x1f) != (insn & 0x1f))
@@ -482,18 +472,13 @@ extract_rca(insn, invalid)
 
 /*ARGSUSED*/
 static unsigned
-insert_za(insn, value, errmsg)
-     unsigned insn;
-     int value ATTRIBUTE_UNUSED;
-     const char **errmsg ATTRIBUTE_UNUSED;
+insert_za(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
 {
   return insn | (31 << 21);
 }
 
 static int
-extract_za(insn, invalid)
-     unsigned insn;
-     int *invalid;
+extract_za(unsigned insn, int *invalid)
 {
   if (invalid != (int *) NULL && ((insn >> 21) & 0x1f) != 31)
     *invalid = 1;
@@ -502,18 +487,13 @@ extract_za(insn, invalid)
 
 /*ARGSUSED*/
 static unsigned
-insert_zb(insn, value, errmsg)
-     unsigned insn;
-     int value ATTRIBUTE_UNUSED;
-     const char **errmsg ATTRIBUTE_UNUSED;
+insert_zb(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
 {
   return insn | (31 << 16);
 }
 
 static int
-extract_zb(insn, invalid)
-     unsigned insn;
-     int *invalid;
+extract_zb(unsigned insn, int *invalid)
 {
   if (invalid != (int *) NULL && ((insn >> 16) & 0x1f) != 31)
     *invalid = 1;
@@ -522,18 +502,13 @@ extract_zb(insn, invalid)
 
 /*ARGSUSED*/
 static unsigned
-insert_zc(insn, value, errmsg)
-     unsigned insn;
-     int value ATTRIBUTE_UNUSED;
-     const char **errmsg ATTRIBUTE_UNUSED;
+insert_zc(unsigned insn, int value ATTRIBUTE_UNUSED, const char **errmsg ATTRIBUTE_UNUSED)
 {
   return insn | 31;
 }
 
 static int
-extract_zc(insn, invalid)
-     unsigned insn;
-     int *invalid;
+extract_zc(unsigned insn, int *invalid)
 {
   if (invalid != (int *) NULL && (insn & 0x1f) != 31)
     *invalid = 1;
@@ -544,10 +519,7 @@ extract_zc(insn, invalid)
 /* The displacement field of a Branch format insn.  */
 
 static unsigned
-insert_bdisp(insn, value, errmsg)
-     unsigned insn;
-     int value;
-     const char **errmsg;
+insert_bdisp(unsigned insn, int value, const char **errmsg)
 {
   if (errmsg != (const char **)NULL && (value & 3))
     *errmsg = _("branch operand unaligned");
@@ -556,9 +528,7 @@ insert_bdisp(insn, value, errmsg)
 
 /*ARGSUSED*/
 static int
-extract_bdisp(insn, invalid)
-     unsigned insn;
-     int *invalid ATTRIBUTE_UNUSED;
+extract_bdisp(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
 {
   return 4 * (((insn & 0x1FFFFF) ^ 0x100000) - 0x100000);
 }
@@ -567,10 +537,7 @@ extract_bdisp(insn, invalid)
 /* The hint field of a JMP/JSR insn.  */
 
 static unsigned
-insert_jhint(insn, value, errmsg)
-     unsigned insn;
-     int value;
-     const char **errmsg;
+insert_jhint(unsigned insn, int value, const char **errmsg)
 {
   if (errmsg != (const char **)NULL && (value & 3))
     *errmsg = _("jump hint unaligned");
@@ -579,9 +546,7 @@ insert_jhint(insn, value, errmsg)
 
 /*ARGSUSED*/
 static int
-extract_jhint(insn, invalid)
-     unsigned insn;
-     int *invalid ATTRIBUTE_UNUSED;
+extract_jhint(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
 {
   return 4 * (((insn & 0x3FFF) ^ 0x2000) - 0x2000);
 }
@@ -589,10 +554,7 @@ extract_jhint(insn, invalid)
 /* The hint field of an EV6 HW_JMP/JSR insn.  */
 
 static unsigned
-insert_ev6hwjhint(insn, value, errmsg)
-     unsigned insn;
-     int value;
-     const char **errmsg;
+insert_ev6hwjhint(unsigned insn, int value, const char **errmsg)
 {
   if (errmsg != (const char **)NULL && (value & 3))
     *errmsg = _("jump hint unaligned");
@@ -601,9 +563,7 @@ insert_ev6hwjhint(insn, value, errmsg)
 
 /*ARGSUSED*/
 static int
-extract_ev6hwjhint(insn, invalid)
-     unsigned insn;
-     int *invalid ATTRIBUTE_UNUSED;
+extract_ev6hwjhint(unsigned insn, int *invalid ATTRIBUTE_UNUSED)
 {
   return 4 * (((insn & 0x1FFF) ^ 0x1000) - 0x1000);
 }
@@ -1804,9 +1764,7 @@ static const char * const vms_regnames[64] = {
 /* Disassemble Alpha instructions.  */
 
 int
-print_insn_alpha (memaddr, info)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
+print_insn_alpha (bfd_vma memaddr, struct disassemble_info *info)
 {
   static const struct alpha_opcode *opcode_index[AXP_NOPS+1];
   const char * const * regnames;
sh4-dis.c +6 -18
index d183176..a9ed5b2 100644
@@ -1170,11 +1170,8 @@ static void print_dsp_reg PARAMS ((int, fprintf_ftype, void *));
 static void print_insn_ppi PARAMS ((int, struct disassemble_info *));
 
 static void
-print_movxy (op, rn, rm, fprintf_fn, stream)
-     const sh_opcode_info *op;
-     int rn, rm;
-     fprintf_ftype fprintf_fn;
-     void *stream;
+print_movxy (const sh_opcode_info *op, int rn, int rm,
+	     fprintf_ftype fprintf_fn, void *stream)
 {
   int n;
 
@@ -1248,9 +1245,7 @@ print_movxy (op, rn, rm, fprintf_fn, stream)
    Return nonzero if a field b of a parallel processing insns follows.  */
 
 static void
-print_insn_ddt (insn, info)
-     int insn;
-     struct disassemble_info *info;
+print_insn_ddt (int insn, struct disassemble_info *info)
 {
   fprintf_ftype fprintf_fn = info->fprintf_func;
   void *stream = info->stream;
@@ -1337,10 +1332,7 @@ print_insn_ddt (insn, info)
 }
 
 static void
-print_dsp_reg (rm, fprintf_fn, stream)
-     int rm;
-     fprintf_ftype fprintf_fn;
-     void *stream;
+print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
 {
   switch (rm)
     {
@@ -1381,9 +1373,7 @@ print_dsp_reg (rm, fprintf_fn, stream)
 }
 
 static void
-print_insn_ppi (field_b, info)
-     int field_b;
-     struct disassemble_info *info;
+print_insn_ppi (int field_b, struct disassemble_info *info)
 {
   static const char *sx_tab[] = { "x0", "x1", "a0", "a1" };
   static const char *sy_tab[] = { "y0", "y1", "m0", "m1" };
@@ -1528,9 +1518,7 @@ print_insn_ppi (field_b, info)
 /* FIXME mvs: movx insns print as ".word 0x%03x", insn & 0xfff
    (ie. the upper nibble is missing).  */
 int
-print_insn_sh (memaddr, info)
-     bfd_vma memaddr;
-     struct disassemble_info *info;
+print_insn_sh (bfd_vma memaddr, struct disassemble_info *info)
 {
   fprintf_ftype fprintf_fn = info->fprintf_func;
   void *stream = info->stream;
Signature · 1 line
1.6.2.5
#5 lore raw

PATCH 4/7 gcc wants 1st static and then const

In reply to Juan Quintela
---
 hw/g364fb.c                   |    2 +-
 target-i386/kvm.c             |    2 +-
 target-microblaze/translate.c |    4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
hw/g364fb.c +1 -1
index 88e3048..d1d2c12 100644
@@ -396,7 +396,7 @@ static uint32_t g364fb_ctrl_readb(void *opaque, target_phys_addr_t addr)
 
 static void g364fb_update_depth(G364State *s)
 {
-    const static int depths[8] = { 1, 2, 4, 8, 15, 16, 0 };
+    static const int depths[8] = { 1, 2, 4, 8, 15, 16, 0 };
     s->depth = depths[(s->ctla & 0x00700000) >> 20];
 }
 
target-i386/kvm.c +1 -1
index cab9fcc..7010999 100644
@@ -790,7 +790,7 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
 #ifdef KVM_CAP_SET_GUEST_DEBUG
 int kvm_arch_insert_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint *bp)
 {
-    const static uint8_t int3 = 0xcc;
+    static const uint8_t int3 = 0xcc;
 
     if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 1, 0) ||
         cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&int3, 1, 1))
target-microblaze/translate.c +2 -2
index dfeb8ae..e91ea39 100644
@@ -91,7 +91,7 @@ typedef struct DisasContext {
     int singlestep_enabled;
 } DisasContext;
 
-const static char *regnames[] =
+static const char *regnames[] =
 {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
     "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
@@ -99,7 +99,7 @@ const static char *regnames[] =
     "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
 };
 
-const static char *special_regnames[] =
+static const char *special_regnames[] =
 {
     "rpc", "rmsr", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7",
     "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
Signature · 1 line
1.6.2.5
#6 lore raw

PATCH 5/7 __thread should be before real type

In reply to Juan Quintela
---
 linux-user/mmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/mmap.c +1 -1
index 07ce051..144fb7c 100644
@@ -35,7 +35,7 @@
 
 #if defined(CONFIG_USE_NPTL)
 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
-static int __thread mmap_lock_count;
+static __thread int mmap_lock_count;
 
 void mmap_lock(void)
 {
Signature · 1 line
1.6.2.5
#7 lore raw

PATCH 6/7 Add -Wold-style-declaration -Wold-style-definition to QEMU_CFLAGS

In reply to Juan Quintela

ANSI c89 has been with us for a while.

---
 configure |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
configure +1 -0
index 62dccd2..81b9ba8 100755
@@ -1648,6 +1648,7 @@ if test "$debug" = "no" ; then
 fi
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
+QEMU_CFLAGS="-Wold-style-declaration -Wold-style-definition $QEMU_CFLAGS"
 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
 QEMU_CFLAGS="-U_FORTIFY_SOURCE $QEMU_CFLAGS"
 QEMU_CFLAGS="-I. -I\$(SRC_PATH) -MMD -MP -MT \$@ $QEMU_CFLAGS"
Signature · 1 line
1.6.2.5
#8 lore raw

Re: [Qemu-devel] [PATCH 6/7] Add -Wold-style-declaration -Wold-style-definition to QEMU_CFLAGS

Quoted 12 lines · Juan Quintela

ANSI c89 has been with us for a while.

---
 configure |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index 62dccd2..81b9ba8 100755
@@ -1648,6 +1648,7 @@ if test "$debug" = "no" ; then
Quoted 4 lines

 fi
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" +QEMU_CFLAGS="-Wold-style-declaration -Wold-style-definition $QEMU_CFLAGS"

Some older versions of gcc don't handle -Wold-style-declaration. For instance gcc 4.1.2.

Laurent

Quoted 9 lines

 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" QEMU_CFLAGS="-U_FORTIFY_SOURCE $QEMU_CFLAGS"
 QEMU_CFLAGS="-I. -I\$(SRC_PATH) -MMD -MP -MT \$@ $QEMU_CFLAGS"
--
1.6.2.5

#9 lore raw

Re: [Qemu-devel] [PATCH 6/7] Add -Wold-style-declaration -Wold-style-definition to QEMU_CFLAGS

Quoted 8 lines · Laurent Desnogues
Quoted 7 lines · Juan Quintela

ANSI c89 has been with us for a while.

---
 configure |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines
Quoted 9 lines
configure +0 -0
index 62dccd2..81b9ba8 100755
@@ -1648,6 +1648,7 @@ if test "$debug" = "no" ; then

 fi
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" +QEMU_CFLAGS="-Wold-style-declaration -Wold-style-definition $QEMU_CFLAGS"

Some older versions of gcc don't handle -Wold-style-declaration. For instance gcc 4.1.2.

Pretty old, do we want to support it? If yes, make configure detect whether the warning works?

#10 lore raw

Re: [Qemu-devel] [PATCH 6/7] Add -Wold-style-declaration -Wold-style-definition to QEMU_CFLAGS

Quoted 23 lines · Markus Armbruster
Quoted 8 lines · Laurent Desnogues
Quoted 7 lines · Juan Quintela

ANSI c89 has been with us for a while.

---
 configure |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines
Quoted 9 lines
configure +0 -0
index 62dccd2..81b9ba8 100755
@@ -1648,6 +1648,7 @@ if test "$debug" = "no" ; then

 fi
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" +QEMU_CFLAGS="-Wold-style-declaration -Wold-style-definition $QEMU_CFLAGS"

Some older versions of gcc don't handle -Wold-style-declaration. For instance gcc 4.1.2.

Quoted 2 lines

Pretty old, do we want to support it?  If yes, make configure detect whether the warning works?

Yes, OpenBSD uses 3.3.5 (propolice).

There are already similar checks for linker flags in configure, new checks for warnings available would allow a different set of flags for the latest and greatest GCC and the good old ones.

#11 lore raw

[Qemu-devel] Re: [PATCH 6/7] Add -Wold-style-declaration -Wold-style-definition to QEMU_CFLAGS

Quoted 24 lines · Blue Swirl
Quoted 23 lines · Markus Armbruster
Quoted 20 lines · Laurent Desnogues
Quoted 12 lines · Juan Quintela

ANSI c89 has been with us for a while.

---
 configure |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
configure +0 -0
index 62dccd2..81b9ba8 100755
@@ -1648,6 +1648,7 @@ if test "$debug" = "no" ; then
Quoted 4 lines

 fi
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" +QEMU_CFLAGS="-Wold-style-declaration -Wold-style-definition $QEMU_CFLAGS"

Some older versions of gcc don't handle -Wold-style-declaration. For instance gcc 4.1.2.

Quoted 8 lines
Quoted 2 lines

Pretty old, do we want to support it?  If yes, make configure detect whether the warning works?

Yes, OpenBSD uses 3.3.5 (propolice).

There are already similar checks for linker flags in configure, new checks for warnings available would allow a different set of flags for the latest and greatest GCC and the good old ones.

Fixed in new series just sent. It detects in configure if flags exists.

Thanks for the review, Juan.

#12 lore raw

PATCH 7/7 Remove PARAMS() macro

In reply to Juan Quintela

Only two disassemblers (alpha and sh4) were still using it. Just remove its use there, and its aparations in dis-asm.h

---
 alpha-dis.c |   40 +++++++++++-----------
 dis-asm.h   |  102 ++++++++++++++++++++++++++++------------------------------
 sh4-dis.c   |    8 ++--
 3 files changed, 73 insertions(+), 77 deletions(-)
alpha-dis.c +20 -20
index 2f67c76..895d74d 100644
@@ -108,8 +108,8 @@ struct alpha_operand
      string (the operand will be inserted in any case).  If the
      operand value is legal, *ERRMSG will be unchanged (most operands
      can accept any value).  */
-  unsigned (*insert) PARAMS ((unsigned instruction, int op,
-			      const char **errmsg));
+  unsigned (*insert) (unsigned instruction, int op,
+                      const char **errmsg);
 
   /* Extraction function.  This is used by the disassembler.  To
      extract this operand type from an instruction, check this field.
@@ -128,7 +128,7 @@ struct alpha_operand
      non-zero if this operand type can not actually be extracted from
      this operand (i.e., the instruction does not match).  If the
      operand is valid, *INVALID will not be changed.  */
-  int (*extract) PARAMS ((unsigned instruction, int *invalid));
+  int (*extract) (unsigned instruction, int *invalid);
 };
 
 /* Elements in the table are retrieved by indexing with values from
@@ -273,23 +273,23 @@ enum bfd_reloc_code_real {
 
 
 /* Local insertion and extraction functions */
 
-static unsigned insert_rba PARAMS((unsigned, int, const char **));
-static unsigned insert_rca PARAMS((unsigned, int, const char **));
-static unsigned insert_za PARAMS((unsigned, int, const char **));
-static unsigned insert_zb PARAMS((unsigned, int, const char **));
-static unsigned insert_zc PARAMS((unsigned, int, const char **));
-static unsigned insert_bdisp PARAMS((unsigned, int, const char **));
-static unsigned insert_jhint PARAMS((unsigned, int, const char **));
-static unsigned insert_ev6hwjhint PARAMS((unsigned, int, const char **));
-
-static int extract_rba PARAMS((unsigned, int *));
-static int extract_rca PARAMS((unsigned, int *));
-static int extract_za PARAMS((unsigned, int *));
-static int extract_zb PARAMS((unsigned, int *));
-static int extract_zc PARAMS((unsigned, int *));
-static int extract_bdisp PARAMS((unsigned, int *));
-static int extract_jhint PARAMS((unsigned, int *));
-static int extract_ev6hwjhint PARAMS((unsigned, int *));
+static unsigned insert_rba (unsigned, int, const char **);
+static unsigned insert_rca (unsigned, int, const char **);
+static unsigned insert_za (unsigned, int, const char **);
+static unsigned insert_zb (unsigned, int, const char **);
+static unsigned insert_zc (unsigned, int, const char **);
+static unsigned insert_bdisp (unsigned, int, const char **);
+static unsigned insert_jhint (unsigned, int, const char **);
+static unsigned insert_ev6hwjhint (unsigned, int, const char **);
+
+static int extract_rba (unsigned, int *);
+static int extract_rca (unsigned, int *);
+static int extract_za (unsigned, int *);
+static int extract_zb (unsigned, int *);
+static int extract_zc (unsigned, int *);
+static int extract_bdisp (unsigned, int *);
+static int extract_jhint (unsigned, int *);
+static int extract_ev6hwjhint (unsigned, int *);
 
 

/* The operands table */

dis-asm.h +45 -47

134 lines not on this page · raw message

@@ -415,22 +413,20 @@ extern disassembler_ftype disassembler PARAMS ((bfd *));
/* Here is a function which callers may wish to use for read_memory_func.
It gets bytes from a buffer. */
extern int buffer_read_memory
- PARAMS ((bfd_vma, bfd_byte *, int, struct disassemble_info *));
+ (bfd_vma, bfd_byte *, int, struct disassemble_info *);

/* This function goes with buffer_read_memory.

    It prints a message using info->fprintf_func and info->stream.  */

-extern void perror_memory PARAMS ((int, bfd_vma, struct disassemble_info *)); +extern void perror_memory (int, bfd_vma, struct disassemble_info *);

/* Just print the address in hex. This is included for completeness even
though both GDB and objdump provide their own (to print symbolic addresses). */
-extern void generic_print_address
- PARAMS ((bfd_vma, struct disassemble_info *));
+extern void generic_print_address (bfd_vma, struct disassemble_info *);

/* Always true. */
-extern int generic_symbol_at_address
- PARAMS ((bfd_vma, struct disassemble_info *));
+extern int generic_symbol_at_address (bfd_vma, struct disassemble_info *);

/* Macro to initialize a disassemble_info struct. This should be called
by all applications creating such a struct. */

sh4-dis.c +4 -4
index a9ed5b2..a502a61 100644
@@ -1164,10 +1164,10 @@ const sh_opcode_info sh_table[] =
 #endif
 
 static void print_movxy
-  PARAMS ((const sh_opcode_info *, int, int, fprintf_ftype, void *));
-static void print_insn_ddt PARAMS ((int, struct disassemble_info *));
-static void print_dsp_reg PARAMS ((int, fprintf_ftype, void *));
-static void print_insn_ppi PARAMS ((int, struct disassemble_info *));
+  (const sh_opcode_info *, int, int, fprintf_ftype, void *);
+static void print_insn_ddt (int, struct disassemble_info *);
+static void print_dsp_reg (int, fprintf_ftype, void *);
+static void print_insn_ppi (int, struct disassemble_info *);
 
 static void
 print_movxy (const sh_opcode_info *op, int rn, int rm,
Signature · 1 line
1.6.2.5
#13 lore raw
In reply to Juan Quintela
Quoted 27 lines · Juan Quintela

Hi

In commemoration of the 20th anniversary of the c89 standard, this brings qemu codebase to c89. How do I know?

Previous to last patch adds to QEMU_CFLAGS:
-Wold-style-declaration -Wold-style-definition

Why?
- typedef abuse for the 1st patch. How that ever worked, I don't know.
- gcc gets picky, and you have to declare functions as:
static inline void f(...)
inline static void f(...)
but
static void inline f(...)
gets warnings. Just move the few functions that have the third format to the 1st one.
- bring alpha-dis.c and sh4-dis.c to ansi c89 function declaration.
- static + const: gcc wants you to use:
static const
and gives a warning for
const static
- same for static + __thread (only 1 occurrence)
- last patch removes PARAMS() from dis-asm.h
last users were alpha-dis.c and sh4-dis.c (do you start to see a pattern here).

Quoted 4 lines

Last one is not required, but as qemu is not going to compile in pre-c89 compiler any time soon, it is better to also apply it.

Later, Juan.

None of these are incorrect C89, just terribly old-fashioned and/or bad style. Good cleanup.