Powered by Linux
Re: tiny patch for userland project — Semantic Matching Tool

Re: tiny patch for userland project

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(6/15/12 5:13 PM), KOSAKI Motohiro wrote:
(6/15/12 6:35 AM), Dan Carpenter wrote:
On Thu, Jun 14, 2012 at 12:53:52AM -0400, KOSAKI Motohiro wrote:
Hi,

Today, I tried to use 'smatch' for ruby project and I found plenty false positive errors.
They were mainly caused that glibc uses some no smatch recognized attributes. I did apply
following patch myself. (see below)

Is there any more good way? I didn't find a hint from README.

And, I have one unsolved issue. I've seen following annoying error a lot.

/usr/include/bits/xopen_lim.h:122:6: warning: constant 9223372036854775807L is so big it is long long

Because of, /usr/include/limits.h has "#define LONG_MAX 9223372036854775807L" and it is completely
valid on 64bit OS. Is there any way to disable this message when using 64bit?

The way to do this is to add an -m64 to the cgcc command.

make CHECK="~/path/to/smatch/smatch --full-path" \
CC="~/path/to/smatch/cgcc -m64"

Great! this works perfectly.


And it also does seem like Smatch prints out a bunch of garbage...
I'll try turn of it off unless the --spammy flag is used.

Today, I'm playing smatch a while. then I have two feature request for applying
smatch to userland open source project.

1) /usr/include have plenty smatch error. but they don't project author's fault.
please consider to make a way to ignore /usr/include. I can drop them by sed
filter. but it's annoying.

2) many userland project use -include gcc option for improving operating system
portability. (e.g. "gcc -include missing.h", and missing.h has OS unportable
function declarations). It would be great if smatch also have -include option.

I need more detailed explanation of (2). Please think following -I and -include combination.


Makefile
--------------
bar:
$(CC) -I./include-for-foo -include foo.h main.c -o bar


main.c
------------------
#include <stdio.h>

int main(void)
{
printf("foo = %d\n", FOO);
return 0;
}


include-for-foo/foo.h
----------------------
#define FOO 42


current smatch doesn't search ./include-for-foo/foo.h, but gcc and clang do.
I think it's a bug of following.

static void add_cmdline_include(char *filename)
{
int fd = open(filename, O_RDONLY); // Should care -I path too!
if (fd < 0) {
perror(filename);
return;
}

Is this acceptable way?


From 79e6edf5a07ad35722b4bc6290f396e6efd6c3a4 Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxx>
Date: Mon, 18 Jun 2012 05:58:37 -0400
Subject: [PATCH] Fix -include option

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxx>
---
 lib.c |   53 +++++++++++++++++++++++++----------------------------
 1 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/lib.c b/lib.c
index cedf358..d9385e8 100644
--- a/lib.c
+++ b/lib.c
@@ -189,6 +189,8 @@ void die(const char *fmt, ...)
static struct token *pre_buffer_begin = NULL;
 static struct token *pre_buffer_end = NULL;
+static struct token *pre_buffer_begin2 = NULL;
+static struct token *pre_buffer_end2 = NULL;
int Waddress_space = 1;
 int Wbitwise = 0;
@@ -224,11 +226,6 @@ static enum { STANDARD_C89,
               STANDARD_GNU89,
               STANDARD_GNU99, } standard = STANDARD_GNU89;
-#define CMDLINE_INCLUDE 20
-int cmdline_include_nr = 0;
-struct cmdline_include cmdline_include[CMDLINE_INCLUDE];
-
-
 void add_pre_buffer(const char *fmt, ...)
 {
 	va_list args;
@@ -247,6 +244,25 @@ void add_pre_buffer(const char *fmt, ...)
 	pre_buffer_end = end;
 }
+void add_pre_buffer2(const char *fmt, ...)
+{
+	va_list args;
+	unsigned int size;
+	struct token *begin, *end;
+	char buffer[4096];
+
+	va_start(args, fmt);
+	size = vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+	begin = tokenize_buffer(buffer, size, &end);
+	if (!pre_buffer_begin2)
+		pre_buffer_begin2 = begin;
+	if (pre_buffer_end2)
+		pre_buffer_end2->next = begin;
+	pre_buffer_end2 = end;
+}
+
+
 static char **handle_switch_D(char *arg, char **next)
 {
 	const char *name = arg + 1;
@@ -299,16 +315,7 @@ static char **handle_switch_I(char *arg, char **next)
static void add_cmdline_include(char *filename)
 {
-	int fd = open(filename, O_RDONLY);
-	if (fd < 0) {
-		perror(filename);
-		return;
-	}
-	if (cmdline_include_nr >= CMDLINE_INCLUDE)
-		die("too many include files for %s¥n", filename);
-	cmdline_include[cmdline_include_nr].filename = filename;
-	cmdline_include[cmdline_include_nr].fd = fd;
-	cmdline_include_nr++;
+	add_pre_buffer2("#include ¥"%s¥"¥n", filename);
 }
static char **handle_switch_i(char *arg, char **next)
@@ -903,19 +910,9 @@ static struct symbol_list *sparse_file(const char *filename)
  */
 static struct symbol_list *sparse_initial(void)
 {
-	struct token *token;
-	int i;
-
-	// Prepend any "include" file to the stream.
-	// We're in global scope, it will affect all files!
-	token = NULL;
-	for (i = cmdline_include_nr - 1; i >= 0; i--)
-		token = tokenize(cmdline_include[i].filename, cmdline_include[i].fd,
-				 token, includepath);
-
-	// Prepend the initial built-in stream
-	if (token)
-		pre_buffer_end->next = token;
+	if (pre_buffer_begin2)
+		pre_buffer_end->next = pre_buffer_begin2;
+
 	return sparse_tokenstream(pre_buffer_begin);
 }
--
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe smatch" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux