Support LLVM style of no_sanitize attribute (PR sanitizer/85556).
authorMartin Liska <mliska@suse.cz>
Fri, 11 May 2018 07:37:35 +0000 (09:37 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 11 May 2018 07:37:35 +0000 (07:37 +0000)
2018-05-11  Martin Liska  <mliska@suse.cz>

        PR sanitizer/85556
* doc/extend.texi: Document LLVM style format for no_sanitize
attribute.
2018-05-11  Martin Liska  <mliska@suse.cz>

        PR sanitizer/85556
* c-attribs.c (handle_no_sanitize_attribute): Iterate all
TREE_LIST values.
2018-05-11  Martin Liska  <mliska@suse.cz>

        PR sanitizer/85556
* c-c++-common/ubsan/attrib-6.c: New test.

From-SVN: r260154

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-attribs.c
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/attrib-6.c [new file with mode: 0644]

index e5c1d8e7c92099775c385cb7592d95fd0166452f..75ed3b33f70463913cb63d75efa04561754a6634 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-11  Martin Liska  <mliska@suse.cz>
+
+        PR sanitizer/85556
+       * doc/extend.texi: Document LLVM style format for no_sanitize
+       attribute.
+
 2018-05-10  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        * config/rs6000/rs6000.c (mode_supports_dq_form): Rename
index 052b22265881435922436fff79e493b9840bd5f6..d2fba2fae8a3acae5254ed262e3dadf24609514d 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-11  Martin Liska  <mliska@suse.cz>
+
+        PR sanitizer/85556
+       * c-attribs.c (handle_no_sanitize_attribute): Iterate all
+       TREE_LIST values.
+
 2018-05-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/85662
index 9bddc1aad4f11d59dd0f85e1dff04a8890d988fa..d302b4f22c7863c4a04aa828b73d8f63543b91da 100644 (file)
@@ -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);
 
index 9d085844cfde04b8f0a72f512b999c21c70b20cb..a4664cad8195619065df1ba6ae54b1c2aa9871a3 100644 (file)
@@ -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
index bafd284857a52c82b8d40de1461cd1d110b26f32..ee9f633ad8473a48576645450e59b0a9708ed896 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-11  Martin Liska  <mliska@suse.cz>
+
+        PR sanitizer/85556
+       * c-c++-common/ubsan/attrib-6.c: New test.
+
 2018-05-10  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/85687
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 (file)
index 0000000..2af70c8
--- /dev/null
@@ -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) {
+}