Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -425,3 +428,5 @@ typedef struct {
var_t *var;
int polluted;
} regfile_t;

#endif
4 changes: 4 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 41 additions & 1 deletion tests/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down