Hi. I'm going to backport following 2 revisions. Patches can bootstrap on x86_64-linux-gnu and survive regression tests.
Martin
>From 3308817aa11be9d43cd564d249dae1c28bf41015 Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Fri, 11 May 2018 07:37:35 +0000 Subject: Backport r260154 gcc/ChangeLog: 2018-05-11 Martin Liska <mli...@suse.cz> PR sanitizer/85556 * doc/extend.texi: Document LLVM style format for no_sanitize attribute. gcc/c-family/ChangeLog: 2018-05-11 Martin Liska <mli...@suse.cz> PR sanitizer/85556 * c-attribs.c (handle_no_sanitize_attribute): Iterate all TREE_LIST values. gcc/testsuite/ChangeLog: 2018-05-11 Martin Liska <mli...@suse.cz> PR sanitizer/85556 * c-c++-common/ubsan/attrib-6.c: New test. --- diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 9bddc1aad4f..d302b4f22c7 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -403,7 +403,7 @@ const struct attribute_spec c_common_attribute_table[] = 0, 0, true, false, false, false, handle_no_address_safety_analysis_attribute, NULL }, - { "no_sanitize", 1, 1, true, false, false, false, + { "no_sanitize", 1, -1, true, false, false, false, handle_no_sanitize_attribute, NULL }, { "no_sanitize_address", 0, 0, true, false, false, false, handle_no_sanitize_address_attribute, NULL }, @@ -683,22 +683,26 @@ static tree handle_no_sanitize_attribute (tree *node, tree name, tree args, int, bool *no_add_attrs) { + unsigned int flags = 0; *no_add_attrs = true; - tree id = TREE_VALUE (args); if (TREE_CODE (*node) != FUNCTION_DECL) { warning (OPT_Wattributes, "%qE attribute ignored", name); return NULL_TREE; } - if (TREE_CODE (id) != STRING_CST) + for (; args; args = TREE_CHAIN (args)) { - error ("no_sanitize argument not a string"); - return NULL_TREE; - } + tree id = TREE_VALUE (args); + if (TREE_CODE (id) != STRING_CST) + { + error ("no_sanitize argument not a string"); + return NULL_TREE; + } - char *string = ASTRDUP (TREE_STRING_POINTER (id)); - unsigned int flags = parse_no_sanitize_attribute (string); + char *string = ASTRDUP (TREE_STRING_POINTER (id)); + flags |= parse_no_sanitize_attribute (string); + } add_no_sanitize_value (*node, flags); diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 9d085844cfd..a4664cad819 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2977,6 +2977,8 @@ mentioned in @var{sanitize_option}. A list of values acceptable by @smallexample void __attribute__ ((no_sanitize ("alignment", "object-size"))) f () @{ /* @r{Do something.} */; @} +void __attribute__ ((no_sanitize ("alignment,object-size"))) +g () @{ /* @r{Do something.} */; @} @end smallexample @item no_sanitize_address diff --git a/gcc/testsuite/c-c++-common/ubsan/attrib-6.c b/gcc/testsuite/c-c++-common/ubsan/attrib-6.c new file mode 100644 index 00000000000..2af70c8c2cf --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/attrib-6.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined" } */ + +static void __attribute__((no_sanitize("foobar"))) +foo (void) { /* { dg-warning "attribute directive ignored" } */ +} + +static void __attribute__((no_sanitize("address,undefined"))) +foo2 (void) { +} + +static void __attribute__((no_sanitize("address", "undefined"))) +foo3 (void) { +} + +static void __attribute__((no_sanitize("address", "address", ""))) +foo4 (void) { +} + +static void __attribute__((no_sanitize("address", "address", "address,address"))) +foo5 (void) { +} + +static void __attribute__((no_sanitize("address", "address,kernel-address,thread,leak,undefined,vptr,shift,integer-divide-by-zero,unreachable,vla-bound,null,return,signed-integer-overflow,bounds,bounds-strict,alignment,object-size,float-divide-by-zero,float-cast-overflow,nonnull-attribute,returns-nonnull-attribute,bool,enum"))) +foo6 (void) { +} -- 2.16.3
>From 8203f7efd03cc82717ab0416a151e96d3a7b8f4b Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Wed, 23 May 2018 07:40:43 +0000 Subject: Backport r260566 gcc/ChangeLog: 2018-05-23 Yury Gribov <tetra2...@gmail.com> PR tree-optimization/85822 * tree-vrp.c (is_masked_range_test): Fix handling of negative constants. gcc/testsuite/ChangeLog: 2018-05-23 Yury Gribov <tetra2...@gmail.com> PR tree-optimization/85822 * c-c++-common/pr85822.c: New test. --- diff --git a/gcc/testsuite/c-c++-common/pr85822.c b/gcc/testsuite/c-c++-common/pr85822.c new file mode 100644 index 00000000000..3b09188ab47 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr85822.c @@ -0,0 +1,27 @@ +/* { dg-options "-O2" } */ +/* { dg-do run } */ + +static const long long int TagTypeNumber = 0xffff000000000000ll; + +long long int x; + +void foo(void) +{ + x = TagTypeNumber + 1; +} + +int main(int argc, char **argv) +{ + if (argc > 0) + foo (); + + if ((x & TagTypeNumber) == TagTypeNumber) + { + unsigned y = (unsigned)x; + __builtin_printf ("v: %u\n", y); + if (y != 1) + __builtin_abort (); + } + + return 0; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index aa53db65576..6c482dd3e46 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3844,10 +3844,10 @@ register_edge_assert_for_1 (tree op, enum tree_code code, Such comparison can yield assertions like X >= XX...X00...0 X <= XX...X11...1 - in case of COND_OP being NE_EXPR or + in case of COND_OP being EQ_EXPR or X < XX...X00...0 X > XX...X11...1 - in case of EQ_EXPR. */ + in case of NE_EXPR. */ static bool is_masked_range_test (tree name, tree valt, enum tree_code cond_code, @@ -3867,6 +3867,10 @@ is_masked_range_test (tree name, tree valt, enum tree_code cond_code, wi::tree_to_wide_ref mask = wi::to_wide (maskt); wide_int inv_mask = ~mask; + /* Must have been removed by now so don't bother optimizing. */ + if (mask == 0 || inv_mask == 0) + return false; + /* Assume VALT is INTEGER_CST. */ wi::tree_to_wide_ref val = wi::to_wide (valt); @@ -3907,9 +3911,6 @@ is_masked_range_test (tree name, tree valt, enum tree_code cond_code, *low = wide_int_to_tree (type, val); *high = wide_int_to_tree (type, val | inv_mask); - if (wi::neg_p (val, TYPE_SIGN (type))) - std::swap (*low, *high); - return true; } -- 2.16.3