[dpdk-dev,v2] Clang compile error with RTE_LIBRTE_MEMPOOL_DEBUG enabled.

Message ID 3EC8A7DC-C947-40DC-B8FD-60023A12B00A@windriver.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Wiles, Roger Keith Sept. 28, 2014, 5:30 a.m. UTC
  When enabling RTE_LIBRTE_MEMPOOL_DEBUG and compiling with clang
compiler an error occurs, because ifdefed code now includes GCC pragmas.

GCC 4.4 is when push_options and pop_options pragma show up.

Signed-off-by: Keith Wiles <keith.wiles@windriver.com>
---
 lib/librte_mempool/rte_mempool.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Thomas Monjalon Oct. 1, 2014, 12:58 p.m. UTC | #1
2014-09-28 05:30, Wiles, Roger Keith:
> When enabling RTE_LIBRTE_MEMPOOL_DEBUG and compiling with clang
> compiler an error occurs, because ifdefed code now includes GCC pragmas.
> 
> GCC 4.4 is when push_options and pop_options pragma show up.
> 
> Signed-off-by: Keith Wiles <keith.wiles@windriver.com>
[...]
> -#ifndef __INTEL_COMPILER
> +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
>  #pragma GCC push_options
>  #pragma GCC diagnostic ignored "-Wcast-qual"
>  #endif

Does clang accept const casting with -Wcast-qual?

I'd prefer to use the same logic as in rte_mempool.c:
	#pragma GCC diagnostic ignored "-Wcast-qual"
	#pragma GCC diagnostic error "-Wcast-qual"
without using push/pop.
Or if push/pop is really needed, it is implemented in clang:
	http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
  
Wiles, Roger Keith Oct. 1, 2014, 2:57 p.m. UTC | #2
Hi Thomas,

Changing the macros to:

#ifdef RTE_LIBRTE_MEMPOOL_DEBUG
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wcast-qual"
#endif
.
.
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic error "-Wcast-qual"
#endif

Works and is a good solution. I normally do not like negative ‘ifndef’ but it works :-)

Can you make that change if everyone agrees, as would have to remove other changes to that file I want to do in the future to resend this patch. If not I can try and figure it out :-)

Thanks
++Keith

On Oct 1, 2014, at 7:58 AM, Thomas Monjalon <thomas.monjalon@6wind.com> wrote:

> 2014-09-28 05:30, Wiles, Roger Keith:
>> When enabling RTE_LIBRTE_MEMPOOL_DEBUG and compiling with clang
>> compiler an error occurs, because ifdefed code now includes GCC pragmas.
>> 
>> GCC 4.4 is when push_options and pop_options pragma show up.
>> 
>> Signed-off-by: Keith Wiles <keith.wiles@windriver.com>
> [...]
>> -#ifndef __INTEL_COMPILER
>> +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
>> #pragma GCC push_options
>> #pragma GCC diagnostic ignored "-Wcast-qual"
>> #endif
> 
> Does clang accept const casting with -Wcast-qual?
> 
> I'd prefer to use the same logic as in rte_mempool.c:
> 	#pragma GCC diagnostic ignored "-Wcast-qual"
> 	#pragma GCC diagnostic error "-Wcast-qual"
> without using push/pop.
> Or if push/pop is really needed, it is implemented in clang:
> 	http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
> 
> -- 
> Thomas

Keith Wiles, Principal Technologist with CTO office, Wind River mobile 972-213-5533
  
Wiles, Roger Keith Oct. 1, 2014, 5:06 p.m. UTC | #3
Thomas, I will submit a v3 patch in a few minutes.

On Oct 1, 2014, at 9:57 AM, Wiles, Roger Keith <keith.wiles@windriver.com> wrote:

> Hi Thomas,
> 
> Changing the macros to:
> 
> #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
> #ifndef __INTEL_COMPILER
> #pragma GCC diagnostic ignored "-Wcast-qual"
> #endif
> .
> .
> #ifndef __INTEL_COMPILER
> #pragma GCC diagnostic error "-Wcast-qual"
> #endif
> 
> Works and is a good solution. I normally do not like negative ‘ifndef’ but it works :-)
> 
> Can you make that change if everyone agrees, as would have to remove other changes to that file I want to do in the future to resend this patch. If not I can try and figure it out :-)
> 
> Thanks
> ++Keith
> 
> On Oct 1, 2014, at 7:58 AM, Thomas Monjalon <thomas.monjalon@6wind.com> wrote:
> 
>> 2014-09-28 05:30, Wiles, Roger Keith:
>>> When enabling RTE_LIBRTE_MEMPOOL_DEBUG and compiling with clang
>>> compiler an error occurs, because ifdefed code now includes GCC pragmas.
>>> 
>>> GCC 4.4 is when push_options and pop_options pragma show up.
>>> 
>>> Signed-off-by: Keith Wiles <keith.wiles@windriver.com>
>> [...]
>>> -#ifndef __INTEL_COMPILER
>>> +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
>>> #pragma GCC push_options
>>> #pragma GCC diagnostic ignored "-Wcast-qual"
>>> #endif
>> 
>> Does clang accept const casting with -Wcast-qual?
>> 
>> I'd prefer to use the same logic as in rte_mempool.c:
>> 	#pragma GCC diagnostic ignored "-Wcast-qual"
>> 	#pragma GCC diagnostic error "-Wcast-qual"
>> without using push/pop.
>> Or if push/pop is really needed, it is implemented in clang:
>> 	http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
>> 
>> -- 
>> Thomas
> 
> Keith Wiles, Principal Technologist with CTO office, Wind River mobile 972-213-5533
> 

Keith Wiles, Principal Technologist with CTO office, Wind River mobile 972-213-5533
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h
index 95f19f9..558931a 100644
--- a/lib/librte_mempool/rte_mempool.h
+++ b/lib/librte_mempool/rte_mempool.h
@@ -312,7 +312,7 @@  static inline void __mempool_write_trailer_cookie(void *obj)
  *   - 2: just check that cookie is valid (free or allocated)
  */
 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
-#ifndef __INTEL_COMPILER
+#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
 #pragma GCC push_options
 #pragma GCC diagnostic ignored "-Wcast-qual"
 #endif
@@ -379,7 +379,7 @@  static inline void __mempool_check_cookies(const struct rte_mempool *mp,
        }
    }
 }
-#ifndef __INTEL_COMPILER
+#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
 #pragma GCC pop_options
 #endif
 #else