diff --git a/src/defs.h b/src/defs.h index 040b1a72..a56b15fd 100644 --- a/src/defs.h +++ b/src/defs.h @@ -5,6 +5,9 @@ * file "LICENSE" for information on usage and redistribution of this file. */ +#ifndef SHECC_DEFS_H +#define SHECC_DEFS_H + /* definitions */ /* Limitations */ @@ -425,3 +428,5 @@ typedef struct { var_t *var; int polluted; } regfile_t; + +#endif diff --git a/src/parser.c b/src/parser.c index fa04232f..484de1b4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -409,6 +409,10 @@ bool read_preproc_directive() macro->start_source_idx = source_idx; skip_macro_body(); + } else { + /* Empty alias, may be dummy alias serves as include guard */ + value[0] = 0; + add_alias(alias, value); } return true; diff --git a/tests/driver.sh b/tests/driver.sh index 31385cdf..dc26151e 100755 --- a/tests/driver.sh +++ b/tests/driver.sh @@ -465,9 +465,49 @@ try_ 0 << EOF #else #define A 1 #endif + +#ifndef A +#define B 1 +#else +#define B 0 +#endif int main() { - return A; + return A + B; +} +EOF + +# include guard test, simulates inclusion of a file named defs.h and global.c +try_ 0 << EOF +/* #include "defs.h" */ +#ifndef DEFS_H +#define DEFS_H + +#define A 1 + +#endif +/* end if "defs.h" inclusion */ + +/* #include "global.c" */ +#ifndef GLOBAL_C +#define GLOBAL_C + +#define B 1 + +/* [global.c] #include "defs.h" */ +#ifndef DEFS_H +#define DEFS_H + +#define A 2 + +#endif +/* end if "defs.h" inclusion */ +#endif +/* end if "global.c" inclusion */ + +int main() +{ + return A - B; } EOF