Skip to content

Commit 1991606

Browse files
marxinMartin Liska
authored andcommitted
Support LLVM style of no_sanitize attribute (PR sanitizer/85556).
2018-05-11 Martin Liska <[email protected]> PR sanitizer/85556 * doc/extend.texi: Document LLVM style format for no_sanitize attribute. 2018-05-11 Martin Liska <[email protected]> PR sanitizer/85556 * c-attribs.c (handle_no_sanitize_attribute): Iterate all TREE_LIST values. 2018-05-11 Martin Liska <[email protected]> PR sanitizer/85556 * c-c++-common/ubsan/attrib-6.c: New test. From-SVN: r260154
1 parent 683be2f commit 1991606

File tree

6 files changed

+57
-8
lines changed

6 files changed

+57
-8
lines changed

gcc/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-05-11 Martin Liska <[email protected]>
2+
3+
PR sanitizer/85556
4+
* doc/extend.texi: Document LLVM style format for no_sanitize
5+
attribute.
6+
17
2018-05-10 Michael Meissner <[email protected]>
28

39
* config/rs6000/rs6000.c (mode_supports_dq_form): Rename

gcc/c-family/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-05-11 Martin Liska <[email protected]>
2+
3+
PR sanitizer/85556
4+
* c-attribs.c (handle_no_sanitize_attribute): Iterate all
5+
TREE_LIST values.
6+
17
2018-05-10 Jakub Jelinek <[email protected]>
28

39
PR c++/85662

gcc/c-family/c-attribs.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ const struct attribute_spec c_common_attribute_table[] =
403403
0, 0, true, false, false, false,
404404
handle_no_address_safety_analysis_attribute,
405405
NULL },
406-
{ "no_sanitize", 1, 1, true, false, false, false,
406+
{ "no_sanitize", 1, -1, true, false, false, false,
407407
handle_no_sanitize_attribute, NULL },
408408
{ "no_sanitize_address", 0, 0, true, false, false, false,
409409
handle_no_sanitize_address_attribute, NULL },
@@ -683,22 +683,26 @@ static tree
683683
handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
684684
bool *no_add_attrs)
685685
{
686+
unsigned int flags = 0;
686687
*no_add_attrs = true;
687-
tree id = TREE_VALUE (args);
688688
if (TREE_CODE (*node) != FUNCTION_DECL)
689689
{
690690
warning (OPT_Wattributes, "%qE attribute ignored", name);
691691
return NULL_TREE;
692692
}
693693

694-
if (TREE_CODE (id) != STRING_CST)
694+
for (; args; args = TREE_CHAIN (args))
695695
{
696-
error ("no_sanitize argument not a string");
697-
return NULL_TREE;
698-
}
696+
tree id = TREE_VALUE (args);
697+
if (TREE_CODE (id) != STRING_CST)
698+
{
699+
error ("no_sanitize argument not a string");
700+
return NULL_TREE;
701+
}
699702

700-
char *string = ASTRDUP (TREE_STRING_POINTER (id));
701-
unsigned int flags = parse_no_sanitize_attribute (string);
703+
char *string = ASTRDUP (TREE_STRING_POINTER (id));
704+
flags |= parse_no_sanitize_attribute (string);
705+
}
702706

703707
add_no_sanitize_value (*node, flags);
704708

gcc/doc/extend.texi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,8 @@ mentioned in @var{sanitize_option}. A list of values acceptable by
29772977
@smallexample
29782978
void __attribute__ ((no_sanitize ("alignment", "object-size")))
29792979
f () @{ /* @r{Do something.} */; @}
2980+
void __attribute__ ((no_sanitize ("alignment,object-size")))
2981+
g () @{ /* @r{Do something.} */; @}
29802982
@end smallexample
29812983

29822984
@item no_sanitize_address

gcc/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-05-11 Martin Liska <[email protected]>
2+
3+
PR sanitizer/85556
4+
* c-c++-common/ubsan/attrib-6.c: New test.
5+
16
2018-05-10 Steven G. Kargl <[email protected]>
27

38
PR fortran/85687
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-fsanitize=undefined" } */
3+
4+
static void __attribute__((no_sanitize("foobar")))
5+
foo (void) { /* { dg-warning "attribute directive ignored" } */
6+
}
7+
8+
static void __attribute__((no_sanitize("address,undefined")))
9+
foo2 (void) {
10+
}
11+
12+
static void __attribute__((no_sanitize("address", "undefined")))
13+
foo3 (void) {
14+
}
15+
16+
static void __attribute__((no_sanitize("address", "address", "")))
17+
foo4 (void) {
18+
}
19+
20+
static void __attribute__((no_sanitize("address", "address", "address,address")))
21+
foo5 (void) {
22+
}
23+
24+
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")))
25+
foo6 (void) {
26+
}

0 commit comments

Comments
 (0)