There was some support for it but it was just a define that expanded to the fixed name "base_file.c". Implement the real thing by saving the input filename and replacing __BASE_FILE__ by it. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- lib.c | 6 +++--- lib.h | 2 ++ pre-process.c | 6 ++++++ validation/preprocessor/base-file.c | 17 +++++++++++++++++ validation/preprocessor/base-file.h | 2 ++ validation/preprocessor/dynamic.c | 4 ++++ 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 validation/preprocessor/base-file.c create mode 100644 validation/preprocessor/base-file.h diff --git a/lib.c b/lib.c index c451a88ce..30d1cf6d1 100644 --- a/lib.c +++ b/lib.c @@ -60,6 +60,8 @@ int gcc_major = __GNUC__; int gcc_minor = __GNUC_MINOR__; int gcc_patchlevel = __GNUC_PATCHLEVEL__; +const char *base_filename; + static const char *gcc_base_dir = GCC_BASE; static const char *multiarch_dir = MULTIARCH_TRIPLET; @@ -1256,9 +1258,6 @@ static void create_builtin_stream(void) add_pre_buffer("#define __builtin_ms_va_end(arg)\n"); add_pre_buffer("#define __builtin_va_arg_pack()\n"); - /* FIXME! We need to do these as special magic macros at expansion time! */ - add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n"); - if (optimize_level) add_pre_buffer("#define __OPTIMIZE__ 1\n"); if (optimize_size) @@ -1314,6 +1313,7 @@ static struct symbol_list *sparse_file(const char *filename) if (fd < 0) die("No such file: %s", filename); } + base_filename = filename; // Tokenize the input stream token = tokenize(filename, fd, NULL, includepath); diff --git a/lib.h b/lib.h index d7bd3651f..4d613936e 100644 --- a/lib.h +++ b/lib.h @@ -46,6 +46,8 @@ extern int die_if_error; extern int repeat_phase; extern int gcc_major, gcc_minor, gcc_patchlevel; +extern const char *base_filename; + extern unsigned int hexval(unsigned int c); struct position { diff --git a/pre-process.c b/pre-process.c index 14c39b7af..88be02f1e 100644 --- a/pre-process.c +++ b/pre-process.c @@ -165,6 +165,11 @@ static void expand_file(struct token *token) replace_with_string(token, stream_name(token->pos.stream)); } +static void expand_basefile(struct token *token) +{ + replace_with_string(token, base_filename); +} + static time_t t = 0; static void expand_date(struct token *token) { @@ -1924,6 +1929,7 @@ static void init_preprocessor(void) } dynamic[] = { { "__LINE__", expand_line }, { "__FILE__", expand_file }, + { "__BASE_FILE__", expand_basefile }, { "__DATE__", expand_date }, { "__TIME__", expand_time }, { "__COUNTER__", expand_counter }, diff --git a/validation/preprocessor/base-file.c b/validation/preprocessor/base-file.c new file mode 100644 index 000000000..61a290cb0 --- /dev/null +++ b/validation/preprocessor/base-file.c @@ -0,0 +1,17 @@ +__FILE__ +__BASE_FILE__ + +#include "base-file.h" + +/* + * check-name: base file + * check-command: sparse -E $file + * + * check-output-start + +"preprocessor/base-file.c" +"preprocessor/base-file.c" +"preprocessor/base-file.h" +"preprocessor/base-file.c" + * check-output-end + */ diff --git a/validation/preprocessor/base-file.h b/validation/preprocessor/base-file.h new file mode 100644 index 000000000..018b16c54 --- /dev/null +++ b/validation/preprocessor/base-file.h @@ -0,0 +1,2 @@ +__FILE__ +__BASE_FILE__ diff --git a/validation/preprocessor/dynamic.c b/validation/preprocessor/dynamic.c index 9d1dcc085..f791ba395 100644 --- a/validation/preprocessor/dynamic.c +++ b/validation/preprocessor/dynamic.c @@ -4,6 +4,9 @@ __LINE__ #if defined(__FILE__) __FILE__ #endif +#if defined(__BASE_FILE__) +__BASE_FILE__ +#endif #if defined(__DATE__) date #endif @@ -25,6 +28,7 @@ __INCLUDE_LEVEL__ 2 "preprocessor/dynamic.c" +"preprocessor/dynamic.c" date time counter -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html