* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-07-30 0:26 ` [PATCH 3/3] Add NOWARN and NOERR compile conditions Tony Camuso
@ 2015-07-30 2:55 ` Josh Triplett
2015-07-30 11:45 ` Tony Camuso
2015-07-31 17:07 ` Tony Camuso
2015-07-31 17:12 ` [PATCH 3/3 V2] lib.c: add Wall_off switch Tony Camuso
` (2 subsequent siblings)
3 siblings, 2 replies; 36+ messages in thread
From: Josh Triplett @ 2015-07-30 2:55 UTC (permalink / raw)
To: Tony Camuso; +Cc: sparse, linux-sparse
On Wed, Jul 29, 2015 at 08:26:41PM -0400, Tony Camuso wrote:
> Allows building sparse to avert reporting semantic problems, e.g.
> using sparse as a tokenizer to create a graph of KABI symbols and
> their dependencies.
>
> Signed-off-by: Tony Camuso <tcamuso@redhat.com>
This doesn't seem like something that should be determined at compile
time. Ideally, this should be determined at runtime.
> lib.c | 21 +++++++++++++++++++++
> parse.c | 12 ++++++++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/lib.c b/lib.c
> index 8dc5bcf..cb10bce 100644
> --- a/lib.c
> +++ b/lib.c
> @@ -48,6 +48,13 @@
> int verbose, optimize, optimize_size, preprocessing;
> int die_if_error = 0;
>
> +#ifdef NOWARN
> +#pragma message "Built with NOWARN"
> +#endif
> +#ifdef NOERR
> +#pragma message "Built with NOERR"
> +#endif
> +
> #ifndef __GNUC__
> # define __GNUC__ 2
> # define __GNUC_MINOR__ 95
> @@ -103,6 +110,9 @@ unsigned int hexval(unsigned int c)
>
> static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
> {
> +#ifdef NOWARN
> + return;
> +#else
> static char buffer[512];
> const char *name;
>
> @@ -111,9 +121,12 @@ static void do_warn(const char *type, struct position pos, const char * fmt, va_
>
> fprintf(stderr, "%s:%d:%d: %s%s\n",
> name, pos.line, pos.pos, type, buffer);
> +#endif
> }
>
> +#ifndef NOWARN
> static int max_warnings = 100;
> +#endif
> static int show_info = 1;
>
> void info(struct position pos, const char * fmt, ...)
> @@ -129,6 +142,9 @@ void info(struct position pos, const char * fmt, ...)
>
> static void do_error(struct position pos, const char * fmt, va_list args)
> {
> +#ifdef NOERR
> + return;
> +#else
> static int errors = 0;
> die_if_error = 1;
> show_info = 1;
> @@ -145,10 +161,14 @@ static void do_error(struct position pos, const char * fmt, va_list args)
>
> do_warn("error: ", pos, fmt, args);
> errors++;
> +#endif
> }
>
> void warning(struct position pos, const char * fmt, ...)
> {
> +#ifdef NOWARN
> + return;
> +#else
> va_list args;
>
> if (Wsparse_error) {
> @@ -171,6 +191,7 @@ void warning(struct position pos, const char * fmt, ...)
> va_start(args, fmt);
> do_warn("warning: ", pos, fmt, args);
> va_end(args);
> +#endif
> }
>
> void sparse_error(struct position pos, const char * fmt, ...)
> diff --git a/parse.c b/parse.c
> index 02275d8..f773fe8 100644
> --- a/parse.c
> +++ b/parse.c
> @@ -44,6 +44,13 @@
> #include "expression.h"
> #include "target.h"
>
> +#ifdef NOWARN
> +#pragma message "Built with NOWARN"
> +#endif
> +#ifdef NOERR
> +#pragma message "Built with NOERR"
> +#endif
> +
> static struct symbol_list **function_symbol_list;
> struct symbol_list *function_computed_target_list;
> struct statement_list *function_computed_goto_list;
> @@ -2746,8 +2753,13 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
>
> /* Just a type declaration? */
> if (!ident) {
> +
> +#if defined NOWARN || defined NOERR
> + return token->next;
> +#else
> warning(token->pos, "missing identifier in declaration");
> return expect(token, ';', "at the end of type declaration");
> +#endif
> }
>
> /* type define declaration? */
> --
> 2.4.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-07-30 2:55 ` Josh Triplett
@ 2015-07-30 11:45 ` Tony Camuso
2015-07-31 23:46 ` Christopher Li
2015-07-31 17:07 ` Tony Camuso
1 sibling, 1 reply; 36+ messages in thread
From: Tony Camuso @ 2015-07-30 11:45 UTC (permalink / raw)
To: Josh Triplett; +Cc: sparse, linux-sparse
On 07/29/2015 10:55 PM, Josh Triplett wrote:
> On Wed, Jul 29, 2015 at 08:26:41PM -0400, Tony Camuso wrote:
>> Allows building sparse to avert reporting semantic problems, e.g.
>> using sparse as a tokenizer to create a graph of KABI symbols and
>> their dependencies.
>>
>> Signed-off-by: Tony Camuso <tcamuso@redhat.com>
>
> This doesn't seem like something that should be determined at compile
> time. Ideally, this should be determined at runtime.
I thought it would be less intrusive, since I don't know how useful
this would be to others.
If you prefer a switch, I will do that.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-07-30 11:45 ` Tony Camuso
@ 2015-07-31 23:46 ` Christopher Li
2015-08-01 11:09 ` Tony Camuso
0 siblings, 1 reply; 36+ messages in thread
From: Christopher Li @ 2015-07-31 23:46 UTC (permalink / raw)
To: Tony Camuso; +Cc: Josh Triplett, Linux-Sparse
On Thu, Jul 30, 2015 at 4:45 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>
> I thought it would be less intrusive, since I don't know how useful
> this would be to others.
>
> If you prefer a switch, I will do that.
I agree that this should be run time behavior.
+
+#if defined NOWARN || defined NOERR
+ return token->next;
+#else
What is up with this change? It is not output warning or not.
It affect the parsing as well. If sparse can't bail out properly,
this should be a separate patch.
Chris
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-07-31 23:46 ` Christopher Li
@ 2015-08-01 11:09 ` Tony Camuso
2015-08-01 17:52 ` Josh Triplett
2015-08-01 18:45 ` Christopher Li
0 siblings, 2 replies; 36+ messages in thread
From: Tony Camuso @ 2015-08-01 11:09 UTC (permalink / raw)
To: Christopher Li; +Cc: Josh Triplett, Linux-Sparse
On 07/31/2015 07:46 PM, Christopher Li wrote:
> On Thu, Jul 30, 2015 at 4:45 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>>
>> I thought it would be less intrusive, since I don't know how useful
>> this would be to others.
>>
>> If you prefer a switch, I will do that.
>
> I agree that this should be run time behavior.
>
> +
> +#if defined NOWARN || defined NOERR
> + return token->next;
> +#else
>
> What is up with this change? It is not output warning or not.
> It affect the parsing as well. If sparse can't bail out properly,
> this should be a separate patch.
>
> Chris
>
Hi, Chris.
I've since submitted a runtime patch (3/3 V3) with a switch as a
response to this patch, but it basically does the same thing here.
Consider the case where the source contains something like this...
struct foo {
union {
int number;
int *pointer;
};
};
There being no ident for the union within the struct, we get the warning,
"missing identifier in declaration" etc.
Code without the patch.
/* Just a type declaration? */
if (!ident) {
warning(token->pos, "missing identifier in declaration");
return expect(token, ';', "at the end of type declaration");
}
Regards,
Tony
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-01 11:09 ` Tony Camuso
@ 2015-08-01 17:52 ` Josh Triplett
2015-08-01 18:45 ` Christopher Li
1 sibling, 0 replies; 36+ messages in thread
From: Josh Triplett @ 2015-08-01 17:52 UTC (permalink / raw)
To: Tony Camuso; +Cc: Christopher Li, Linux-Sparse
On Sat, Aug 01, 2015 at 07:09:06AM -0400, Tony Camuso wrote:
> On 07/31/2015 07:46 PM, Christopher Li wrote:
> >On Thu, Jul 30, 2015 at 4:45 AM, Tony Camuso <tcamuso@redhat.com> wrote:
> >>
> >>I thought it would be less intrusive, since I don't know how useful
> >>this would be to others.
> >>
> >>If you prefer a switch, I will do that.
> >
> >I agree that this should be run time behavior.
> >
> >+
> >+#if defined NOWARN || defined NOERR
> >+ return token->next;
> >+#else
> >
> >What is up with this change? It is not output warning or not.
> >It affect the parsing as well. If sparse can't bail out properly,
> >this should be a separate patch.
> >
> >Chris
> >
>
> Hi, Chris.
>
> I've since submitted a runtime patch (3/3 V3) with a switch as a
> response to this patch, but it basically does the same thing here.
>
> Consider the case where the source contains something like this...
>
> struct foo {
> union {
> int number;
> int *pointer;
> };
> };
>
> There being no ident for the union within the struct, we get the warning,
> "missing identifier in declaration" etc.
If so, that's actually a bug in Sparse; anonymous unions should be
allowed without warning:
$ cat test.c
struct foo {
union {
int number;
int *pointer;
};
};
$ gcc -Wall -Wextra -c test.c -o /dev/null
$
They have a well-defined semantic meaning, and they're standardized in
C11, just not in C89 or C99.
- Josh Triplett
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-01 11:09 ` Tony Camuso
2015-08-01 17:52 ` Josh Triplett
@ 2015-08-01 18:45 ` Christopher Li
2015-08-02 13:42 ` Tony Camuso
` (2 more replies)
1 sibling, 3 replies; 36+ messages in thread
From: Christopher Li @ 2015-08-01 18:45 UTC (permalink / raw)
To: Tony Camuso; +Cc: Josh Triplett, Linux-Sparse
On Sat, Aug 1, 2015 at 4:09 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>
> I've since submitted a runtime patch (3/3 V3) with a switch as a
> response to this patch, but it basically does the same thing here.
>
> Consider the case where the source contains something like this...
>
> struct foo {
> union {
> int number;
> int *pointer;
> };
> };
>
> There being no ident for the union within the struct, we get the warning,
> "missing identifier in declaration" etc.
>
I can't reproduce the warning with the chrisl repo master branch.
That being said, if there is indeed a bug in sparse, it should be a
separate patch. It changes the parsing behavior.
Thanks
Chris
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-01 18:45 ` Christopher Li
@ 2015-08-02 13:42 ` Tony Camuso
2015-08-02 23:16 ` Tony Camuso
2015-08-02 23:22 ` Tony Camuso
2 siblings, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2015-08-02 13:42 UTC (permalink / raw)
To: Christopher Li; +Cc: Josh Triplett, Linux-Sparse
On 08/01/2015 02:45 PM, Christopher Li wrote:
> On Sat, Aug 1, 2015 at 4:09 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>>
>> I've since submitted a runtime patch (3/3 V3) with a switch as a
>> response to this patch, but it basically does the same thing here.
>>
>> Consider the case where the source contains something like this...
>>
>> struct foo {
>> union {
>> int number;
>> int *pointer;
>> };
>> };
>>
>> There being no ident for the union within the struct, we get the warning,
>> "missing identifier in declaration" etc.
>>
>
> I can't reproduce the warning with the chrisl repo master branch.
>
> That being said, if there is indeed a bug in sparse, it should be a
> separate patch. It changes the parsing behavior.
>
> Thanks
>
> Chris
>
I'll isolate exactly where the report is coming from, but it is tripping
over this in parse.c
warning(token->pos, "missing identifier in declaration");
return expect(token, ';', "at the end of type declaration");
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-01 18:45 ` Christopher Li
2015-08-02 13:42 ` Tony Camuso
@ 2015-08-02 23:16 ` Tony Camuso
2015-08-02 23:22 ` Tony Camuso
2 siblings, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2015-08-02 23:16 UTC (permalink / raw)
To: Christopher Li; +Cc: Josh Triplett, Linux-Sparse
On 08/01/2015 02:45 PM, Christopher Li wrote:
> On Sat, Aug 1, 2015 at 4:09 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>>
>> I've since submitted a runtime patch (3/3 V3) with a switch as a
>> response to this patch, but it basically does the same thing here.
>>
>> Consider the case where the source contains something like this...
>>
>> struct foo {
>> union {
>> int number;
>> int *pointer;
>> };
>> };
>>
>> There being no ident for the union within the struct, we get the warning,
>> "missing identifier in declaration" etc.
>>
>
> I can't reproduce the warning with the chrisl repo master branch.
>
> That being said, if there is indeed a bug in sparse, it should be a
> separate patch. It changes the parsing behavior.
>
> Thanks
>
> Chris
>
This doubt this is a sparse bug. It is an most likely caused by some RHEL
specific macros with encapsulated anonymous unions devised to protect the
Kernel Application Binary Interface while backporting upstream changes
from point release to point release. I can try to convince the KABI macro
maintainers to make their macros sparse-compliant, but I'm hoping you agree
that it might not be a bad idea to provide an option to disable the sparse
error reporting in the meantime.
If you're interested in pursuing this further, these are the errors I'm
seeing, followed by the source that generates them.
/work/linux/fs/bio.i:9137:130: error: Expected ) in function declarator
/work/linux/fs/bio.i:9137:130: error: got (
builtin:0:0: error: expected ; at end of declaration
builtin:0:0: error: expected ; at end of declaration
builtin:0:0: error: expected ; at end of declaration
/work/linux/fs/bio.i:9137:172: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9137:172: error: got }
/work/linux/fs/bio.i:9137:209: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9137:209: error: got }
/work/linux/fs/bio.i:9137:266: error: Expected ) in function declarator
/work/linux/fs/bio.i:9137:266: error: got (
/work/linux/fs/bio.i:9137:308: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9137:308: error: got }
/work/linux/fs/bio.i:9137:350: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9137:350: error: got }
/work/linux/fs/bio.i:9137:382: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9137:382: error: got }
/work/linux/fs/bio.i:9137:385: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9137:385: error: got }
/work/linux/fs/bio.i:9139:1: error: Expected ; at the end of type declaration
/work/linux/fs/bio.i:9139:1: error: got }
The anonymous unions giving us those error messages are encapsulated
in a RHEL-specific macro.
# define _RH_KABI_REPLACE(_orig, _new) \
union { \
_new; \
struct { \
_orig; \
} __UNIQUE_ID(rh_kabi_hide); \
__RH_KABI_CHECK_SIZE_ALIGN(_orig, _new); \
}
Here's an example of the macro invocation.
RH_KABI_REPLACE(void *spin_mlock, /* Spinner MCS lock */
struct optimistic_spin_queue *osq) /* Spinner MCS lock */
The preprocessor expands it as follows.
union { struct optimistic_spin_queue *osq; struct { void *spin_mlock; } __UNIQUE_ID_rh_kabi_hide0; union { _Static_assert(sizeof(struct{struct optimistic_spin_queue *osq;}) <= sizeof(struct{void * spin_mlock;}), "kabi sizeof test panic"); _Static_assert(__alignof__(struct{struct optimistic_spin_queue *osq;}) <= __alignof__(struct{void *spin_mlock;}), "kabi alignof test panic"); }; };
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-01 18:45 ` Christopher Li
2015-08-02 13:42 ` Tony Camuso
2015-08-02 23:16 ` Tony Camuso
@ 2015-08-02 23:22 ` Tony Camuso
2015-08-03 11:23 ` Nicolai Stange
2 siblings, 1 reply; 36+ messages in thread
From: Tony Camuso @ 2015-08-02 23:22 UTC (permalink / raw)
To: Christopher Li; +Cc: Josh Triplett, Linux-Sparse
On 08/01/2015 02:45 PM, Christopher Li wrote:
> On Sat, Aug 1, 2015 at 4:09 AM, Tony Camuso <tcamuso@redhat.com> wrote:
>>
>> I've since submitted a runtime patch (3/3 V3) with a switch as a
>> response to this patch, but it basically does the same thing here.
>>
>> Consider the case where the source contains something like this...
>>
>> struct foo {
>> union {
>> int number;
>> int *pointer;
>> };
>> };
>>
>> There being no ident for the union within the struct, we get the warning,
>> "missing identifier in declaration" etc.
>>
>
> I can't reproduce the warning with the chrisl repo master branch.
>
> That being said, if there is indeed a bug in sparse, it should be a
> separate patch. It changes the parsing behavior.
>
> Thanks
>
> Chris
>
Here's one that might be a sparse bug.
/work/linux/fs/bio.i:5368:26: error: Expected ) at end of cast operator
/work/linux/fs/bio.i:5368:26: error: got __int128
Here is the kernel source in include/linux/math64.h that causes the error.
static inline __attribute__((no_instrument_function)) u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift)
{
return (u64)(((unsigned __int128)a * mul) >> shift);
}
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-02 23:22 ` Tony Camuso
@ 2015-08-03 11:23 ` Nicolai Stange
2015-08-03 11:47 ` Tony Camuso
0 siblings, 1 reply; 36+ messages in thread
From: Nicolai Stange @ 2015-08-03 11:23 UTC (permalink / raw)
To: Tony Camuso; +Cc: Christopher Li, Josh Triplett, Linux-Sparse
Hi Tony,
Tony Camuso <tcamuso@redhat.com> writes:
> Here's one that might be a sparse bug.
>
> /work/linux/fs/bio.i:5368:26: error: Expected ) at end of cast operator
> /work/linux/fs/bio.i:5368:26: error: got __int128
>
> Here is the kernel source in include/linux/math64.h that causes the error.
>
> static inline __attribute__((no_instrument_function)) u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift)
> {
> return (u64)(((unsigned __int128)a * mul) >> shift);
> }
This one is probably triggered by running sparse on gcc -E output.
The mul_u64_u32_shr() implementation cited by you is protected by a
#if ... && defined(__SIZEOF_INT128__)
in include/linux/math64.h
__SIZEOF_INT128__ is #define'd by gcc but not by sparse.
The reason for your parsing error messages is probably that
declaration_specifiers() does not eat up the __int128, leaving this one
to cast_expression().
Could you please confirm that you did indeed run sparse on gcc -E
output?
Thank you,
Nicolai
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-08-03 11:23 ` Nicolai Stange
@ 2015-08-03 11:47 ` Tony Camuso
0 siblings, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2015-08-03 11:47 UTC (permalink / raw)
To: Nicolai Stange; +Cc: Christopher Li, Josh Triplett, Linux-Sparse
On 08/03/2015 07:23 AM, Nicolai Stange wrote:
> Hi Tony,
>
> Tony Camuso <tcamuso@redhat.com> writes:
>> Here's one that might be a sparse bug.
>>
>> /work/linux/fs/bio.i:5368:26: error: Expected ) at end of cast operator
>> /work/linux/fs/bio.i:5368:26: error: got __int128
>>
>> Here is the kernel source in include/linux/math64.h that causes the error.
>>
>> static inline __attribute__((no_instrument_function)) u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift)
>> {
>> return (u64)(((unsigned __int128)a * mul) >> shift);
>> }
>
> This one is probably triggered by running sparse on gcc -E output.
>
> The mul_u64_u32_shr() implementation cited by you is protected by a
> #if ... && defined(__SIZEOF_INT128__)
> in include/linux/math64.h
>
> __SIZEOF_INT128__ is #define'd by gcc but not by sparse.
>
>
> The reason for your parsing error messages is probably that
> declaration_specifiers() does not eat up the __int128, leaving this one
> to cast_expression().
>
> Could you please confirm that you did indeed run sparse on gcc -E
> output?
>
> Thank you,
>
> Nicolai
Yes, we are using -E to generate preprocessor output.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3] Add NOWARN and NOERR compile conditions
2015-07-30 2:55 ` Josh Triplett
2015-07-30 11:45 ` Tony Camuso
@ 2015-07-31 17:07 ` Tony Camuso
1 sibling, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2015-07-31 17:07 UTC (permalink / raw)
To: Josh Triplett; +Cc: sparse, linux-sparse
On 07/29/2015 10:55 PM, Josh Triplett wrote:
> On Wed, Jul 29, 2015 at 08:26:41PM -0400, Tony Camuso wrote:
>> Allows building sparse to avert reporting semantic problems, e.g.
>> using sparse as a tokenizer to create a graph of KABI symbols and
>> their dependencies.
>>
>> Signed-off-by: Tony Camuso <tcamuso@redhat.com>
>
> This doesn't seem like something that should be determined at compile
> time. Ideally, this should be determined at runtime.
>
I will be sending the new patch as a reply to the original, though the
subject line is different, because I'm using the input switches instead
of build-time constants.
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH 3/3 V2] lib.c: add Wall_off switch
2015-07-30 0:26 ` [PATCH 3/3] Add NOWARN and NOERR compile conditions Tony Camuso
2015-07-30 2:55 ` Josh Triplett
@ 2015-07-31 17:12 ` Tony Camuso
2015-07-31 18:01 ` Tony Camuso
2015-07-31 19:27 ` [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings Tony Camuso
2015-08-03 16:35 ` [PATCH 3/3 v4] " Tony Camuso
3 siblings, 1 reply; 36+ messages in thread
From: Tony Camuso @ 2015-07-31 17:12 UTC (permalink / raw)
To: josh, linux-sparse; +Cc: tcamuso, sparse
Disables all warning and error reporting for using sparse as a
tokenizer only.
Signed-off-by: Tony Camuso <tcamuso@redhat.com>
---
lib.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib.c b/lib.c
index 8dc5bcf..c274a68 100644
--- a/lib.c
+++ b/lib.c
@@ -241,6 +241,7 @@ int Wtypesign = 0;
int Wundef = 0;
int Wuninitialized = 1;
int Wvla = 1;
+int Wall_off = 0;
int dbg_entry = 0;
int dbg_dead = 0;
@@ -464,6 +465,7 @@ static const struct warning {
{ "undef", &Wundef },
{ "uninitialized", &Wuninitialized },
{ "vla", &Wvla },
+ { "all_off", &Wall_off },
};
enum {
@@ -479,6 +481,12 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w
char *p = arg + 1;
unsigned i;
+ if (!strcmp(p, "all_off")) {
+ for (i = 0; i < n; i++)
+ *warnings[i].flag = WARNING_FORCE_OFF;
+ return NULL;
+ }
+
if (!strcmp(p, "sparse-all")) {
for (i = 0; i < n; i++) {
if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
--
2.4.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3 V2] lib.c: add Wall_off switch
2015-07-31 17:12 ` [PATCH 3/3 V2] lib.c: add Wall_off switch Tony Camuso
@ 2015-07-31 18:01 ` Tony Camuso
0 siblings, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2015-07-31 18:01 UTC (permalink / raw)
To: josh, linux-sparse; +Cc: sparse
On 07/31/2015 01:12 PM, Tony Camuso wrote:
> Disables all warning and error reporting for using sparse as a
> tokenizer only.
>
> Signed-off-by: Tony Camuso <tcamuso@redhat.com>
Spoke too soon ..
NAK
I'll send an update when I have something that really works.
> ---
> lib.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/lib.c b/lib.c
> index 8dc5bcf..c274a68 100644
> --- a/lib.c
> +++ b/lib.c
> @@ -241,6 +241,7 @@ int Wtypesign = 0;
> int Wundef = 0;
> int Wuninitialized = 1;
> int Wvla = 1;
> +int Wall_off = 0;
>
> int dbg_entry = 0;
> int dbg_dead = 0;
> @@ -464,6 +465,7 @@ static const struct warning {
> { "undef", &Wundef },
> { "uninitialized", &Wuninitialized },
> { "vla", &Wvla },
> + { "all_off", &Wall_off },
> };
>
> enum {
> @@ -479,6 +481,12 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w
> char *p = arg + 1;
> unsigned i;
>
> + if (!strcmp(p, "all_off")) {
> + for (i = 0; i < n; i++)
> + *warnings[i].flag = WARNING_FORCE_OFF;
> + return NULL;
> + }
> +
> if (!strcmp(p, "sparse-all")) {
> for (i = 0; i < n; i++) {
> if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings
2015-07-30 0:26 ` [PATCH 3/3] Add NOWARN and NOERR compile conditions Tony Camuso
2015-07-30 2:55 ` Josh Triplett
2015-07-31 17:12 ` [PATCH 3/3 V2] lib.c: add Wall_off switch Tony Camuso
@ 2015-07-31 19:27 ` Tony Camuso
2015-08-01 12:59 ` Sam Ravnborg
2015-08-03 16:35 ` [PATCH 3/3 v4] " Tony Camuso
3 siblings, 1 reply; 36+ messages in thread
From: Tony Camuso @ 2015-07-31 19:27 UTC (permalink / raw)
To: josh, linux-sparse; +Cc: tcamuso, sparse
For using sparse as a tokenizer only. While it still parses semantics,
it doesn't report any semantic errors, which is undesirable for some
tasks like locating the KABI associations in a kernel source file.
Signed-off-by: Tony Camuso <tcamuso@redhat.com>
---
lib.c | 20 +++++++++++++++++++-
lib.h | 1 +
parse.c | 4 ++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/lib.c b/lib.c
index 8dc5bcf..ef182ae 100644
--- a/lib.c
+++ b/lib.c
@@ -103,6 +103,9 @@ unsigned int hexval(unsigned int c)
static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
{
+ if (Wall_off)
+ return;
+
static char buffer[512];
const char *name;
@@ -120,7 +123,7 @@ void info(struct position pos, const char * fmt, ...)
{
va_list args;
- if (!show_info)
+ if (!show_info || Wall_off)
return;
va_start(args, fmt);
do_warn("", pos, fmt, args);
@@ -129,6 +132,9 @@ void info(struct position pos, const char * fmt, ...)
static void do_error(struct position pos, const char * fmt, va_list args)
{
+ if (Wall_off)
+ return;
+
static int errors = 0;
die_if_error = 1;
show_info = 1;
@@ -151,6 +157,9 @@ void warning(struct position pos, const char * fmt, ...)
{
va_list args;
+ if (Wall_off)
+ return;
+
if (Wsparse_error) {
va_start(args, fmt);
do_error(pos, fmt, args);
@@ -241,6 +250,7 @@ int Wtypesign = 0;
int Wundef = 0;
int Wuninitialized = 1;
int Wvla = 1;
+int Wall_off = 0;
int dbg_entry = 0;
int dbg_dead = 0;
@@ -464,6 +474,7 @@ static const struct warning {
{ "undef", &Wundef },
{ "uninitialized", &Wuninitialized },
{ "vla", &Wvla },
+ { "all_off", &Wall_off },
};
enum {
@@ -479,6 +490,13 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w
char *p = arg + 1;
unsigned i;
+ if (!strcmp(p, "all_off")) {
+ for (i = 0; i < n; i++)
+ *warnings[i].flag = WARNING_FORCE_OFF;
+ Wall_off = 1;
+ return NULL;
+ }
+
if (!strcmp(p, "sparse-all")) {
for (i = 0; i < n; i++) {
if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
diff --git a/lib.h b/lib.h
index 15b69fa..65e4836 100644
--- a/lib.h
+++ b/lib.h
@@ -127,6 +127,7 @@ extern int Wtypesign;
extern int Wundef;
extern int Wuninitialized;
extern int Wvla;
+extern int Wall_off;
extern int dbg_entry;
extern int dbg_dead;
diff --git a/parse.c b/parse.c
index 02275d8..d70dffb 100644
--- a/parse.c
+++ b/parse.c
@@ -2746,6 +2746,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
/* Just a type declaration? */
if (!ident) {
+
+ if (Wall_off)
+ return token->next;
+
warning(token->pos, "missing identifier in declaration");
return expect(token, ';', "at the end of type declaration");
}
--
2.4.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings
2015-07-31 19:27 ` [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings Tony Camuso
@ 2015-08-01 12:59 ` Sam Ravnborg
2015-08-01 13:52 ` Tony Camuso
0 siblings, 1 reply; 36+ messages in thread
From: Sam Ravnborg @ 2015-08-01 12:59 UTC (permalink / raw)
To: Tony Camuso; +Cc: josh, linux-sparse, sparse
> diff --git a/parse.c b/parse.c
> index 02275d8..d70dffb 100644
> --- a/parse.c
> +++ b/parse.c
> @@ -2746,6 +2746,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
>
> /* Just a type declaration? */
> if (!ident) {
> +
> + if (Wall_off)
> + return token->next;
> +
> warning(token->pos, "missing identifier in declaration");
> return expect(token, ';', "at the end of type declaration");
This is on the wrong level.
You need to silence sparse in the spare_error function.
Not on the level where you do the expect() - otherwise you would
have to sprinkle "if (Wall_off)" checks everywhere.
This was also a problem in v1 of the patch.
Sam
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings
2015-08-01 12:59 ` Sam Ravnborg
@ 2015-08-01 13:52 ` Tony Camuso
0 siblings, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2015-08-01 13:52 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: josh, linux-sparse, sparse
On 08/01/2015 08:59 AM, Sam Ravnborg wrote:
>> diff --git a/parse.c b/parse.c
>> index 02275d8..d70dffb 100644
>> --- a/parse.c
>> +++ b/parse.c
>> @@ -2746,6 +2746,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
>>
>> /* Just a type declaration? */
>> if (!ident) {
>> +
>> + if (Wall_off)
>> + return token->next;
>> +
>> warning(token->pos, "missing identifier in declaration");
>> return expect(token, ';', "at the end of type declaration");
>
> This is on the wrong level.
> You need to silence sparse in the spare_error function.
>
> Not on the level where you do the expect() - otherwise you would
> have to sprinkle "if (Wall_off)" checks everywhere.
>
> This was also a problem in v1 of the patch.
>
> Sam
>
Thanks, Sam. Rework in progress ...
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH 3/3 v4] Add Wall_off switch to disable errors and warnings
2015-07-30 0:26 ` [PATCH 3/3] Add NOWARN and NOERR compile conditions Tony Camuso
` (2 preceding siblings ...)
2015-07-31 19:27 ` [PATCH 3/3 V3] Add Wall_off switch to disable errors and warnings Tony Camuso
@ 2015-08-03 16:35 ` Tony Camuso
2016-01-05 1:19 ` Luc Van Oostenryck
3 siblings, 1 reply; 36+ messages in thread
From: Tony Camuso @ 2015-08-03 16:35 UTC (permalink / raw)
To: sam, linux-sparse; +Cc: josh, sparse, tcamuso
Disable all error reporting. Useful when semantic parsing checks are
being done elsewhere or all you need is a tokenizer.
Signed-off-by: Tony Camuso <tcamuso@redhat.com>
---
lib.c | 27 +++++++++++++++++++++++----
lib.h | 1 +
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/lib.c b/lib.c
index 8dc5bcf..08f6a6b 100644
--- a/lib.c
+++ b/lib.c
@@ -101,21 +101,26 @@ unsigned int hexval(unsigned int c)
return retval;
}
+static int max_warnings = 100;
+static int show_info = 1;
+
static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
{
static char buffer[512];
const char *name;
- vsprintf(buffer, fmt, args);
+ if (Wall_off) {
+ max_warnings = 0;
+ return;
+ }
+
+ vsprintf(buffer, fmt, args);
name = stream_name(pos.stream);
fprintf(stderr, "%s:%d:%d: %s%s\n",
name, pos.line, pos.pos, type, buffer);
}
-static int max_warnings = 100;
-static int show_info = 1;
-
void info(struct position pos, const char * fmt, ...)
{
va_list args;
@@ -130,6 +135,12 @@ void info(struct position pos, const char * fmt, ...)
static void do_error(struct position pos, const char * fmt, va_list args)
{
static int errors = 0;
+
+ if (Wall_off) {
+ max_warnings = 0;
+ return;
+ }
+
die_if_error = 1;
show_info = 1;
/* Shut up warnings after an error */
@@ -241,6 +252,7 @@ int Wtypesign = 0;
int Wundef = 0;
int Wuninitialized = 1;
int Wvla = 1;
+int Wall_off = 0;
int dbg_entry = 0;
int dbg_dead = 0;
@@ -479,6 +491,13 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w
char *p = arg + 1;
unsigned i;
+ if (!strcmp(p, "all_off")) {
+ for (i = 0; i < n; i++)
+ *warnings[i].flag = WARNING_FORCE_OFF;
+ Wall_off = 1;
+ return NULL;
+ }
+
if (!strcmp(p, "sparse-all")) {
for (i = 0; i < n; i++) {
if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
diff --git a/lib.h b/lib.h
index 15b69fa..65e4836 100644
--- a/lib.h
+++ b/lib.h
@@ -127,6 +127,7 @@ extern int Wtypesign;
extern int Wundef;
extern int Wuninitialized;
extern int Wvla;
+extern int Wall_off;
extern int dbg_entry;
extern int dbg_dead;
--
2.4.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3 v4] Add Wall_off switch to disable errors and warnings
2015-08-03 16:35 ` [PATCH 3/3 v4] " Tony Camuso
@ 2016-01-05 1:19 ` Luc Van Oostenryck
2016-01-13 14:39 ` Tony Camuso
0 siblings, 1 reply; 36+ messages in thread
From: Luc Van Oostenryck @ 2016-01-05 1:19 UTC (permalink / raw)
To: Tony Camuso; +Cc: sam, linux-sparse, josh, sparse
On Mon, Aug 03, 2015 at 12:35:59PM -0400, Tony Camuso wrote:
> Disable all error reporting. Useful when semantic parsing checks are
> being done elsewhere or all you need is a tokenizer.
>
> Signed-off-by: Tony Camuso <tcamuso@redhat.com>
> ---
> lib.c | 27 +++++++++++++++++++++++----
> lib.h | 1 +
> 2 files changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/lib.c b/lib.c
> index 8dc5bcf..08f6a6b 100644
> --- a/lib.c
> +++ b/lib.c
...
> @@ -130,6 +135,12 @@ void info(struct position pos, const char * fmt, ...)
> static void do_error(struct position pos, const char * fmt, va_list args)
> {
> static int errors = 0;
> +
> + if (Wall_off) {
> + max_warnings = 0;
> + return;
> + }
> +
Is this really needed?
The same check in do_warn should be enough to quiet all messages, isn't it?
> @@ -479,6 +491,13 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w
> char *p = arg + 1;
> unsigned i;
>
> + if (!strcmp(p, "all_off")) {
> + for (i = 0; i < n; i++)
> + *warnings[i].flag = WARNING_FORCE_OFF;
> + Wall_off = 1;
> + return NULL;
> + }
> +
Can't you simply set max_warnings to 0 already here
instead of doing it in do_warn()?
> @@ -127,6 +127,7 @@ extern int Wtypesign;
> extern int Wundef;
> extern int Wuninitialized;
> extern int Wvla;
> +extern int Wall_off;
I think it should be better to use a much more explicit name,
something like "ignore_all_warnings" for example.
Also it would be nice to document this new option in the man page.
Regards,
Luc
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 3/3 v4] Add Wall_off switch to disable errors and warnings
2016-01-05 1:19 ` Luc Van Oostenryck
@ 2016-01-13 14:39 ` Tony Camuso
0 siblings, 0 replies; 36+ messages in thread
From: Tony Camuso @ 2016-01-13 14:39 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: sam, linux-sparse, josh, sparse
On 01/04/2016 08:19 PM, Luc Van Oostenryck wrote:
> On Mon, Aug 03, 2015 at 12:35:59PM -0400, Tony Camuso wrote:
>> Disable all error reporting. Useful when semantic parsing checks are
>> being done elsewhere or all you need is a tokenizer.
>>
>> Signed-off-by: Tony Camuso <tcamuso@redhat.com>
>> ---
>> lib.c | 27 +++++++++++++++++++++++----
>> lib.h | 1 +
>> 2 files changed, 24 insertions(+), 4 deletions(-)
>>
>> diff --git a/lib.c b/lib.c
>> index 8dc5bcf..08f6a6b 100644
>> --- a/lib.c
>> +++ b/lib.c
>
> ...
>
>> @@ -130,6 +135,12 @@ void info(struct position pos, const char * fmt, ...)
>> static void do_error(struct position pos, const char * fmt, va_list args)
>> {
>> static int errors = 0;
>> +
>> + if (Wall_off) {
>> + max_warnings = 0;
>> + return;
>> + }
>> +
>
> Is this really needed?
> The same check in do_warn should be enough to quiet all messages, isn't it?
I'll test again to be certain, but IIRC, I needed it there, too.
If I don't need it there, I will drop it in a new version of the
patch.
>
>> @@ -479,6 +491,13 @@ static char **handle_onoff_switch(char *arg, char **next, const struct warning w
>> char *p = arg + 1;
>> unsigned i;
>>
>> + if (!strcmp(p, "all_off")) {
>> + for (i = 0; i < n; i++)
>> + *warnings[i].flag = WARNING_FORCE_OFF;
>> + Wall_off = 1;
>> + return NULL;
>> + }
>> +
>
> Can't you simply set max_warnings to 0 already here
> instead of doing it in do_warn()?
Yes, I will do that. It does make more sense in that block.
>> @@ -127,6 +127,7 @@ extern int Wtypesign;
>> extern int Wundef;
>> extern int Wuninitialized;
>> extern int Wvla;
>> +extern int Wall_off;
>
> I think it should be better to use a much more explicit name,
> something like "ignore_all_warnings" for example.
Also will do that.
> Also it would be nice to document this new option in the man page.
I'll add this to the patch.
>
> Regards,
> Luc
>
Ciao,
Tony
^ permalink raw reply [flat|nested] 36+ messages in thread