On Fri, Jul 21, 2017 at 01:38:17PM +0800, 吴潍浠(此彼) wrote:
> Hi Jeff
>
> I have signed the copyright assignment, and used the name 'Wish Wu' .
> Should I send you a copy of my assignment ?
>
> The attachment is my new patch with small changes.
> Codes are checked by ./contrib/check_GNU_style.sh, except some special files.
Please provide a ChangeLog entry, you can use ./contrib/mklog as a start.
@@ -975,6 +974,10 @@ fsanitize=
Common Driver Report Joined
Select what to sanitize.
+fsanitize-coverage=
+Common Driver Report Joined
+Select what to coverage sanitize.
+
Why Driver? The reason fsanitize= needs it is that say for
-fsanitize=address we add libraries in the driver, etc., but that
isn't the case for the coverage, right?
--- gcc/flag-types.h(revision 250199)
+++ gcc/flag-types.h(working copy)
@@ -250,6 +250,14 @@ enum sanitize_code {
| SANITIZE_BOUNDS_STRICT
};
+/* Different trace modes. */
+enum sanitize_coverage_code {
+ /* Trace PC. */
+ SANITIZE_COV_TRACE_PC = 1UL << 0,
+ /* Trace Compare. */
+ SANITIZE_COV_TRACE_CMP = 1UL << 1
+};
No need for UL suffixes, the reason sanitize_code uses them is
that it includes 1 << 16 and above and might be included even in target code
(for host we require 32-bit integers, for target code it might be just
16-bit).
--- gcc/opts.c (revision 250199)
+++ gcc/opts.c (working copy)
@@ -1519,6 +1519,17 @@ const struct sanitizer_opts_s sanitizer_opts[] =
{ NULL, 0U, 0UL, false }
};
+/* -f{,no-}sanitize-coverage= suboptions. */
+const struct sanitizer_opts_s coverage_sanitizer_opts[] =
+{
+#define SANITIZER_OPT(name, flags, recover) \
+{ #name, flags, sizeof #name - 1, recover }
+ SANITIZER_OPT (trace-pc, SANITIZE_COV_TRACE_PC, false),
+ SANITIZER_OPT (trace-cmp, SANITIZE_COV_TRACE_CMP, false),
+#undef SANITIZER_OPT
+ { NULL, 0U, 0UL, false }
No need to have the recover argument for the macro, just add false to it
(unless you want to use a different struct type that wouldn't even include
that member).
+/* Given ARG, an unrecognized coverage sanitizer option, return the best
+ matching coverage sanitizer option, or NULL if there isn't one. */
+
+static const char *
+get_closest_coverage_sanitizer_option (const string_fragment &arg)
+{
+ best_match bm (arg);
+ for (int i = 0; coverage_sanitizer_opts[i].name != NULL; ++i)
+{
+ bm.consider (coverage_sanitizer_opts[i].name);
+}
Body which contains just one line shouldn't be wrapped in {}s, just use
for (int i = 0; coverage_sanitizer_opts[i].name != NULL; ++i)
bm.consider (coverage_sanitizer_opts[i].name);
+unsigned int
+parse_coverage_sanitizer_options (const char *p, location_t loc,
+unsigned int flags, int value, bool complain)
Wrong formatting, unsigned int should go below const char *, like:
parse_coverage_sanitizer_options (const char *p, location_t loc,
unsigned int flags, int value, bool complain)
+{
+ while (*p != 0)
+{
+ size_t len, i;
+ bool found = false;
+ const char *comma = strchr (p, ',');
+
+ if (comma == NULL)
+ len = strlen (p);
+ else
+ len = comma - p;
+ if (len == 0)
+ {
+ p = comma + 1;
+ continue;
+ }
+
+ /* Check to see if the string matches an option class name. */
+ for (i = 0; coverage_sanitizer_opts[i].name != NULL; ++i)
+ if (len == coverage_sanitizer_opts[i].len
+ && memcmp (p, coverage_sanitizer_opts[i].name, len) == 0)
+ {
+ if (value)
+ flags |= coverage_sanitizer_opts[i].flag;
+ else
+ flags &= ~coverage_sanitizer_opts[i].flag;
+ found = true;
+ break;
+ }
+
+ if (! found && complain)
+ {
+ const char *hint
+ = get_closest_coverage_sanitizer_option (string_fragment (p, len));
+
+ if (hint)
+ error_at (loc,
+ "unrecognized argument to "
+ "-f%ssanitize-coverage= option: %q.*s;"
+ " did you mean %qs?",
+ value ? "" : "no-",
+ (int) len, p, hint);
+ else
+ error_at (loc,
+ "unrecognized argument to "
+ "-f%ssanitize-coverage= option: %q.*s",
+ value ? "" : "no-",
+ (int) len, p);
+ }
+
+ if (comma == NULL)
+ break;
+ p = comma + 1;
+}
+ return flags;
+}
Though, looking at the above, it sounds like there is just way too much
duplication. So, maybe better just use the parse_sanitizer_options
and get_closest_coverage_option functions for all of
-f{,no-}sanitize{,-recover,-coverage}= , add
const struct sanitizer_opts_s *opts = sanitizer_opts;
if (code == OPT_fsanitize_coverage_)
opts = coverage_sanitizer_opts;
early in both functions, deal with the diagnostics (to print "-coverage