From 0006428c64c1cbdc062b84b982cd1a385a01beca Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Wed, 31 Mar 2021 13:16:35 +0200 Subject: [PATCH 1/3] Ignore unsupported pragmas Signed-off-by: Jeroen Koekkoek --- src/idl/src/directive.c | 9 ++++++--- src/tools/idlc/src/idlc.c | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/idl/src/directive.c b/src/idl/src/directive.c index f98589ab95..958e13646a 100644 --- a/src/idl/src/directive.c +++ b/src/idl/src/directive.c @@ -563,6 +563,10 @@ idl_retcode_t idl_parse_directive(idl_pstate_t *pstate, idl_token_t *tok) return parse_line(pstate, tok); } else if ((pstate->scanner.state & IDL_SCAN_KEYLIST) == IDL_SCAN_KEYLIST) { return parse_keylist(pstate, tok); + } else if (pstate->scanner.state == IDL_SCAN_UNKNOWN_PRAGMA) { + if (tok->code == '\n') + pstate->scanner.state = IDL_SCAN; + return IDL_RETCODE_OK; } else if (pstate->scanner.state == IDL_SCAN_PRAGMA) { /* expect keylist */ if (tok->code == IDL_TOKEN_IDENTIFIER) { @@ -576,10 +580,9 @@ idl_retcode_t idl_parse_directive(idl_pstate_t *pstate, idl_token_t *tok) pstate->scanner.state = IDL_SCAN_KEYLIST; return IDL_RETCODE_OK; } - idl_error(pstate, &tok->location, - "Unsupported #pragma directive %s", tok->value.str); - return IDL_RETCODE_SYNTAX_ERROR; } + pstate->scanner.state = IDL_SCAN_UNKNOWN_PRAGMA; + return IDL_RETCODE_OK; } else if (pstate->scanner.state == IDL_SCAN_DIRECTIVE_NAME) { if (tok->code == IDL_TOKEN_PP_NUMBER) { /* expect linemarker */ diff --git a/src/tools/idlc/src/idlc.c b/src/tools/idlc/src/idlc.c index c78293e797..0af7820868 100644 --- a/src/tools/idlc/src/idlc.c +++ b/src/tools/idlc/src/idlc.c @@ -302,8 +302,8 @@ static idl_retcode_t idlc_parse(void) if (mcpp_lib_main(config.argc, config.argv) == 0) { assert(!config.compile || retcode == IDL_RETCODE_OK); } else if (config.compile) { - assert(retcode != IDL_RETCODE_OK); - ret = retcode; + /* retcode is not set on preprocessor error */ + ret = retcode ? retcode : IDL_RETCODE_SYNTAX_ERROR; } if (pstate) { pstate->flags &= ~IDL_WRITE; @@ -576,7 +576,9 @@ int main(int argc, char *argv[]) config.file = argv[optind]; config.argv[config.argc++] = config.file; if ((ret = idlc_parse())) { - fprintf(stderr, "Cannot parse '%s'\n", config.file); + /* assume other errors are reported by processor */ + if (ret == IDL_RETCODE_NO_MEMORY) + fprintf(stderr, "Out of memory\n"); goto err_parse; } else if (config.compile) { if (gen.generate) From 8c641f78b9233a581d1b70ea8d2d5d9e03227ec6 Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Wed, 31 Mar 2021 13:20:28 +0200 Subject: [PATCH 2/3] Remove nonexistent file from CMakeLists.txt Signed-off-by: Jeroen Koekkoek --- src/idl/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/idl/CMakeLists.txt b/src/idl/CMakeLists.txt index aa7caff31f..65abc0f29c 100644 --- a/src/idl/CMakeLists.txt +++ b/src/idl/CMakeLists.txt @@ -49,7 +49,6 @@ add_library( src/string.c src/annotation.c src/scope.c - src/hashid.c src/string.c src/tree.c src/visit.c From a6182b2555cb9c490d5dbd4f061e74f54c445531 Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Tue, 6 Apr 2021 10:03:23 +0200 Subject: [PATCH 3/3] Add test to verify unsupported pragmas are ignored Signed-off-by: Jeroen Koekkoek --- src/idl/tests/pragma.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/idl/tests/pragma.c b/src/idl/tests/pragma.c index 62fdde1d74..030c61ec75 100644 --- a/src/idl/tests/pragma.c +++ b/src/idl/tests/pragma.c @@ -139,3 +139,19 @@ CU_Test(idl_pragma, keylist_outer_scope) CU_ASSERT((idl_mask(s1->keylist) & IDL_KEYLIST) != 0); idl_delete_pstate(pstate); } + +CU_Test(idl_pragma, unknown) +{ + idl_retcode_t ret; + idl_pstate_t *pstate = NULL; + idl_struct_t *s1; + static const char str[] = "struct s1 { char c; };\n" + "#pragma foo \"bar::baz\""; + + ret = parse_string(str, &pstate); + CU_ASSERT_EQUAL_FATAL(ret, IDL_RETCODE_OK); + CU_ASSERT_PTR_NOT_NULL_FATAL(pstate); + s1 = (idl_struct_t *)pstate->root; + CU_ASSERT_FATAL(idl_is_struct(s1)); + idl_delete_pstate(pstate); +}