+2017-09-18 Richard Biener <rguenther@suse.de>
+
+ Backport from mainline
+ 2017-08-28 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/81977
+ * tree-ssa-sccvn.c (vn_reference_lookup_3): Fix look through
+ memcpy.
+
+ 2017-09-04 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/82084
+ * fold-const.h (can_native_encode_string_p): Declare.
+ * fold-const.c (can_native_encode_string_p): Factor out from ...
+ (native_encode_string): ... here.
+ * tree-vect-stmts.c (vectorizable_store): Call it to avoid
+ vectorizing stores from constants we later cannot handle.
+
+ 2017-07-25 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/81505
+ * fold-const.c (fold_negate_const): TREE_OVERFLOW should be
+ sticky.
+
2017-09-15 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
static int
native_encode_string (const_tree expr, unsigned char *ptr, int len, int off)
{
- tree type = TREE_TYPE (expr);
- HOST_WIDE_INT total_bytes;
-
- if (TREE_CODE (type) != ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
- || GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) != BITS_PER_UNIT
- || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type)))
+ if (! can_native_encode_string_p (expr))
return 0;
- total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (type));
+
+ HOST_WIDE_INT total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (expr)));
if ((off == -1 && total_bytes > len)
|| off >= total_bytes)
return 0;
}
}
+/* Return true iff a STRING_CST S is accepted by
+ native_encode_expr. */
+
+bool
+can_native_encode_string_p (const_tree expr)
+{
+ tree type = TREE_TYPE (expr);
+
+ if (TREE_CODE (type) != ARRAY_TYPE
+ || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
+ || (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) != BITS_PER_UNIT)
+ || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type)))
+ return false;
+ return true;
+}
+
/* Fold a VIEW_CONVERT_EXPR of a constant expression EXPR to type
TYPE at compile-time. If we're unable to perform the conversion
return NULL_TREE. */
bool overflow;
wide_int val = wi::neg (arg0, &overflow);
t = force_fit_type (type, val, 1,
- (overflow | TREE_OVERFLOW (arg0))
- && !TYPE_UNSIGNED (type));
+ (overflow && ! TYPE_UNSIGNED (type))
+ || TREE_OVERFLOW (arg0));
break;
}
/* Convert between trees and native memory representation. */
extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1);
extern tree native_interpret_expr (tree, const unsigned char *, int);
+extern bool can_native_encode_string_p (const_tree);
/* Fold constants as much as possible in an expression.
Returns the simplified expression.
+2017-09-18 Richard Biener <rguenther@suse.de>
+
+ Backport from mainline
+ 2017-08-28 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/81977
+ * g++.dg/torture/pr81977.C: New testcase.
+
+ 2017-09-04 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/82084
+ * g++.dg/torture/pr82084.C: New testcase.
+
+ 2017-07-25 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/81505
+ * gcc.dg/ubsan/pr81505.c: New testcase.
+
2017-09-18 Martin Liska <mliska@suse.cz>
* gcc.dg/asan/pr81224.c: Remove.
--- /dev/null
+/* { dg-do run } */
+/* { dg-require-effective-target int32plus } */
+
+#include <cstdint>
+
+typedef struct
+{
+ uint16_t x ;
+ uint16_t y ;
+ uint64_t z ;
+} __attribute__((packed, aligned(1))) TestMsgType;
+
+struct Payload
+{
+ uint16_t header_info[2];
+ TestMsgType _pref;
+ void Pack(uint8_t *buffer)
+ {
+ __builtin_memcpy(buffer, &_pref, sizeof(_pref));
+ }
+ void UnPack(uint8_t *buffer)
+ {
+ __builtin_memcpy(&_pref, buffer, sizeof(_pref));
+ }
+};
+
+
+struct Msg
+{
+ Payload _payload;
+ void Pack(uint8_t *buffer)
+ {
+ _payload.Pack(buffer);
+ }
+
+ void UnPack(uint8_t *buffer)
+ {
+ _payload.UnPack(buffer);
+ }
+};
+
+int main()
+{
+ uint8_t * buffer = new uint8_t [30];
+ Msg msg;
+ Msg msg1;
+ msg._payload._pref.x = 0xabcd;
+ msg._payload._pref.y = 0xa;
+ msg._payload._pref.z = 0x0001020304051617;
+ msg.Pack(&buffer[0]);
+ msg1.UnPack(&buffer[0]);
+ if (msg1._payload._pref.x != 0xabcd)
+ __builtin_abort ();
+ delete [] buffer;
+}
--- /dev/null
+// { dg-do compile }
+
+#include <string>
+int main()
+{
+ wchar_t strs[4][2]= { L"A", L"B", L"C" , L"D"};
+ std::wstring ss(strs[0]);
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O3 -fsanitize=signed-integer-overflow" } */
+
+int a, b, c, h;
+
+int i[5][5];
+
+void
+fn1 ()
+{
+ int l = 0;
+
+ for (a = 0; a <= 3; a++)
+ for (b = 1; b >= 0; b -= 1)
+ l |= i[0][b];
+ c = l;
+}
memset (&op, 0, sizeof (op));
op.type = vr->type;
op.opcode = MEM_REF;
- op.op0 = build_int_cst (ptr_type_node, at - rhs_offset);
+ op.op0 = build_int_cst (ptr_type_node, at - lhs_offset + rhs_offset);
op.off = at - lhs_offset + rhs_offset;
vr->operands[0] = op;
op.type = TREE_TYPE (rhs);
op = gimple_assign_rhs1 (stmt);
+ /* In the case this is a store from a STRING_CST make sure
+ native_encode_expr can handle it. */
+ if (TREE_CODE (op) == STRING_CST
+ && ! can_native_encode_string_p (op))
+ return false;
+
if (!vect_is_simple_use (op, vinfo, &def_stmt, &dt, &rhs_vectype))
{
if (dump_enabled_p ())