Skip to content

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

@mingodad

Description

@mingodad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions