aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseyko <seyko2@gmail.com>2016-04-13 06:17:02 +0300
committerseyko <seyko2@gmail.com>2016-04-13 06:17:02 +0300
commitb5b3e89f9e6735eb33eedd2b3071acd38222ee04 (patch)
tree4d9d3b63aea4bfddc5d980b12aeb05b0d344fe9d
parentb0296139a8ca3c15cd601ca1449e6547c8a352a0 (diff)
downloadtinycc-b5b3e89f9e6735eb33eedd2b3071acd38222ee04.tar.gz
tinycc-b5b3e89f9e6735eb33eedd2b3071acd38222ee04.tar.bz2
Fix pragma once guard
From: Vlad Vissoultchev Date: Mon, 11 Apr 2016 01:26:32 +0300 Subject: Fix pragma once guard when compiling multiple source files When compiling multiple source files directly to executable cached include files guard was incorrectly checked for TOK_once in ifndef_macro member. If two source files included the same header guarded by pragma once, then the second one erroneously skipped it as `cached_includes` is not cleared on second `tcc_compile`
-rw-r--r--tcc.c2
-rw-r--r--tccpp.c7
2 files changed, 6 insertions, 3 deletions
diff --git a/tcc.c b/tcc.c
index d373980..94def68 100644
--- a/tcc.c
+++ b/tcc.c
@@ -344,7 +344,7 @@ int main(int argc, char **argv)
tcc_parse_args(s, argc - 1, argv + 1);
tcc_set_environment(s);
if (s->output_type != TCC_OUTPUT_OBJ)
- tcc_error("interlnal error");
+ tcc_error("internal error");
tcc_set_output_type(s, s->output_type);
}
}
diff --git a/tccpp.c b/tccpp.c
index b892b2e..603a65e 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1471,8 +1471,11 @@ static void pragma_parse(TCCState *s1)
tcc_warning("unbalanced #pragma pop_macro");
} else if (tok == TOK_once) {
- add_cached_include(s1, file->filename, TOK_once);
+ char buf1[sizeof file->filename];
+ pstrcpy(buf1, sizeof(buf1), "#once#");
+ pstrcat(buf1, sizeof(buf1), file->filename);
+ add_cached_include(s1, file->filename, tok_alloc(buf1, strlen(buf1))->tok);
} else if (s1->ppfp) {
/* tcc -E: keep pragmas below unchanged */
unget_tok(' ');
@@ -1670,7 +1673,7 @@ ST_FUNC void preprocess(int is_bof)
pstrcat(buf1, sizeof(buf1), buf);
e = search_cached_include(s1, buf1);
- if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) {
+ if (e && define_find(e->ifndef_macro)) {
/* no need to parse the include because the 'ifndef macro'
is defined */
#ifdef INC_DEBUG