diff options
| -rwxr-xr-x | cgcc | 2 | ||||
| -rw-r--r-- | lib.c | 22 | ||||
| -rw-r--r-- | sparse.1 | 6 | ||||
| -rw-r--r-- | validation/fdiag-prefix.c | 11 |
4 files changed, 37 insertions, 4 deletions
@@ -103,7 +103,7 @@ sub check_only_option { my ($arg) = @_; return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|memcpy-max-count|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/; return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/; - return 1 if $arg =~ /^-f(dump-ir|memcpy-max-count)(=\S*)?$/; + return 1 if $arg =~ /^-f(dump-ir|memcpy-max-count|diagnostic-prefix)(=\S*)?$/; return 1 if $arg =~ /^-f(mem2reg|optim)(-enable|-disable|=last)?$/; return 0; } @@ -62,6 +62,7 @@ int gcc_patchlevel = __GNUC_PATCHLEVEL__; const char *base_filename; +static const char *diag_prefix = ""; static const char *gcc_base_dir = GCC_BASE; static const char *multiarch_dir = MULTIARCH_TRIPLET; @@ -133,8 +134,8 @@ static void do_warn(const char *type, struct position pos, const char * fmt, va_ name = stream_name(pos.stream); fflush(stdout); - fprintf(stderr, "%s:%d:%d: %s%s\n", - name, pos.line, pos.pos, type, buffer); + fprintf(stderr, "%s:%d:%d: %s%s%s\n", + name, pos.line, pos.pos, diag_prefix, type, buffer); } unsigned int fmax_warnings = 100; @@ -237,7 +238,7 @@ void die(const char *fmt, ...) vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); - fprintf(stderr, "%s\n", buffer); + fprintf(stderr, "%s%s\n", diag_prefix, buffer); exit(1); } @@ -899,6 +900,20 @@ static int handle_fpasses(const char *arg, const char *opt, const struct flag *f return 0; } +static int handle_fdiagnostic_prefix(const char *arg, const char *opt, const struct flag *flag, int options) +{ + switch (*opt) { + case '\0': + diag_prefix = "sparse: "; + return 1; + case '=': + diag_prefix = xasprintf("%s: ", opt+1); + return 1; + default: + return 0; + } +} + static int handle_fdump_ir(const char *arg, const char *opt, const struct flag *flag, int options) { static const struct mask_map dump_ir_options[] = { @@ -925,6 +940,7 @@ static int handle_fmax_warnings(const char *arg, const char *opt, const struct f } static struct flag fflags[] = { + { "diagnostic-prefix", NULL, handle_fdiagnostic_prefix }, { "dump-ir", NULL, handle_fdump_ir }, { "max-warnings=", NULL, handle_fmax_warnings }, { "mem-report", &fmem_report }, @@ -390,6 +390,12 @@ Report some statistics about memory allocation used by the tool. . .SH OTHER OPTIONS .TP +.B \-fdiagnostic-prefix[=PREFIX] +Prefix all diagnostics by the given PREFIX, followed by ": ". +If no one is given "sparse" is used. +The default is to not use a prefix at all. +. +.TP .B \-fmemcpy-max-count=COUNT Set the limit for the warnings given by \fB-Wmemcpy-max-count\fR. A COUNT of 'unlimited' or '0' will effectively disable the warning. diff --git a/validation/fdiag-prefix.c b/validation/fdiag-prefix.c new file mode 100644 index 00000000..71160d45 --- /dev/null +++ b/validation/fdiag-prefix.c @@ -0,0 +1,11 @@ +int a. + +/* + * check-name: fdiag-prefix + * check-command: sparse -fdiagnostic-prefix=prefix $file + * + * check-error-start +fdiag-prefix.c:1:6: prefix: error: Expected ; at end of declaration +fdiag-prefix.c:1:6: prefix: error: got . + * check-error-end + */ |
