+2017-03-31 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/79572
+ * c-ubsan.h (ubsan_maybe_instrument_reference): Change argument to
+ tree *.
+ * c-ubsan.c (ubsan_maybe_instrument_reference): Likewise. Handle
+ not just NOP_EXPR to REFERENCE_TYPE, but also INTEGER_CST with
+ REFERENCE_TYPE.
+
2017-03-31 David Malcolm <dmalcolm@redhat.com>
PR documentation/78732
return fold_build2 (COMPOUND_EXPR, TREE_TYPE (op), call, op);
}
-/* Instrument a NOP_EXPR to REFERENCE_TYPE if needed. */
+/* Instrument a NOP_EXPR to REFERENCE_TYPE or INTEGER_CST with REFERENCE_TYPE
+ type if needed. */
void
-ubsan_maybe_instrument_reference (tree stmt)
+ubsan_maybe_instrument_reference (tree *stmt_p)
{
- tree op = TREE_OPERAND (stmt, 0);
+ tree stmt = *stmt_p;
+ tree op = stmt;
+ if (TREE_CODE (stmt) == NOP_EXPR)
+ op = TREE_OPERAND (stmt, 0);
op = ubsan_maybe_instrument_reference_or_call (EXPR_LOCATION (stmt), op,
TREE_TYPE (stmt),
UBSAN_REF_BINDING);
if (op)
- TREE_OPERAND (stmt, 0) = op;
+ {
+ if (TREE_CODE (stmt) == NOP_EXPR)
+ TREE_OPERAND (stmt, 0) = op;
+ else
+ *stmt_p = op;
+ }
}
/* Instrument a CALL_EXPR to a method if needed. */
extern tree ubsan_instrument_bounds (location_t, tree, tree *, bool);
extern bool ubsan_array_ref_instrumented_p (const_tree);
extern void ubsan_maybe_instrument_array_ref (tree *, bool);
-extern void ubsan_maybe_instrument_reference (tree);
+extern void ubsan_maybe_instrument_reference (tree *);
extern void ubsan_maybe_instrument_member_call (tree, bool);
/* Declare this here as well as in ubsan.h. */
2017-03-31 Jakub Jelinek <jakub@redhat.com>
+ PR c++/79572
+ * cp-gimplify.c (cp_genericize_r): Sanitize INTEGER_CSTs with
+ REFERENCE_TYPE. Adjust ubsan_maybe_instrument_reference caller
+ for NOP_EXPR to REFERENCE_TYPE.
+
PR libstdc++/80251
* cp-tree.h (enum cp_trait_kind): Add CPTK_IS_AGGREGATE.
* cxx-pretty-print.c (pp_cxx_trait_expression): Handle
}
}
+ if (TREE_CODE (stmt) == INTEGER_CST
+ && TREE_CODE (TREE_TYPE (stmt)) == REFERENCE_TYPE
+ && (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
+ && !wtd->no_sanitize_p)
+ {
+ ubsan_maybe_instrument_reference (stmt_p);
+ if (*stmt_p != stmt)
+ {
+ *walk_subtrees = 0;
+ return NULL_TREE;
+ }
+ }
+
/* Other than invisiref parms, don't walk the same tree twice. */
if (p_set->contains (stmt))
{
if ((flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
&& TREE_CODE (stmt) == NOP_EXPR
&& TREE_CODE (TREE_TYPE (stmt)) == REFERENCE_TYPE)
- ubsan_maybe_instrument_reference (stmt);
+ ubsan_maybe_instrument_reference (stmt_p);
else if (TREE_CODE (stmt) == CALL_EXPR)
{
tree fn = CALL_EXPR_FN (stmt);
+2017-03-31 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/79572
+ * g++.dg/ubsan/null-8.C: New test.
+
2017-03-31 Pat Haugen <pthaugen@us.ibm.com>
PR target/80107
--- /dev/null
+// PR c++/79572
+// { dg-do run }
+// { dg-options "-fsanitize=null -std=c++14" }
+// { dg-output "reference binding to null pointer of type 'const int'" }
+
+void
+foo (const int &iref)
+{
+ if (&iref)
+ __builtin_printf ("iref %d\n", iref);
+ else
+ __builtin_printf ("iref is NULL\n");
+}
+
+int
+main ()
+{
+ foo (*((int*) __null));
+}