+2017-05-18 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/80797
+ * ubsan.c (instrument_null): Unwrap ADDR_EXPRs.
+ (pass_ubsan::execute): Call gimple_assign_single_p instead of
+ gimple_assign_load_p.
+
2017-05-17 Segher Boessenkool <segher@kernel.crashing.org>
PR middle-end/80692
+2017-05-18 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/80797
+ * c-c++-common/ubsan/null-12.c: New test.
+
2017-05-17 Segher Boessenkool <segher@kernel.crashing.org>
PR middle-end/80692
--- /dev/null
+/* PR sanitizer/80797 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined" } */
+
+struct S
+{
+ int i;
+};
+
+struct R
+{
+ struct T {
+ int i;
+ } *t;
+} r;
+
+int
+main ()
+{
+ struct S *s = 0;
+ struct S *s2[1] = { };
+
+ int *v1 = &s->i;
+ int *v2 = &(*s).i;
+ int *v3 = &s2[0]->i;
+ int *v4 = &s->i + 1;
+ int *v5 = &r.t->i;
+
+ asm ("" : : "r" (&v1) : "memory");
+ asm ("" : : "r" (&v2) : "memory");
+ asm ("" : : "r" (&v3) : "memory");
+ asm ("" : : "r" (&v4) : "memory");
+ asm ("" : : "r" (&v5) : "memory");
+
+ return 0;
+}
+
+/* { dg-output "member access within null pointer of type 'struct S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct S'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*member access within null pointer of type 'struct T'" } */
{
gimple *stmt = gsi_stmt (gsi);
tree t = is_lhs ? gimple_get_lhs (stmt) : gimple_assign_rhs1 (stmt);
+ /* Handle also e.g. &s->i. */
+ if (TREE_CODE (t) == ADDR_EXPR)
+ t = TREE_OPERAND (t, 0);
tree base = get_base_address (t);
const enum tree_code code = TREE_CODE (base);
if (code == MEM_REF
{
if (gimple_store_p (stmt))
instrument_null (gsi, true);
- if (gimple_assign_load_p (stmt))
+ if (gimple_assign_single_p (stmt))
instrument_null (gsi, false);
}