[Mesa-dev] [PATCH] Cut down false positives when running the Clang Analyzer.

John Kåre Alsaker john.kare.alsaker at gmail.com
Thu Oct 11 21:30:07 PDT 2012


---
 src/gallium/auxiliary/util/u_debug.h  |  2 +-
 src/gallium/include/pipe/p_compiler.h | 12 ++++++++++++
 src/mapi/glapi/gen/gl_table.py        | 14 +++++++++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index ec7d4a0..3f4ec25 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -152,7 +152,7 @@ debug_get_num_option(const char *name, long dfault);
 void _debug_assert_fail(const char *expr, 
                         const char *file, 
                         unsigned line, 
-                        const char *function);
+                        const char *function) ANALYZER_NORETURN;
 
 
 /** 
diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h
index 5958333..e6c67b3 100644
--- a/src/gallium/include/pipe/p_compiler.h
+++ b/src/gallium/include/pipe/p_compiler.h
@@ -90,6 +90,18 @@ typedef unsigned char boolean;
 #endif
 #endif
 
+#ifndef __has_feature
+#  define __has_feature(x) 0
+#endif
+
+#ifndef ANALYZER_NORETURN
+#  if __has_feature(attribute_analyzer_noreturn)
+    #define ANALYZER_NORETURN __attribute__((analyzer_noreturn))
+#  else
+#  define ANALYZER_NORETURN
+#  endif
+#endif
+
 /* Function inlining */
 #ifndef inline
 #  ifdef __cplusplus
diff --git a/src/mapi/glapi/gen/gl_table.py b/src/mapi/glapi/gen/gl_table.py
index 856aedb..018b0da 100644
--- a/src/mapi/glapi/gen/gl_table.py
+++ b/src/mapi/glapi/gen/gl_table.py
@@ -107,10 +107,22 @@ class PrintRemapTable(gl_XML.gl_print_base):
         return
 
     def printBody(self, api):
+        print '#ifndef __has_feature'
+        print '#define __has_feature(x) 0'
+        print '#endif'
+        print ''
+        print '#if __has_feature(attribute_analyzer_noreturn)'
+        print 'static inline _glapi_proc gl_table_null() __attribute__((analyzer_noreturn));'
+        print '#endif'
+        print ''
+        print 'static inline _glapi_proc gl_table_null() {'
+        print '   return NULL;'
+        print '}'
+        print ''
         print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
         print '    (*(cast (GET_by_offset(disp, offset)))) parameters'
         print '#define GET_by_offset(disp, offset) \\'
-        print '    (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
+        print '    (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : gl_table_null()'
         print '#define SET_by_offset(disp, offset, fn) \\'
         print '    do { \\'
         print '        if ( (offset) < 0 ) { \\'
-- 
1.7.12.2



More information about the mesa-dev mailing list