Skip to contentSkip to conversation

Fun with Linux 2.6.21-rc1

DISCUSSION Applied Pavel Roskin 3 participants 6 messages Feb 23, 2007 – Feb 26, 2007 Sparse checker

lore
Share & tools
lore
#0 lore raw

Hello!

The current sparse reports many errors with Linux 2.6.21-rc1. There are screenfuls of errors for every file. I have reduced one of them to this simple file:

struct st {
	char c;
} __attribute__ ((aligned(2)));

struct st s1;
struct st s2;

$ sparse test.c 
test.c:5:18: error: Expected ( after asm
test.c:5:18: error: got s2
test.c:5:20: error: Expected ) after asm
test.c:5:20: error: got ;
builtin:0:0: error: expected declaration

The strange thing is that there is no "asm" here at all.

Signature · 2 lines
Regards,
Pavel Roskin
#1 lore raw
Quoted 11 lines · Pavel Roskin

Hello!

The current sparse reports many errors with Linux 2.6.21-rc1. There are screenfuls of errors for every file. I have reduced one of them to this simple file:

struct st {
	char c;
} __attribute__ ((aligned(2)));

struct st s1;
struct st s2;

P.S. The breakage has nothing to do to Linux changes. It was caused by the patch called "Make the ptrlist using the sparse allocator". Undoing the patch fixes the problem.

Signature · 2 lines
Regards,
Pavel Roskin
maintainer
#2 lore raw
Quoted 4 lines · Pavel Roskin

P.S. The breakage has nothing to do to Linux changes. It was caused by the patch called "Make the ptrlist using the sparse allocator". Undoing the patch fixes the problem.

No, that was not it. The bug does not trigger if I remove "-O" or remove the recent struct attribute patch.

You make me guilt for 5 mins. But the real bugs is match_idents did not end with NULL.

This patch should fix it:

Chris

Fix a bug that match_idents forget to end with NULL

Pavel Roskin manage to hit this bug with

struct st {
       char c;
} __attribute__ ((aligned(2)));

struct st s1;
struct st s2;

parse.c +1 -1
Index: sparse/parse.c
===================================================================
@@ -861,7 +861,7 @@ static struct token *handle_attributes(s
 			apply_ctype(token->pos, &thistype, ctype);
 			continue;
 		}
-		if (match_idents(token, &asm_ident, &__asm_ident, &__asm___ident)) {
+		if (match_idents(token, &asm_ident, &__asm_ident, &__asm___ident, NULL)) {
 			struct expression *expr;
 			token = expect(token->next, '(', "after asm");
 			token = parse_expression(token->next, &expr);
#3 lore raw
Quoted 11 lines · Christopher Li
Quoted 4 lines · Pavel Roskin

P.S. The breakage has nothing to do to Linux changes. It was caused by the patch called "Make the ptrlist using the sparse allocator". Undoing the patch fixes the problem.

No, that was not it. The bug does not trigger if I remove "-O" or remove the recent struct attribute patch.

You make me guilt for 5 mins. But the real bugs is match_idents did not end with NULL.

I understand your patch triggered a bug that was sitting there for more than two years. That's quite rare. Sorry for assuming your guilt.

Quoted 1 line

This patch should fix it:

Yes, it's working. Thank you!

Signature · 2 lines
Regards,
Pavel Roskin
#4 lore raw

exposing __attribute__ portability macros in lib.h; any objections?

In reply to Christopher Li
Quoted 1 line · Christopher Li

Fix a bug that match_idents forget to end with NULL

[...]

Quoted 1 line

[...]

parse.c static struct token *handle_attributes(s · line 864

Quoted 2 lines
parse.c +1 -1
-		if (match_idents(token, &asm_ident, &__asm_ident, &__asm___ident)) {
+		if (match_idents(token, &asm_ident, &__asm_ident, &__asm___ident, NULL)) {

Applied.

I'd also like to apply a patch to use __attribute__((__sentinel__)) on match_idents, which would have caught this problem. In order to do so portably, I plan to add a portability macro SENTINEL_ATTR, like the FORMAT_ATTR macro currently in lib.h. However, lib.h currently defines FORMAT_ATTR, uses it for a few prototypes, and then undefines it. Any objections to defining SENTINEL_ATTR and leaving it defined (and probably doing the same for FORMAT_ATTR)? I don't think those would pollute the namespace any more than lib.h already does with position, verbose, info, and similar.

- Josh Triplett

maintainer
#5 lore raw

Re: exposing __attribute__ portability macros in lib.h; any objections?

Quoted 1 line · Josh Triplett

Applied.

Thanks!

Quoted 10 lines

I'd also like to apply a patch to use __attribute__((__sentinel__)) on match_idents, which would have caught this problem. In order to do so portably, I plan to add a portability macro SENTINEL_ATTR, like the FORMAT_ATTR macro currently in lib.h. However, lib.h currently defines FORMAT_ATTR, uses it for a few prototypes, and then undefines it. Any objections to defining SENTINEL_ATTR and leaving it defined (and probably doing the same for FORMAT_ATTR)? I don't think those would pollute the namespace any more than lib.h already does with position, verbose, info, and similar.

No objection for __sentinel__ per se. In the long run, I would like to get ride of match_idents completely. I want to define more parser operation function for pre-defined keywords. So it is driven by the symbol table rather than comparing the keyword one by one. It is a big change though.

Chris