Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing cpp-reference.com/w/c examples with sparse #4

Open
mingodad opened this issue Nov 14, 2024 · 0 comments
Open

Testing cpp-reference.com/w/c examples with sparse #4

mingodad opened this issue Nov 14, 2024 · 0 comments

Comments

@mingodad
Copy link

I created a Lua script (see attached with the resulting output) to extract the examples from https://en.cppreference.com/w/c (can be downloaded here https://en.cppreference.com/w/Cppreference:Archives) and here is the sumary:

Total files scanned     :	614
Total files with code   :	434
Total files failed code :	111

I also needed to make small changes to sparse to return non zero when there is errors in the evaluate functions:

---------------------------------- evaluate.c ----------------------------------
index fe716f63..3cf6cef4 100644
@@ -44,6 +44,7 @@
 #include "expression.h"
 
 struct symbol *current_fn;
+int bad_eval_count = 0;
 
 struct ident bad_address_space = { .len = 6, .name = "bad AS", };
 
@@ -83,6 +84,7 @@ static struct symbol *evaluate_symbol_expression(struct expression *expr)
 
 	if (!sym) {
 		expression_error(expr, "undefined identifier '%s'", show_ident(expr->symbol_name));
+                ++bad_eval_count;
 		return NULL;
 	}
 
@@ -91,6 +93,7 @@ static struct symbol *evaluate_symbol_expression(struct expression *expr)
 	base_type = get_base_type(sym);
 	if (!base_type) {
 		expression_error(expr, "identifier '%s' has no type", show_ident(expr->symbol_name));
+                ++bad_eval_count;
 		return NULL;
 	}
 

---------------------------------- evaluate.h ----------------------------------
index a16e9703..baf5c716 100644
@@ -6,6 +6,7 @@ struct expression_list;
 struct statement;
 struct symbol;
 struct symbol_list;
+extern int bad_eval_count;
 
 ///
 // evaluate the type of an expression

----------------------------------- sparse.c -----------------------------------
index e7cc6f55..5a430e3e 100644
@@ -39,6 +39,7 @@
 #include "symbol.h"
 #include "expression.h"
 #include "linearize.h"
+#include "evaluate.h"
 
 static int context_increase(struct basic_block *bb, int entry)
 {
@@ -325,13 +326,18 @@ int main(int argc, char **argv)
 
 	// by default ignore -o <file>
 	do_output = 0;
+        int error_count = 0;
+        struct symbol_list *sym_list;
 
 	// Expand, linearize and show it.
 	check_symbols(sparse_initialize(argc, argv, &filelist));
 	FOR_EACH_PTR(filelist, file) {
-		check_symbols(sparse(file));
+                bad_eval_count = 0;
+                sym_list = sparse(file);
+                error_count += has_error + bad_eval_count;
+		check_symbols(sym_list);
 	} END_FOR_EACH_PTR(file);
 
 	report_stats();
-	return 0;
+	return error_count;
 }

test-c-reference.output.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant