* [ubsan] Instrument expr only when doing shift or division
@ 2013-07-31 7:06 Marek Polacek
0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2013-07-31 7:06 UTC (permalink / raw)
To: GCC Patches
Running
make -C gcc check RUNTESTFLAGS='--target_board=unix/-fsanitize=undefined
dg.exp=*const-expr*' unveiled a pretty stupid bug: we should
instrument expression only when it's actually needed, not otherwise.
On the C++ FE this is handled right, the thinko was only in C FE.
Tested x86_64-unknown-linux-gnu, applying to ubsan branch.
diff --git a/gcc/c/ChangeLog.ubsan b/gcc/c/ChangeLog.ubsan
index 11d167f..f41ae90 100644
--- a/gcc/c/ChangeLog.ubsan
+++ b/gcc/c/ChangeLog.ubsan
@@ -1,3 +1,8 @@
+2013-07-31 Marek Polacek <polacek@redhat.com>
+
+ * c-typeck.c (build_binary_op): Sanitize only when
+ doing shift or division.
+
2013-07-30 Marek Polacek <polacek@redhat.com>
* c-typeck.c (build_binary_op): Sanitize only when
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 7257166..2595382 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10489,7 +10489,8 @@ build_binary_op (location_t location, enum tree_code code,
}
if (flag_sanitize & SANITIZE_UNDEFINED
- && current_function_decl != 0)
+ && current_function_decl != 0
+ && (doing_div_or_mod || doing_shift))
{
/* OP0 and/or OP1 might have side-effects. */
op0 = c_save_expr (op0);
Marek
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-07-31 6:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-31 7:06 [ubsan] Instrument expr only when doing shift or division Marek Polacek
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).