Re: Document __builtin_*_overflow

2014-11-25 Thread Gerald Pfeifer
Hi Jakub,

On Wednesday 2014-11-12 14:13, Jakub Jelinek wrote:
 This patch mentions __builtin_*_overflow in gcc-5/changes.html.
 Ok for CVS?

I've fallen a bit behind with GCC patches, sorry.

What do you think about this follow-up patch on top of yours?

Gerald

Index: changes.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-5/changes.html,v
retrieving revision 1.41
diff -u -r1.41 changes.html
--- changes.html23 Nov 2014 14:42:28 -  1.41
+++ changes.html25 Nov 2014 18:49:02 -
@@ -157,14 +157,14 @@
These builtins have two integral arguments (which don't need to have
the same type), the arguments are extended to infinite precision
signed type, code+/code, code-/code or code*/code
-   is performed on those and the result is stored into some integer
-   variable pointed by the last argument.  If the stored value is equal
-   to the infinite precision result, the built-in functions return
+   is performed on those, and the result is stored in an integer
+   variable pointed to by the last argument.  If the stored value is
+   equal to the infinite precision result, the built-in functions return
codefalse/code, otherwise codetrue/code.  The type of
the integer variable that will hold the result can be different from
-   the types of arguments.  The following snippet demonstrates how
-   this can be used in computing the size for the codecalloc/code
-   function:
+   the types of the first two arguments.  The following snippet
+   demonstrates how this can be used in computing the size for the
+   codecalloc/code function:
 blockquotepre
 void *
 calloc (size_t x, size_t y)
@@ -177,8 +177,8 @@
   return ret;
 }
 /pre/blockquote
-   On e.g. i?86 or x86-64 the above will result in codemul/code
-   instruction followed by jump on overflow.
+   On e.g. i?86 or x86-64 the above will result in a codemul/code
+   instruction followed by a jump on overflow.
 /li
 liThe option code-fextended-identifiers/code is now enabled
by default for C++, and for C99 and later C versions.  Various

Gerald


Re: Document __builtin_*_overflow

2014-11-25 Thread Jakub Jelinek
On Tue, Nov 25, 2014 at 07:50:02PM +0100, Gerald Pfeifer wrote:
 Hi Jakub,
 
 On Wednesday 2014-11-12 14:13, Jakub Jelinek wrote:
  This patch mentions __builtin_*_overflow in gcc-5/changes.html.
  Ok for CVS?
 
 I've fallen a bit behind with GCC patches, sorry.
 
 What do you think about this follow-up patch on top of yours?

LGTM, thanks.

 --- changes.html  23 Nov 2014 14:42:28 -  1.41
 +++ changes.html  25 Nov 2014 18:49:02 -
 @@ -157,14 +157,14 @@
   These builtins have two integral arguments (which don't need to have
   the same type), the arguments are extended to infinite precision
   signed type, code+/code, code-/code or code*/code
 - is performed on those and the result is stored into some integer
 - variable pointed by the last argument.  If the stored value is equal
 - to the infinite precision result, the built-in functions return
 + is performed on those, and the result is stored in an integer
 + variable pointed to by the last argument.  If the stored value is
 + equal to the infinite precision result, the built-in functions return
   codefalse/code, otherwise codetrue/code.  The type of
   the integer variable that will hold the result can be different from
 - the types of arguments.  The following snippet demonstrates how
 - this can be used in computing the size for the codecalloc/code
 - function:
 + the types of the first two arguments.  The following snippet
 + demonstrates how this can be used in computing the size for the
 + codecalloc/code function:
  blockquotepre
  void *
  calloc (size_t x, size_t y)
 @@ -177,8 +177,8 @@
return ret;
  }
  /pre/blockquote
 - On e.g. i?86 or x86-64 the above will result in codemul/code
 - instruction followed by jump on overflow.
 + On e.g. i?86 or x86-64 the above will result in a codemul/code
 + instruction followed by a jump on overflow.
  /li
  liThe option code-fextended-identifiers/code is now enabled
   by default for C++, and for C99 and later C versions.  Various
 
 Gerald

Jakub


Document __builtin_*_overflow

2014-11-12 Thread Jakub Jelinek
Hi!

This patch mentions __builtin_*_overflow in gcc-5/changes.html.
Ok for CVS?

--- gcc-5/changes.html  27 Oct 2014 18:05:26 -  1.20
+++ gcc-5/changes.html  12 Nov 2014 13:09:01 -
@@ -84,7 +84,36 @@
 of the standard directive code#include/code
 and the extension code#include_next/code respectively.
 /li
-
+liA new set of built-in functions for arithmetics with overflow checking
+   has been added: code__builtin_add_overflow/code,
+   code__builtin_sub_overflow/code and 
code__builtin_mul_overflow/code
+   and for compatibility with clang also other variants.
+   These builtins have two integral arguments (which don't need to have
+   the same type), the arguments are extended to infinite precision
+   signed type, code+/code, code-/code or code*/code
+   is performed on those and the result is stored into some integer
+   variable pointed by the last argument.  If the stored value is equal
+   to the infinite precision result, the built-in functions return
+   codefalse/code, otherwise codetrue/code.  The type of
+   the integer variable that will hold the result can be different from
+   the types of arguments.  The following snippet demonstrates how
+   this can be used in computing the size for the codecalloc/code
+   function:
+blockquotepre
+void *
+calloc (size_t x, size_t y)
+{
+  size_t sz;
+  if (__builtin_mul_overflow (x, y, amp;sz)
+return NULL;
+  void *ret = malloc (sz);
+  if (ret) memset (res, 0, sz);
+  return ret;
+}
+/pre/blockquote
+   On e.g. i?86 or x86-64 the above will result in codemul/code
+   instruction followed by jump on overflow.
+/li
   /ul
 
 h3 id=cC/h3

Jakub


Re: Document __builtin_*_overflow

2014-11-12 Thread Richard Biener
On Wed, Nov 12, 2014 at 2:13 PM, Jakub Jelinek ja...@redhat.com wrote:
 Hi!

 This patch mentions __builtin_*_overflow in gcc-5/changes.html.
 Ok for CVS?

Ok.

Thanks,
Richard.

 --- gcc-5/changes.html  27 Oct 2014 18:05:26 -  1.20
 +++ gcc-5/changes.html  12 Nov 2014 13:09:01 -
 @@ -84,7 +84,36 @@
  of the standard directive code#include/code
  and the extension code#include_next/code respectively.
  /li
 -
 +liA new set of built-in functions for arithmetics with overflow 
 checking
 +   has been added: code__builtin_add_overflow/code,
 +   code__builtin_sub_overflow/code and 
 code__builtin_mul_overflow/code
 +   and for compatibility with clang also other variants.
 +   These builtins have two integral arguments (which don't need to have
 +   the same type), the arguments are extended to infinite precision
 +   signed type, code+/code, code-/code or code*/code
 +   is performed on those and the result is stored into some integer
 +   variable pointed by the last argument.  If the stored value is equal
 +   to the infinite precision result, the built-in functions return
 +   codefalse/code, otherwise codetrue/code.  The type of
 +   the integer variable that will hold the result can be different from
 +   the types of arguments.  The following snippet demonstrates how
 +   this can be used in computing the size for the codecalloc/code
 +   function:
 +blockquotepre
 +void *
 +calloc (size_t x, size_t y)
 +{
 +  size_t sz;
 +  if (__builtin_mul_overflow (x, y, amp;sz)
 +return NULL;
 +  void *ret = malloc (sz);
 +  if (ret) memset (res, 0, sz);
 +  return ret;
 +}
 +/pre/blockquote
 +   On e.g. i?86 or x86-64 the above will result in codemul/code
 +   instruction followed by jump on overflow.
 +/li
/ul

  h3 id=cC/h3

 Jakub


Re: Document __builtin_*_overflow

2014-11-12 Thread Tristan Gingold

 On 12 Nov 2014, at 14:13, Jakub Jelinek ja...@redhat.com wrote:
 +  size_t sz;
 +  if (__builtin_mul_overflow (x, y, amp;sz)

Missing right parenthesis ?



Re: Document __builtin_*_overflow

2014-11-12 Thread Jakub Jelinek
On Wed, Nov 12, 2014 at 03:39:25PM +0100, Tristan Gingold wrote:
 
  On 12 Nov 2014, at 14:13, Jakub Jelinek ja...@redhat.com wrote:
  +  size_t sz;
  +  if (__builtin_mul_overflow (x, y, amp;sz)
 
 Missing right parenthesis ?

Thanks, fixed.

Jakub