aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--evaluate.c8
-rw-r--r--lib.c4
-rw-r--r--lib.h1
-rw-r--r--validation/eval/undecl-no-indent.c19
-rw-r--r--validation/preprocessor/freestanding.c11
-rw-r--r--validation/preprocessor/hosted.c11
-rwxr-xr-xvalidation/test-suite11
7 files changed, 61 insertions, 4 deletions
diff --git a/evaluate.c b/evaluate.c
index aa0f2080..3b9aec3c 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3130,6 +3130,10 @@ static struct symbol *evaluate_call(struct expression *expr)
if (ctype->type != SYM_FN) {
struct expression *arg;
+
+ if (fn->ctype == &bad_ctype)
+ return NULL;
+
expression_error(expr, "not a function %s",
show_ident(sym->ident));
/* do typechecking in arguments */
@@ -3304,9 +3308,7 @@ static struct symbol *evaluate_generic_selection(struct expression *expr)
if (!evaluate_symbol(stype))
continue;
- if (stype->type == SYM_NODE)
- base = stype->ctype.base_type;
-
+ base = stype->ctype.base_type;
if (base->type == SYM_ARRAY && base->array_size) {
get_expression_value_silent(base->array_size);
if (base->array_size->type == EXPR_VALUE)
diff --git a/lib.c b/lib.c
index 88bb3109..e5678826 100644
--- a/lib.c
+++ b/lib.c
@@ -311,6 +311,7 @@ int dbg_ir = 0;
int dbg_postorder = 0;
unsigned long fdump_ir;
+int fhosted = 1;
int fmem_report = 0;
unsigned long long fmemcpy_max_count = 100000;
unsigned long fpasses = ~0UL;
@@ -994,6 +995,8 @@ static int handle_fmax_warnings(const char *arg, const char *opt, const struct f
static struct flag fflags[] = {
{ "diagnostic-prefix", NULL, handle_fdiagnostic_prefix },
{ "dump-ir", NULL, handle_fdump_ir },
+ { "freestanding", &fhosted, NULL, OPT_INVERSE },
+ { "hosted", &fhosted },
{ "linearize", NULL, handle_fpasses, PASS_LINEARIZE },
{ "max-warnings=", NULL, handle_fmax_warnings },
{ "mem-report", &fmem_report },
@@ -1300,6 +1303,7 @@ static void predefined_macros(void)
predefine("__GNUC_PATCHLEVEL__", 1, "%d", gcc_patchlevel);
predefine("__STDC__", 1, "1");
+ predefine("__STDC_HOSTED__", 0, fhosted ? "1" : "0");
switch (standard) {
default:
break;
diff --git a/lib.h b/lib.h
index e767840c..4f67958e 100644
--- a/lib.h
+++ b/lib.h
@@ -202,6 +202,7 @@ extern int dbg_postorder;
extern unsigned int fmax_warnings;
extern int fmem_report;
extern unsigned long fdump_ir;
+extern int fhosted;
extern unsigned long long fmemcpy_max_count;
extern unsigned long fpasses;
extern int fpic;
diff --git a/validation/eval/undecl-no-indent.c b/validation/eval/undecl-no-indent.c
new file mode 100644
index 00000000..4aadf3d9
--- /dev/null
+++ b/validation/eval/undecl-no-indent.c
@@ -0,0 +1,19 @@
+inline void fun(void)
+{
+ undecl();
+}
+
+void foo(void);
+void foo(void)
+{
+ fun();
+ fun();
+}
+
+/*
+ * check-name: undecl-no-indent
+ *
+ * check-error-start
+eval/undecl-no-indent.c:3:9: error: undefined identifier 'undecl'
+ * check-error-end
+ */
diff --git a/validation/preprocessor/freestanding.c b/validation/preprocessor/freestanding.c
new file mode 100644
index 00000000..7ee35354
--- /dev/null
+++ b/validation/preprocessor/freestanding.c
@@ -0,0 +1,11 @@
+__STDC_HOSTED__
+
+/*
+ * check-name: freestanding
+ * check-command: sparse -E -ffreestanding $file
+ *
+ * check-output-start
+
+0
+ * check-output-end
+ */
diff --git a/validation/preprocessor/hosted.c b/validation/preprocessor/hosted.c
new file mode 100644
index 00000000..e6b3d3c1
--- /dev/null
+++ b/validation/preprocessor/hosted.c
@@ -0,0 +1,11 @@
+__STDC_HOSTED__
+
+/*
+ * check-name: hosted
+ * check-command: sparse -E -fhosted $file
+ *
+ * check-output-start
+
+1
+ * check-output-end
+ */
diff --git a/validation/test-suite b/validation/test-suite
index a22f7013..f7d992dc 100755
--- a/validation/test-suite
+++ b/validation/test-suite
@@ -458,6 +458,7 @@ echo "options:"
echo " -a append the created test to the input file"
echo " -f write a test known to fail"
echo " -l write a test for linearized code"
+echo " -p write a test for pre-processing"
echo
echo "argument(s):"
echo " file file containing the test case(s)"
@@ -474,7 +475,7 @@ do_format()
linear=0
fail=0
- while [ $# -gt 1 ] ; do
+ while [ $# -gt 0 ] ; do
case "$1" in
-a)
append=1 ;;
@@ -483,6 +484,9 @@ do_format()
-l)
def_cmd='test-linearize -Wno-decl $file'
linear=1 ;;
+ -p)
+ def_cmd='sparse -E $file' ;;
+
help|-*)
do_format_help
return 0
@@ -493,6 +497,11 @@ do_format()
continue
done
+ if [ $# -lt 1 -o $# -gt 3 ]; then
+ do_format_help
+ return 0
+ fi
+
arg_file "$1" || return 1
file="$1"