Suppress sparse warnings for global variables initialized in headers.
authorBen Pfaff <blp@nicira.com>
Fri, 6 May 2011 18:38:19 +0000 (11:38 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 16 May 2011 20:40:48 +0000 (13:40 -0700)
sparse warns if a non-static variable with external linkage has an
initializer at first declaration, because it suspects that it should be
static instead.  Generally it's correct, but not in these cases, so add
a redundant declaration to suppress the warning.

The suppress warnings look like:
../ofproto/connmgr.c:40:1: warning: symbol 'VLM_connmgr' was not declared. Should it be static?
../ofproto/collectors.c:31:1: warning: symbol 'vlog_module_ptr_collectors' was not declared. Should it be static?
../ofproto/connmgr.c:43:1: warning: symbol 'counter_ofconn_stuck' was not declared. Should it be static?

lib/coverage.h
lib/stress.h
lib/vlog.h

index d816fb61c73b7d59856b65715165392521093443..b7db6c47043aefddd210f6bdacd08552e9c5022d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ struct coverage_counter {
 #if USE_LINKER_SECTIONS
 #define COVERAGE_DEFINE(COUNTER)                                        \
         COVERAGE_DEFINE__(COUNTER);                                     \
+        extern struct coverage_counter *counter_ptr_##COUNTER;          \
         struct coverage_counter *counter_ptr_##COUNTER                  \
             __attribute__((section("coverage"))) = &counter_##COUNTER
 #else
@@ -60,6 +61,7 @@ void coverage_clear(void);
 
 /* Implementation detail. */
 #define COVERAGE_DEFINE__(COUNTER)                              \
+        extern struct coverage_counter counter_##COUNTER;       \
         struct coverage_counter counter_##COUNTER = { #COUNTER, 0, 0 }
 
 #endif /* coverage.h */
index 4244fca9b43ccdeebbdd2162dadce0ccef312db8..9d6ea97f0793ae4d8e20c998621e8390bfec224f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010 Nicira Networks.
+ * Copyright (c) 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@ struct stress_option {
 #if USE_LINKER_SECTIONS
 #define STRESS_OPTION(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
         STRESS_OPTION__(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT); \
+        extern struct stress_option *stress_option_ptr_##NAME;          \
         struct stress_option *stress_option_ptr_##NAME                  \
             __attribute__((section("stress_options"))) = &stress_##NAME
 #else
@@ -76,6 +77,7 @@ void stress_init_command(void);
 /* Implementation details. */
 
 #define STRESS_OPTION__(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
+        extern struct stress_option stress_##NAME;                      \
         struct stress_option stress_##NAME =                            \
         { #NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT,           \
           DEFAULT ? DEFAULT : 0,                /* period */            \
index 12844c6f7f1715bd26d848be352b6ea2442f2e68..3f40c297dbbe736197a9841e1316777d9a7ff841 100644 (file)
@@ -92,6 +92,7 @@ struct vlog_module {
 #if USE_LINKER_SECTIONS
 #define VLOG_DEFINE_MODULE(MODULE)                                      \
         VLOG_DEFINE_MODULE__(MODULE)                                    \
+        extern struct vlog_module *vlog_module_ptr_##MODULE;            \
         struct vlog_module *vlog_module_ptr_##MODULE                    \
             __attribute__((section("vlog_modules"))) = &VLM_##MODULE
 #else
@@ -258,6 +259,7 @@ void vlog_usage(void);
     } while (0)
 
 #define VLOG_DEFINE_MODULE__(MODULE)                                    \
+        extern struct vlog_module VLM_##MODULE;                         \
         struct vlog_module VLM_##MODULE =                               \
         {                                                               \
             #MODULE,                                      /* name */    \