<html><body>
<p><font size="2" face="sans-serif">Hi Jim, Hal,</font><br>
<br>
<font size="2" face="sans-serif">Thanks for explaining this.</font><br>
<br>
<font size="2" face="sans-serif">I do understand the casting solution, but I am not sure what function you are referring to in your last message.</font><br>
<font size="2" face="sans-serif">Can you please explain?</font><br>
<br>
<br>
<font size="2" face="sans-serif">Thanks</font><br>
<br>
<font size="2" face="sans-serif">-- Carlo</font><br>
<br>
<br>
<br>
<img width="16" height="16" src="cid:1__=0ABBF76FDFCB7DE58f9e8a93df938@us.ibm.com" border="0" alt="Inactive hide details for "Cownie, James H" ---03/02/2015 06:28:19 AM---> If you'd like to prevent this, you'll need to change "><font size="2" color="#424282" face="sans-serif">"Cownie, James H" ---03/02/2015 06:28:19 AM---> If you'd like to prevent this, you'll need to change the type of the variable to int  > (or unsign</font><br>
<br>
<font size="1" color="#5F5F5F" face="sans-serif">From:      </font><font size="1" face="sans-serif">"Cownie, James H" <james.h.cownie@intel.com></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">To:        </font><font size="1" face="sans-serif">Hal Finkel <hfinkel@anl.gov></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Cc:        </font><font size="1" face="sans-serif">Carlo Bertolli/Watson/IBM@IBMUS, "openmp-dev@dcs-maillist2.engr.illinois.edu" <openmp-dev@dcs-maillist2.engr.illinois.edu></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Date:      </font><font size="1" face="sans-serif">03/02/2015 06:28 AM</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Subject:   </font><font size="1" face="sans-serif">RE: [Openmp-dev] Two warnings with clang 3.5 on ppc63le</font><br>
<hr width="100%" size="2" align="left" noshade style="color:#8091A5; "><br>
<br>
<br>
<tt><font size="2">> If you'd like to prevent this, you'll need to change the type of the variable to int <br>
> (or unsigned int, etc.). You might notice that in LLVM, for example, we have many 'enum' <br>
> variables that are typed as 'int' or 'unsigned' for a similar reason (if you want to use <br>
> an enum to name some possible integer values, but allow others, you can't actually use an <br>
> enum as the variable type).<br>
<br>
So the right answer, then, would be to change the formal argument of the function to be of <br>
type "int", rather than the enum type, and rely on the fact that enums are silently, automatically, cast<br>
to int.<br>
<br>
-- Jim<br>
<br>
James Cownie <james.h.cownie@intel.com><br>
SSG/DPD/TCAR (Technical Computing, Analyzers and Runtimes)<br>
Tel: +44 117 9071438<br>
<br>
-----Original Message-----<br>
From: Hal Finkel [</font></tt><tt><font size="2"><a href="mailto:hfinkel@anl.gov">mailto:hfinkel@anl.gov</a></font></tt><tt><font size="2">] <br>
Sent: Monday, March 2, 2015 11:15 AM<br>
To: Cownie, James H<br>
Cc: Carlo Bertolli; openmp-dev@dcs-maillist2.engr.illinois.edu<br>
Subject: Re: [Openmp-dev] Two warnings with clang 3.5 on ppc63le<br>
<br>
----- Original Message -----<br>
> From: "James H Cownie" <james.h.cownie@intel.com><br>
> To: "Carlo Bertolli" <cbertol@us.ibm.com>, openmp-dev@dcs-maillist2.engr.illinois.edu<br>
> Sent: Monday, March 2, 2015 4:28:27 AM<br>
> Subject: Re: [Openmp-dev] Two warnings with clang 3.5 on ppc63le<br>
> <br>
> 1.<br>
> /home/compteam/slave0/build_folder_omp/libiomp-src/runtime/src/kmp_error.c:124:23:<br>
> warning: comparison of constant 16 with expression of type 'enum<br>
> cons_type' is always true<br>
> [-Wtautological-constant-out-of-range-compare]<br>
> if ( 0 < ct && ct <= cons_text_c_num ) {;<br>
> ~~ ^ ~~~~~~~~~~~~~~~<br>
> <br>
> It looks like that there are no machines where const char * is more<br>
> that 64-bit. The second check can be removed safely - maybe the<br>
> author of this intended something different?<br>
> <br>
> I think you’re misunderstanding the point here. cons_text_c_num gives<br>
> us the number of elements in the table. The point so to ensure that<br>
> the value we’ve been passed is a correct index into the table. The<br>
> compiler is right that * if * the value passed is a correct member<br>
> of the enumeration it can’t be outside the range, but the check is<br>
> there precisely to ensure that the value passed in is in range<br>
> (because we can’t tell here that someone didn’t call this with<br>
> “(enum cons_type)1000”).<br>
> <br>
> So I think what we need here is a cast so that your compiler is<br>
> happy<br>
<br>
To be clear, the problem with the happiness of the compiler here is that, as written, the compiler is free to remove the check all together. Adding the cast may silence the warning, but the compiler's optimizer is still free to infer the range of the variable based on its original type. If you'd like to prevent this, you'll need to change the type of the variable to int (or unsigned int, etc.). You might notice that in LLVM, for example, we have many 'enum' variables that are typed as 'int' or 'unsigned' for a similar reason (if you want to use an enum to name some possible integer values, but allow others, you can't actually use an enum as the variable type).<br>
<br>
 -Hal<br>
<br>
>, rather than removing the test.<br>
> <br>
> Something like<br>
> <br>
> if ( 0 < ct && ((int)ct) <= cons_text_c_num ) {;<br>
> <br>
> You could write the whole thing as<br>
> <br>
> if ( ((unsigned int)ct) <= cons_text_c_num ) {;<br>
> but that may be a little too clever for its own good, especially<br>
> since the performance of this code can’t matter.<br>
> <br>
> -- Jim<br>
> <br>
> James Cownie <james.h.cownie@intel.com><br>
> SSG/DPD/TCAR (Technical Computing, Analyzers and Runtimes)<br>
> <br>
> Tel: +44 117 9071438<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> From: openmp-dev-bounces@cs.uiuc.edu<br>
> [</font></tt><tt><font size="2"><a href="mailto:openmp-dev-bounces@cs.uiuc.edu">mailto:openmp-dev-bounces@cs.uiuc.edu</a></font></tt><tt><font size="2">] On Behalf Of Carlo Bertolli<br>
> Sent: Friday, February 27, 2015 10:57 PM<br>
> To: openmp-dev@dcs-maillist2.engr.illinois.edu<br>
> Subject: [Openmp-dev] Two warnings with clang 3.5 on ppc63le<br>
> <br>
> <br>
> <br>
> Hi<br>
> <br>
> Using clang 3.5 on ppc64le, I obtained the following warnings.<br>
> <br>
> 1.<br>
> /home/compteam/slave0/build_folder_omp/libiomp-src/runtime/src/kmp_error.c:124:23:<br>
> warning: comparison of constant 16 with expression of type 'enum<br>
> cons_type' is always true<br>
> [-Wtautological-constant-out-of-range-compare]<br>
> if ( 0 < ct && ct <= cons_text_c_num ) {;<br>
> ~~ ^ ~~~~~~~~~~~~~~~<br>
> <br>
> It looks like that there are no machines where const char * is more<br>
> that 64-bit. The second check can be removed safely - maybe the<br>
> author of this intended something different?<br>
> <br>
> 2.<br>
> /home/compteam/slave0/build_folder_omp/libiomp-src/runtime/src/kmp_runtime.c:270:58:<br>
> warning: multiple unsequenced modifications to 'gtid'<br>
> [-Wunsequenced]<br>
> if ( __kmp_env_checks == TRUE && !KMP_UBER_GTID(gtid =<br>
> __kmp_gtid_from_thread( th )))<br>
> ^<br>
> /home/compteam/slave0/build_folder_omp/libiomp-src/runtime/src/kmp.h:958:25:<br>
> note: expanded from macro 'KMP_UBER_GTID'<br>
> (__kmp_threads[(gtid)] == __kmp_root[(gtid)]->r.r_uber_thread)\<br>
> ^<br>
> <br>
> gtid here is modified multiple times. We can just move the assignment<br>
> out of the if and have only gtid as parameter of the macro.<br>
> <br>
> <br>
> Below a patch that fixes these problems. Please let me know your<br>
> thoughts on this.<br>
> <br>
> Thanks<br>
> <br>
> -- Carlo<br>
> <br>
> <br>
> <br>
> <br>
> diff --git a/runtime/src/kmp_error.c b/runtime/src/kmp_error.c<br>
> index b76c109..4274365 100644<br>
> --- a/runtime/src/kmp_error.c<br>
> +++ b/runtime/src/kmp_error.c<br>
> @@ -121,7 +121,7 @@ __kmp_pragma(<br>
> kmp_str_buf_t buffer;<br>
> kmp_msg_t prgm;<br>
> __kmp_str_buf_init( & buffer );<br>
> - if ( 0 < ct && ct <= cons_text_c_num ) {;<br>
> + if ( 0 < ct ) {<br>
> cons = cons_text_c[ ct ];<br>
> } else {<br>
> KMP_DEBUG_ASSERT( 0 );<br>
> diff --git a/runtime/src/kmp_runtime.c b/runtime/src/kmp_runtime.c<br>
> index 55b58ce..0a08993 100644<br>
> --- a/runtime/src/kmp_runtime.c<br>
> +++ b/runtime/src/kmp_runtime.c<br>
> @@ -267,7 +267,8 @@ __kmp_check_stack_overlap( kmp_info_t *th )<br>
> }<br>
> <br>
> /* No point in checking ubermaster threads since they use refinement<br>
> and cannot overlap */<br>
> - if ( __kmp_env_checks == TRUE && !KMP_UBER_GTID(gtid =<br>
> __kmp_gtid_from_thread( th )))<br>
> + gtid = __kmp_gtid_from_thread( th );<br>
> + if ( __kmp_env_checks == TRUE && !KMP_UBER_GTID(gtid))<br>
> {<br>
> KA_TRACE(10,("__kmp_check_stack_overlap: performing extensive<br>
> checking\n"));<br>
> if ( stack_beg == NULL ) {<br>
> <br>
> ---------------------------------------------------------------------<br>
> Intel Corporation (UK) Limited<br>
> Registered No. 1134945 (England)<br>
> Registered Office: Pipers Way, Swindon SN3 1RJ<br>
> VAT No: 860 2173 47<br>
> <br>
> This e-mail and any attachments may contain confidential material for<br>
> the sole use of the intended recipient(s). Any review or distribution<br>
> by others is strictly prohibited. If you are not the intended<br>
> recipient, please contact the sender and delete all copies.<br>
> _______________________________________________<br>
> Openmp-dev mailing list<br>
> Openmp-dev@dcs-maillist2.engr.illinois.edu<br>
> </font></tt><tt><font size="2"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/openmp-dev">http://lists.cs.uiuc.edu/mailman/listinfo/openmp-dev</a></font></tt><tt><font size="2"><br>
> <br>
<br>
-- <br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
---------------------------------------------------------------------<br>
Intel Corporation (UK) Limited<br>
Registered No. 1134945 (England)<br>
Registered Office: Pipers Way, Swindon SN3 1RJ<br>
VAT No: 860 2173 47<br>
<br>
This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.<br>
</font></tt><br>
</body></html>