Hi! Apparently the pr81125.C testcase ICEs on Darwin, but not on Linux, the difference is that on Darwin ctors/dtors aren't deduplicated due to lack of flexibility of the object format. I've managed to reproduce also on Linux with a virtual base and -fno-declone-ctor-dtor. The problem was that because the temp var didn't have DECL_CONTEXT set, during cloning that var wasn't remapped and thus was shared by both complete and base ctor.
Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-06-27 Jakub Jelinek <ja...@redhat.com> PR sanitizer/81209 * ubsan.c (ubsan_encode_value): Initialize DECL_CONTEXT on var. * g++.dg/ubsan/pr81209.C: New test. --- gcc/ubsan.c.jj 2017-06-19 17:28:13.000000000 +0200 +++ gcc/ubsan.c 2017-06-26 21:04:45.602012192 +0200 @@ -153,6 +153,7 @@ ubsan_encode_value (tree t, enum ubsan_e { var = create_tmp_var_raw (type); TREE_ADDRESSABLE (var) = 1; + DECL_CONTEXT (var) = current_function_decl; } if (phase == UBSAN_ENCODE_VALUE_RTL) { --- gcc/testsuite/g++.dg/ubsan/pr81209.C.jj 2017-06-26 21:07:47.018875009 +0200 +++ gcc/testsuite/g++.dg/ubsan/pr81209.C 2017-06-26 21:08:08.273624617 +0200 @@ -0,0 +1,21 @@ +// PR sanitizer/81209 +// { dg-do compile } +// { dg-options "-fsanitize=undefined -fno-declone-ctor-dtor" } + +#ifdef __SIZEOF_INT128__ +typedef __int128 T; +#else +typedef long long int T; +#endif + +struct B {}; +struct A : virtual public B +{ + A (long); + T a; +}; + +A::A (long c) +{ + long b = a % c; +} Jakub