@@ -1,3 +1,8 @@
+2013-07-30 Marek Polacek <polacek@redhat.com>
+
+ * c-typeck.c (build_binary_op): Sanitize only when
+ current_function_decl is not zero.
+
2013-07-21 Marek Polacek <polacek@redhat.com>
* c-typeck.c (build_binary_op): Call c_fully_fold on both
@@ -10488,7 +10488,8 @@ build_binary_op (location_t location, enum tree_code code,
return error_mark_node;
}
- if (flag_sanitize & SANITIZE_UNDEFINED)
+ if (flag_sanitize & SANITIZE_UNDEFINED
+ && current_function_decl != 0)
{
/* OP0 and/or OP1 might have side-effects. */
op0 = c_save_expr (op0);
@@ -1,3 +1,8 @@
+2013-07-30 Marek Polacek <polacek@redhat.com>
+
+ * typeck.c (cp_build_binary_op): Sanitize only when
+ current_function_decl is not zero.
+
2013-07-05 Marek Polacek <polacek@redhat.com>
* typeck.c (cp_build_binary_op): Add division by zero and shift
@@ -4885,6 +4885,7 @@ cp_build_binary_op (location_t location,
if ((flag_sanitize & SANITIZE_UNDEFINED)
&& !processing_template_decl
+ && current_function_decl != 0
&& (doing_div_or_mod || doing_shift))
{
/* OP0 and/or OP1 might have side-effects. */
@@ -1,3 +1,7 @@
+2013-07-30 Marek Polacek <polacek@redhat.com>
+
+ * c-c++-common/ubsan/const-expr.c: New test.
+
2013-07-22 Marek Polacek <polacek@redhat.com>
* c-c++-common/ubsan/div-by-zero-3.c: Add more testing.
new file mode 100644
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift -w" } */
+
+enum e { A = 1 << 1, B, };
+const int arr[] = {
+ 1 << 2,
+ 1 << 3,
+};
+
+int
+bar (int a, int b)
+{
+ return a >> b;
+}
+
+int
+foo (void)
+{
+ int i = 1;
+ int vla[B << 3];
+ return bar (A, (i <<= 6, i + 2));
+}