public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/66908] Uninitialized variable when compiled with UBsan
Date: Wed, 22 Jul 2015 14:36:00 -0000	[thread overview]
Message-ID: <bug-66908-4-k0dV2rb4Hz@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-66908-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66908

--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Oh silly me!  This should work; Maxim, could you possibly try this patch?

--- gcc/c-family/c-ubsan.c
+++ gcc/c-family/c-ubsan.c
@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "internal-fn.h"
 #include "stor-layout.h"
 #include "builtins.h"
+#include "gimplify.h"

 /* Instrument division by zero and INT_MIN / -1.  If not instrumenting,
    return NULL_TREE.  */
@@ -54,6 +55,9 @@ ubsan_instrument_division (location_t loc, tree op0, tree
op1)
   gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
              == TYPE_MAIN_VARIANT (TREE_TYPE (op1)));

+  op0 = unshare_expr (op0);
+  op1 = unshare_expr (op1);
+
   if (TREE_CODE (type) == INTEGER_TYPE
       && (flag_sanitize & SANITIZE_DIVIDE))
     t = fold_build2 (EQ_EXPR, boolean_type_node,
@@ -134,6 +138,9 @@ ubsan_instrument_shift (location_t loc, enum tree_code
code,
   HOST_WIDE_INT op0_prec = TYPE_PRECISION (type0);
   tree uprecm1 = build_int_cst (op1_utype, op0_prec - 1);

+  op0 = unshare_expr (op0);
+  op1 = unshare_expr (op1);
+
   t = fold_convert_loc (loc, op1_utype, op1);
   t = fold_build2 (GT_EXPR, boolean_type_node, t, uprecm1);


  parent reply	other threads:[~2015-07-22 14:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-17 10:48 [Bug sanitizer/66908] New: " m.guseva at samsung dot com
2015-07-20 18:20 ` [Bug sanitizer/66908] " y.gribov at samsung dot com
2015-07-21 12:34 ` mpolacek at gcc dot gnu.org
2015-07-21 13:48 ` mpolacek at gcc dot gnu.org
2015-07-21 14:40 ` mpolacek at gcc dot gnu.org
2015-07-22  7:38 ` chefmax at gcc dot gnu.org
2015-07-22  8:21 ` mpolacek at gcc dot gnu.org
2015-07-22 12:07 ` mpolacek at gcc dot gnu.org
2015-07-22 12:40 ` mpolacek at gcc dot gnu.org
2015-07-22 14:36 ` mpolacek at gcc dot gnu.org [this message]
2015-07-22 15:03 ` chefmax at gcc dot gnu.org
2015-07-22 15:26 ` mpolacek at gcc dot gnu.org
2015-07-22 17:47 ` chefmax at gcc dot gnu.org
2015-07-23 13:56 ` mpolacek at gcc dot gnu.org
2015-07-23 13:58 ` chefmax at gcc dot gnu.org
2015-08-11 15:47 ` mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-66908-4-k0dV2rb4Hz@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).