From: Indu Bhagat <indu.bha...@oracle.com>

Currently, the data type of sanitizer flags is unsigned int, with
SANITIZE_SHADOW_CALL_STACK (1UL << 31) being highest individual
enumerator for enum sanitize_code.  Use 'uint64_t' data type to allow
for more distinct instrumentation modes be added when needed.

gcc/ChangeLog:

        * asan.h (sanitize_flags_p): Use 'uint64_t' instead of 'unsigned
        int'.
        * common.opt: Likewise.
        * dwarf2asm.cc (dw2_output_indirect_constant_1): Likewise.
        * opts.cc (find_sanitizer_argument): Likewise.
        (report_conflicting_sanitizer_options): Likewise.
        (parse_sanitizer_options): Likewise.
        (parse_no_sanitize_attribute): Likewise.
        * opts.h (parse_sanitizer_options): Likewise.
        (parse_no_sanitize_attribute): Likewise.
        * tree-cfg.cc (print_no_sanitize_attr_value): Likewise.

gcc/c-family/ChangeLog:

        * c-attribs.cc (add_no_sanitize_value): Likewise.
        (handle_no_sanitize_attribute): Likewise.
        (handle_no_sanitize_address_attribute): Likewise.
        (handle_no_sanitize_thread_attribute): Likewise.
        (handle_no_address_safety_analysis_attribute): Likewise.
        * c-common.h (add_no_sanitize_value): Likewise.

gcc/c/ChangeLog:

        * c-parser.cc (c_parser_declaration_or_fndef): Likewise.

gcc/cp/ChangeLog:

        * typeck.cc (get_member_function_from_ptrfunc): Likewise.

gcc/d/ChangeLog:

        * d-attribs.cc (d_handle_no_sanitize_attribute): Likewise.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-iancule...@oracle.com>
---
 gcc/asan.h                |  5 +++--
 gcc/c-family/c-attribs.cc | 16 ++++++++--------
 gcc/c-family/c-common.h   |  2 +-
 gcc/c/c-parser.cc         |  4 ++--
 gcc/common.opt            |  6 +++---
 gcc/cp/typeck.cc          |  2 +-
 gcc/d/d-attribs.cc        |  8 ++++----
 gcc/dwarf2asm.cc          |  2 +-
 gcc/opts.cc               | 25 +++++++++++++------------
 gcc/opts.h                |  8 ++++----
 gcc/tree-cfg.cc           |  2 +-
 11 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/gcc/asan.h b/gcc/asan.h
index 064d4f24823..d4443de4620 100644
--- a/gcc/asan.h
+++ b/gcc/asan.h
@@ -242,9 +242,10 @@ asan_protect_stack_decl (tree decl)
    remove all flags mentioned in "no_sanitize" of DECL_ATTRIBUTES.  */
 
 inline bool
-sanitize_flags_p (unsigned int flag, const_tree fn = current_function_decl)
+sanitize_flags_p (uint64_t flag,
+                 const_tree fn = current_function_decl)
 {
-  unsigned int result_flags = flag_sanitize & flag;
+  uint64_t result_flags = flag_sanitize & flag;
   if (result_flags == 0)
     return false;
 
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index ea04ed7f0d4..ddb173e3ccf 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -1409,23 +1409,23 @@ handle_cold_attribute (tree *node, tree name, tree 
ARG_UNUSED (args),
 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES.  */
 
 void
-add_no_sanitize_value (tree node, unsigned int flags)
+add_no_sanitize_value (tree node, uint64_t flags)
 {
   tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node));
   if (attr)
     {
-      unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr));
+      uint64_t old_value = tree_to_uhwi (TREE_VALUE (attr));
       flags |= old_value;
 
       if (flags == old_value)
        return;
 
-      TREE_VALUE (attr) = build_int_cst (unsigned_type_node, flags);
+      TREE_VALUE (attr) = build_int_cst (uint64_type_node, flags);
     }
   else
     DECL_ATTRIBUTES (node)
       = tree_cons (get_identifier ("no_sanitize"),
-                  build_int_cst (unsigned_type_node, flags),
+                  build_int_cst (uint64_type_node, flags),
                   DECL_ATTRIBUTES (node));
 }
 
@@ -1436,7 +1436,7 @@ static tree
 handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
                              bool *no_add_attrs)
 {
-  unsigned int flags = 0;
+  uint64_t flags = 0;
   *no_add_attrs = true;
   if (TREE_CODE (*node) != FUNCTION_DECL)
     {
@@ -1473,7 +1473,7 @@ handle_no_sanitize_address_attribute (tree *node, tree 
name, tree, int,
   if (TREE_CODE (*node) != FUNCTION_DECL)
     warning (OPT_Wattributes, "%qE attribute ignored", name);
   else
-    add_no_sanitize_value (*node, SANITIZE_ADDRESS);
+    add_no_sanitize_value (*node, (uint64_t) SANITIZE_ADDRESS);
 
   return NULL_TREE;
 }
@@ -1489,7 +1489,7 @@ handle_no_sanitize_thread_attribute (tree *node, tree 
name, tree, int,
   if (TREE_CODE (*node) != FUNCTION_DECL)
     warning (OPT_Wattributes, "%qE attribute ignored", name);
   else
-    add_no_sanitize_value (*node, SANITIZE_THREAD);
+    add_no_sanitize_value (*node, (uint64_t) SANITIZE_THREAD);
 
   return NULL_TREE;
 }
@@ -1506,7 +1506,7 @@ handle_no_address_safety_analysis_attribute (tree *node, 
tree name, tree, int,
   if (TREE_CODE (*node) != FUNCTION_DECL)
     warning (OPT_Wattributes, "%qE attribute ignored", name);
   else
-    add_no_sanitize_value (*node, SANITIZE_ADDRESS);
+    add_no_sanitize_value (*node, (uint64_t) SANITIZE_ADDRESS);
 
   return NULL_TREE;
 }
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 675708d2680..c7623f52ab0 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1713,7 +1713,7 @@ extern enum flt_eval_method
 excess_precision_mode_join (enum flt_eval_method, enum flt_eval_method);
 
 extern int c_flt_eval_method (bool ts18661_p);
-extern void add_no_sanitize_value (tree node, unsigned int flags);
+extern void add_no_sanitize_value (tree node, uint64_t flags);
 
 extern void maybe_add_include_fixit (rich_location *, const char *, bool);
 extern void maybe_suggest_missing_token_insertion (rich_location *richloc,
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 0c3e3e2889c..3d2550ed729 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -2822,7 +2822,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
                              specs->constexpr_p, &richloc);
                  /* A parameter is initialized, which is invalid.  Don't
                     attempt to instrument the initializer.  */
-                 int flag_sanitize_save = flag_sanitize;
+                 uint64_t flag_sanitize_save = flag_sanitize;
                  if (nested && !empty_ok)
                    flag_sanitize = 0;
                  init = c_parser_expr_no_commas (parser, NULL);
@@ -2911,7 +2911,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
                              specs->constexpr_p, &richloc);
                  /* A parameter is initialized, which is invalid.  Don't
                     attempt to instrument the initializer.  */
-                 int flag_sanitize_save = flag_sanitize;
+                 uint64_t flag_sanitize_save = flag_sanitize;
                  if (TREE_CODE (d) == PARM_DECL)
                    flag_sanitize = 0;
                  init = c_parser_initializer (parser, d);
diff --git a/gcc/common.opt b/gcc/common.opt
index 3d65656e658..9d4b6bf4cc2 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -205,15 +205,15 @@ bool flag_opts_finished
 
 ; What the sanitizer should instrument
 Variable
-unsigned int flag_sanitize
+uint64_t flag_sanitize
 
 ; What sanitizers should recover from errors
 Variable
-unsigned int flag_sanitize_recover = (SANITIZE_UNDEFINED | 
SANITIZE_UNDEFINED_NONDEFAULT | SANITIZE_KERNEL_ADDRESS | 
SANITIZE_KERNEL_HWADDRESS) & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN)
+uint64_t flag_sanitize_recover = (SANITIZE_UNDEFINED | 
SANITIZE_UNDEFINED_NONDEFAULT | SANITIZE_KERNEL_ADDRESS | 
SANITIZE_KERNEL_HWADDRESS) & ~(SANITIZE_UNREACHABLE | SANITIZE_RETURN)
 
 ; What sanitizers should use __builtin_trap () instead of runtime diagnostics
 Variable
-unsigned int flag_sanitize_trap
+uint64_t flag_sanitize_trap
 
 ; Flag whether a prefix has been added to dump_base_name
 Variable
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 0bf5ae4e4e2..37e39b3622f 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -4286,7 +4286,7 @@ get_member_function_from_ptrfunc (tree *instance_ptrptr, 
tree function,
       idx = build1 (NOP_EXPR, vtable_index_type, e3);
       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
        {
-         int flag_sanitize_save;
+         uint64_t flag_sanitize_save;
        case ptrmemfunc_vbit_in_pfn:
          e1 = cp_build_binary_op (input_location,
                                   BIT_AND_EXPR, idx, integer_one_node,
diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 77315dc5d58..df7a93286b3 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -1406,7 +1406,7 @@ d_handle_no_sanitize_attribute (tree *node, tree name, 
tree args, int,
       return NULL_TREE;
     }
 
-  unsigned int flags = 0;
+  uint64_t flags = 0;
   for (; args; args = TREE_CHAIN (args))
     {
       tree id = TREE_VALUE (args);
@@ -1424,16 +1424,16 @@ d_handle_no_sanitize_attribute (tree *node, tree name, 
tree args, int,
      merge existing flags if no_sanitize was previously handled.  */
   if (tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (*node)))
     {
-      unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr));
+      uint64_t old_value = tree_to_uhwi (TREE_VALUE (attr));
       flags |= old_value;
 
       if (flags != old_value)
-       TREE_VALUE (attr) = build_int_cst (d_uint_type, flags);
+       TREE_VALUE (attr) = build_int_cst (d_ulong_type, flags);
     }
   else
     {
       DECL_ATTRIBUTES (*node) = tree_cons (get_identifier ("no_sanitize"),
-                                          build_int_cst (d_uint_type, flags),
+                                          build_int_cst (d_ulong_type, flags),
                                           DECL_ATTRIBUTES (*node));
     }
 
diff --git a/gcc/dwarf2asm.cc b/gcc/dwarf2asm.cc
index ec5c684da47..138464b164a 100644
--- a/gcc/dwarf2asm.cc
+++ b/gcc/dwarf2asm.cc
@@ -1041,7 +1041,7 @@ dw2_output_indirect_constant_1 (const char *sym, tree id)
   sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
   /* Disable ASan for decl because redzones cause ABI breakage between GCC and
      libstdc++ for `.LDFCM*' variables.  See PR 78651 for details.  */
-  unsigned int save_flag_sanitize = flag_sanitize;
+  uint64_t save_flag_sanitize = flag_sanitize;
   flag_sanitize &= ~(SANITIZE_ADDRESS | SANITIZE_USER_ADDRESS
                     | SANITIZE_KERNEL_ADDRESS);
   /* And also temporarily disable -fsection-anchors.  These indirect constants
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 6ca1ec7e865..d00e05f6321 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -988,7 +988,8 @@ vec<const char *> help_option_arguments;
 /* Return the string name describing a sanitizer argument which has been
    provided on the command line and has set this particular flag.  */
 const char *
-find_sanitizer_argument (struct gcc_options *opts, unsigned int flags)
+find_sanitizer_argument (struct gcc_options *opts,
+                        uint64_t flags)
 {
   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
     {
@@ -1022,10 +1023,10 @@ find_sanitizer_argument (struct gcc_options *opts, 
unsigned int flags)
    set these flags.  */
 static void
 report_conflicting_sanitizer_options (struct gcc_options *opts, location_t loc,
-                                     unsigned int left, unsigned int right)
+                                     uint64_t left, uint64_t right)
 {
-  unsigned int left_seen = (opts->x_flag_sanitize & left);
-  unsigned int right_seen = (opts->x_flag_sanitize & right);
+  uint64_t left_seen = (opts->x_flag_sanitize & left);
+  uint64_t right_seen = (opts->x_flag_sanitize & right);
   if (left_seen && right_seen)
     {
       const char* left_arg = find_sanitizer_argument (opts, left_seen);
@@ -2160,9 +2161,9 @@ const struct sanitizer_opts_s sanitizer_opts[] =
   SANITIZER_OPT (pointer-overflow, SANITIZE_POINTER_OVERFLOW, true, true),
   SANITIZER_OPT (builtin, SANITIZE_BUILTIN, true, true),
   SANITIZER_OPT (shadow-call-stack, SANITIZE_SHADOW_CALL_STACK, false, false),
-  SANITIZER_OPT (all, ~0U, true, true),
+  SANITIZER_OPT (all, ~0ULL, true, true),
 #undef SANITIZER_OPT
-  { NULL, 0U, 0UL, false, false }
+  { NULL, 0ULL, 0UL, false, false }
 };
 
 /* -fzero-call-used-regs= suboptions.  */
@@ -2233,7 +2234,7 @@ get_closest_sanitizer_option (const string_fragment &arg,
     {
       /* -fsanitize=all is not valid, so don't offer it.  */
       if (code == OPT_fsanitize_
-         && opts[i].flag == ~0U
+         && opts[i].flag == ~0ULL
          && value)
        continue;
 
@@ -2260,9 +2261,9 @@ get_closest_sanitizer_option (const string_fragment &arg,
    adjust previous FLAGS and return new ones.  If COMPLAIN is false,
    don't issue diagnostics.  */
 
-unsigned int
+uint64_t
 parse_sanitizer_options (const char *p, location_t loc, int scode,
-                        unsigned int flags, int value, bool complain)
+                        uint64_t flags, int value, bool complain)
 {
   enum opt_code code = (enum opt_code) scode;
 
@@ -2288,7 +2289,7 @@ parse_sanitizer_options (const char *p, location_t loc, 
int scode,
            && memcmp (p, sanitizer_opts[i].name, len) == 0)
          {
            /* Handle both -fsanitize and -fno-sanitize cases.  */
-           if (value && sanitizer_opts[i].flag == ~0U)
+           if (value && sanitizer_opts[i].flag == ~0ULL)
              {
                if (code == OPT_fsanitize_)
                  {
@@ -2369,10 +2370,10 @@ parse_sanitizer_options (const char *p, location_t loc, 
int scode,
 /* Parse string values of no_sanitize attribute passed in VALUE.
    Values are separated with comma.  */
 
-unsigned int
+uint64_t
 parse_no_sanitize_attribute (char *value)
 {
-  unsigned int flags = 0;
+  uint64_t flags = 0;
   unsigned int i;
   char *q = strtok (value, ",");
 
diff --git a/gcc/opts.h b/gcc/opts.h
index 382faab9250..c0757e44769 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -432,10 +432,10 @@ extern char *write_langs (unsigned int mask);
 extern void print_ignored_options (void);
 extern void handle_common_deferred_options (void);
 extern void handle_deferred_dump_options (void);
-unsigned int parse_sanitizer_options (const char *, location_t, int,
-                                     unsigned int, int, bool);
+uint64_t parse_sanitizer_options (const char *, location_t, int,
+                                 uint64_t, int, bool);
 
-unsigned int parse_no_sanitize_attribute (char *value);
+uint64_t parse_no_sanitize_attribute (char *value);
 extern bool common_handle_option (struct gcc_options *opts,
                                  struct gcc_options *opts_set,
                                  const struct cl_decoded_option *decoded,
@@ -477,7 +477,7 @@ extern bool opt_enum_arg_to_value (size_t opt_index, const 
char *arg,
 extern const struct sanitizer_opts_s
 {
   const char *const name;
-  unsigned int flag;
+  uint64_t flag;
   size_t len;
   bool can_recover;
   bool can_trap;
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 9a5479a2d38..9526c3000ca 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -8305,7 +8305,7 @@ dump_default_def (FILE *file, tree def, int spc, 
dump_flags_t flags)
 static void
 print_no_sanitize_attr_value (FILE *file, tree value)
 {
-  unsigned int flags = tree_to_uhwi (value);
+  uint64_t flags = tree_to_uhwi (value);
   bool first = true;
   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
     {
-- 
2.50.0

Reply via email to