public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: add an assert to gas/dw2gencfi.c
@ 2006-10-24  7:01 Ben Elliston
  2006-10-24  9:05 ` Jan Beulich
  2006-10-26  0:33 ` Alan Modra
  0 siblings, 2 replies; 5+ messages in thread
From: Ben Elliston @ 2006-10-24  7:01 UTC (permalink / raw)
  To: binutils

Another simple patch.  From memory, I discovered a port that defined
DWARF2_CIE_DATA_ALIGNMENT to 0, so the expression selected the : case
and abs_data_align was set to 0.  The subsequent modulo operation
aborted due to division by zero.

I think the assertion helps with fault-finding.  OK to commit?

2006-10-24  Ben Elliston  <bje@au.ibm.com>

        * dw2gencfi.c (cfi_add_CFA_offset): Assert that abs_data_align is
        greater than zero.

Index: dw2gencfi.c
===================================================================
RCS file: /cvs/src/src/gas/dw2gencfi.c,v
retrieving revision 1.28
diff -u -p -r1.28 dw2gencfi.c
--- dw2gencfi.c 27 Feb 2006 23:07:06 -0000      1.28
+++ dw2gencfi.c 24 Oct 2006 04:53:16 -0000
@@ -256,6 +256,8 @@ cfi_add_CFA_offset (unsigned regno, offs
 
   abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0
                    ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT);
+
+  assert (abs_data_align > 0);
   if (offset % abs_data_align)
     as_bad (_("register save offset not a multiple of %u"), abs_data_align);
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: add an assert to gas/dw2gencfi.c
  2006-10-24  7:01 PATCH: add an assert to gas/dw2gencfi.c Ben Elliston
@ 2006-10-24  9:05 ` Jan Beulich
  2006-10-24 11:28   ` Ben Elliston
  2006-10-26  0:33 ` Alan Modra
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2006-10-24  9:05 UTC (permalink / raw)
  To: Ben Elliston; +Cc: binutils

>--- dw2gencfi.c 27 Feb 2006 23:07:06 -0000      1.28
>+++ dw2gencfi.c 24 Oct 2006 04:53:16 -0000
>@@ -256,6 +256,8 @@ cfi_add_CFA_offset (unsigned regno, offs
> 
>   abs_data_align = (DWARF2_CIE_DATA_ALIGNMENT < 0
>                    ? -DWARF2_CIE_DATA_ALIGNMENT : DWARF2_CIE_DATA_ALIGNMENT);
>+
>+  assert (abs_data_align > 0);
>   if (offset % abs_data_align)
>     as_bad (_("register save offset not a multiple of %u"), abs_data_align);
> }

I have to admit that I'd find it more obvious to put the assert before
the assignment, and have DWARF2_CIE_DATA_ALIGNMENT be its
subject; if there is no potential for this not being a compile-time
constant, then this could even become a build-time assertion rather
than a run-time one.

Jan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: add an assert to gas/dw2gencfi.c
  2006-10-24  9:05 ` Jan Beulich
@ 2006-10-24 11:28   ` Ben Elliston
  2006-10-24 13:30     ` Ben Elliston
  0 siblings, 1 reply; 5+ messages in thread
From: Ben Elliston @ 2006-10-24 11:28 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

> I have to admit that I'd find it more obvious to put the assert
> before the assignment, and have DWARF2_CIE_DATA_ALIGNMENT be its
> subject; if there is no potential for this not being a compile-time
> constant, then this could even become a build-time assertion rather
> than a run-time one.

Fair enough.

There are plenty of instances where DWARF2_CIE_DATA_ALIGNMENT is
#defined to a function name, so catching it at build time seems like a
non-starter.

Thanks, Ben

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: add an assert to gas/dw2gencfi.c
  2006-10-24 11:28   ` Ben Elliston
@ 2006-10-24 13:30     ` Ben Elliston
  0 siblings, 0 replies; 5+ messages in thread
From: Ben Elliston @ 2006-10-24 13:30 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

> There are plenty of instances where DWARF2_CIE_DATA_ALIGNMENT is
> #defined to a function name,

Err, I mean variable.

Ben

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: PATCH: add an assert to gas/dw2gencfi.c
  2006-10-24  7:01 PATCH: add an assert to gas/dw2gencfi.c Ben Elliston
  2006-10-24  9:05 ` Jan Beulich
@ 2006-10-26  0:33 ` Alan Modra
  1 sibling, 0 replies; 5+ messages in thread
From: Alan Modra @ 2006-10-26  0:33 UTC (permalink / raw)
  To: Ben Elliston; +Cc: binutils

On Tue, Oct 24, 2006 at 02:54:11PM +1000, Ben Elliston wrote:
>         * dw2gencfi.c (cfi_add_CFA_offset): Assert that abs_data_align is
>         greater than zero.

OK.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-10-26  0:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-24  7:01 PATCH: add an assert to gas/dw2gencfi.c Ben Elliston
2006-10-24  9:05 ` Jan Beulich
2006-10-24 11:28   ` Ben Elliston
2006-10-24 13:30     ` Ben Elliston
2006-10-26  0:33 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).