public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning
@ 2015-07-01 10:07 Uros Bizjak
  2015-07-08  7:06 ` Uros Bizjak
  2015-07-09 13:00 ` Ian Lance Taylor
  0 siblings, 2 replies; 5+ messages in thread
From: Uros Bizjak @ 2015-07-01 10:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Taylor

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

Hello!

This patch avoids "enum conversion when passing argument 1 of
‘getrusage’ is invalid in C++" warning when compiling getruntime.c.
The condition is copied from sys/resource.h.

2015-07-01  Uros Bizjak  <ubizjak@gmail.com>

    * getruntime.c (get_run_time) [__USE_GNU]: Use RUSAGE_SELF as
    argument 1 of getrusage call.

Bootstrapped on x86_64-linux-gnu.

OK for mainline?

Uros.

[-- Attachment #2: l.diff.txt --]
[-- Type: text/plain, Size: 577 bytes --]

Index: getruntime.c
===================================================================
--- getruntime.c	(revision 225221)
+++ getruntime.c	(working copy)
@@ -95,7 +95,11 @@ get_run_time (void)
 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
   struct rusage rusage;
 
+#if defined __USE_GNU && !defined __cplusplus
+  getrusage (RUSAGE_SELF, &rusage);
+#else
   getrusage (0, &rusage);
+#endif
   return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
 	  + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
 #else /* ! HAVE_GETRUSAGE */

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

* Re: [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning
  2015-07-01 10:07 [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning Uros Bizjak
@ 2015-07-08  7:06 ` Uros Bizjak
  2015-07-09 13:00 ` Ian Lance Taylor
  1 sibling, 0 replies; 5+ messages in thread
From: Uros Bizjak @ 2015-07-08  7:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Taylor

On Wed, Jul 1, 2015 at 12:07 PM, Uros Bizjak <ubizjak@gmail.com> wrote:

> This patch avoids "enum conversion when passing argument 1 of
> ‘getrusage’ is invalid in C++" warning when compiling getruntime.c.
> The condition is copied from sys/resource.h.
>
> 2015-07-01  Uros Bizjak  <ubizjak@gmail.com>
>
>     * getruntime.c (get_run_time) [__USE_GNU]: Use RUSAGE_SELF as
>     argument 1 of getrusage call.
>
> Bootstrapped on x86_64-linux-gnu.
>
> OK for mainline?

I went ahead and committed the patch to mainline as obvious.

Uros.

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

* Re: [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning
  2015-07-01 10:07 [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning Uros Bizjak
  2015-07-08  7:06 ` Uros Bizjak
@ 2015-07-09 13:00 ` Ian Lance Taylor
  2015-07-09 14:15   ` Uros Bizjak
  1 sibling, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2015-07-09 13:00 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches

On Wed, Jul 1, 2015 at 3:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>
> This patch avoids "enum conversion when passing argument 1 of
> ‘getrusage’ is invalid in C++" warning when compiling getruntime.c.
> The condition is copied from sys/resource.h.

Sorry, I've been on vacation.

I think it would be a lot nicer to always use RUSAGE_SELF in the
function, and earlier in the file write

#ifndef RUSAGE_SELF
#define RUSAGE_SELF 0
#endif

Ian

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

* Re: [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning
  2015-07-09 13:00 ` Ian Lance Taylor
@ 2015-07-09 14:15   ` Uros Bizjak
  2015-07-09 14:32     ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Uros Bizjak @ 2015-07-09 14:15 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 860 bytes --]

On Thu, Jul 9, 2015 at 3:00 PM, Ian Lance Taylor <iant@golang.org> wrote:
> On Wed, Jul 1, 2015 at 3:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>
>> This patch avoids "enum conversion when passing argument 1 of
>> ‘getrusage’ is invalid in C++" warning when compiling getruntime.c.
>> The condition is copied from sys/resource.h.
>
> Sorry, I've been on vacation.
>
> I think it would be a lot nicer to always use RUSAGE_SELF in the
> function, and earlier in the file write
>
> #ifndef RUSAGE_SELF
> #define RUSAGE_SELF 0
> #endif

Indeed, attached patch builds without warning.

2015-07-09  Uros Bizjak  <ubizjak@gmail.com>

    * getruntime.c (RUSAGE_SELF): Define if not already defined.
    (get_runtime): Use RUSAGE_SELF as argument 1 of getrusage call.

Bootstrapped on x86_64-linux-gnu.

OK for mainline SVN?

Uros.

[-- Attachment #2: l.diff.txt --]
[-- Type: text/plain, Size: 783 bytes --]

Index: getruntime.c
===================================================================
--- getruntime.c	(revision 225610)
+++ getruntime.c	(working copy)
@@ -65,6 +65,10 @@ Boston, MA 02110-1301, USA.  */
 #define CLOCKS_PER_SEC 1
 #endif
 
+#ifndef RUSAGE_SELF
+#define RUSAGE_SELF 0
+#endif
+
 #ifdef _SC_CLK_TCK
 #define GNU_HZ  sysconf(_SC_CLK_TCK)
 #else
@@ -95,11 +99,7 @@ get_run_time (void)
 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H)
   struct rusage rusage;
 
-#if defined __USE_GNU && !defined __cplusplus
   getrusage (RUSAGE_SELF, &rusage);
-#else
-  getrusage (0, &rusage);
-#endif
   return (rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec
 	  + rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec);
 #else /* ! HAVE_GETRUSAGE */

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

* Re: [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning
  2015-07-09 14:15   ` Uros Bizjak
@ 2015-07-09 14:32     ` Ian Lance Taylor
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2015-07-09 14:32 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches

On Thu, Jul 9, 2015 at 7:15 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Thu, Jul 9, 2015 at 3:00 PM, Ian Lance Taylor <iant@golang.org> wrote:
>> On Wed, Jul 1, 2015 at 3:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>>
>>> This patch avoids "enum conversion when passing argument 1 of
>>> ‘getrusage’ is invalid in C++" warning when compiling getruntime.c.
>>> The condition is copied from sys/resource.h.
>>
>> Sorry, I've been on vacation.
>>
>> I think it would be a lot nicer to always use RUSAGE_SELF in the
>> function, and earlier in the file write
>>
>> #ifndef RUSAGE_SELF
>> #define RUSAGE_SELF 0
>> #endif
>
> Indeed, attached patch builds without warning.
>
> 2015-07-09  Uros Bizjak  <ubizjak@gmail.com>
>
>     * getruntime.c (RUSAGE_SELF): Define if not already defined.
>     (get_runtime): Use RUSAGE_SELF as argument 1 of getrusage call.
>
> Bootstrapped on x86_64-linux-gnu.
>
> OK for mainline SVN?

This is OK.  Thanks for following up.

Ian

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

end of thread, other threads:[~2015-07-09 14:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-01 10:07 [PATCH, libiberty]: Avoid "enum conversion when passing argument 1 of ‘getrusage’ is invalid in C++" warning Uros Bizjak
2015-07-08  7:06 ` Uros Bizjak
2015-07-09 13:00 ` Ian Lance Taylor
2015-07-09 14:15   ` Uros Bizjak
2015-07-09 14:32     ` Ian Lance Taylor

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).