dougk updated this revision to Diff 77815.
dougk marked an inline comment as done.
dougk added a comment.

add a sentence about the change in AddressSanitizer.rst


https://reviews.llvm.org/D26454

Files:
  docs/AddressSanitizer.rst
  lib/CodeGen/SanitizerMetadata.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/asan-globals.cpp
  test/SemaCXX/attr-no-sanitize-address.cpp

Index: test/SemaCXX/attr-no-sanitize-address.cpp
===================================================================
--- test/SemaCXX/attr-no-sanitize-address.cpp
+++ test/SemaCXX/attr-no-sanitize-address.cpp
@@ -16,8 +16,11 @@
 int noanal_testfn(int y) NO_SANITIZE_ADDRESS;
 
 int noanal_testfn(int y) {
+  // Test the deprecated spelling of no_sanitize("address")
   int x NO_SANITIZE_ADDRESS = y; // \
-    // expected-error {{'no_sanitize_address' attribute only applies to functions}}
+    // expected-error {{'no_sanitize_address' attribute only applies to functions and global variables}}
+  int x2 __attribute__((no_sanitize("address"))) = y; // \
+    // expected-error {{'no_sanitize' attribute only applies to functions, methods, and global variables}}
   return x;
 }
 
Index: test/CodeGen/asan-globals.cpp
===================================================================
--- test/CodeGen/asan-globals.cpp
+++ test/CodeGen/asan-globals.cpp
@@ -7,7 +7,8 @@
 
 int global;
 int dyn_init_global = global;
-int __attribute__((no_sanitize("address"))) attributed_global;
+int __attribute__((no_sanitize("address"))) attributed_global1;
+int __attribute__((no_sanitize_address)) attributed_global2;
 int blacklisted_global;
 
 void func() {
@@ -15,26 +16,28 @@
   const char *literal = "Hello, world!";
 }
 
-// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[BLACKLISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL1:[0-9]+]], ![[ATTR_GLOBAL2:[0-9]+]], ![[BLACKLISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false}
 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 8, i32 5}
 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false}
 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 9, i32 5}
-// CHECK: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[ATTR_GLOBAL1]] = !{{{.*}}, null, null, i1 false, i1 true}
+// CHECK: ![[ATTR_GLOBAL2]] = !{{{.*}}, null, null, i1 false, i1 true}
 // CHECK: ![[BLACKLISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
 // CHECK: ![[STATIC_VAR]] = !{{{.*}} ![[STATIC_LOC:[0-9]+]], !"static_var", i1 false, i1 false}
-// CHECK: ![[STATIC_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 14, i32 14}
+// CHECK: ![[STATIC_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 15, i32 14}
 // CHECK: ![[LITERAL]] = !{{{.*}} ![[LITERAL_LOC:[0-9]+]], !"<string literal>", i1 false, i1 false}
-// CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 15, i32 25}
+// CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 16, i32 25}
 
-// BLACKLIST-SRC: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[BLACKLISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// BLACKLIST-SRC: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL1:[0-9]+]], ![[ATTR_GLOBAL2:[0-9]+]], ![[BLACKLISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
 // BLACKLIST-SRC: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false}
 // BLACKLIST-SRC: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // BLACKLIST-SRC: ![[GLOBAL]] = !{{{.*}} null, null, i1 false, i1 true}
 // BLACKLIST-SRC: ![[DYN_INIT_GLOBAL]] = !{{{.*}} null, null, i1 true, i1 true}
-// BLACKLIST-SRC: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
+// BLACKLIST-SRC: ![[ATTR_GLOBAL1]] = !{{{.*}}, null, null, i1 false, i1 true}
+// BLACKLIST-SRC: ![[ATTR_GLOBAL2]] = !{{{.*}}, null, null, i1 false, i1 true}
 // BLACKLIST-SRC: ![[BLACKLISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true}
 // BLACKLIST-SRC: ![[STATIC_VAR]] = !{{{.*}} null, null, i1 false, i1 true}
 // BLACKLIST-SRC: ![[LITERAL]] = !{{{.*}} null, null, i1 false, i1 true}
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5319,9 +5319,9 @@
         !(Attr.hasScope() && Attr.getScopeName()->isStr("gnu")))
       S.Diag(Attr.getLoc(), diag::ext_cxx14_attr) << Attr.getName();
 
-  D->addAttr(::new (S.Context)
-                 DeprecatedAttr(Attr.getRange(), S.Context, Str, Replacement,
-                                Attr.getAttributeSpellingListIndex()));
+  D->addAttr(::new (S.Context) DeprecatedAttr(Attr.getRange(), S.Context,
+                                              Str, Replacement,
+                                              Attr.getAttributeSpellingListIndex()));
 }
 
 static bool isGlobalVar(const Decl *D) {
@@ -5345,9 +5345,11 @@
 
     if (parseSanitizerValue(SanitizerName, /*AllowGroups=*/true) == 0)
       S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
-    else if (isGlobalVar(D) && SanitizerName != "address")
+    else if (isGlobalVar(D) && SanitizerName != "address") {
       S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
           << Attr.getName() << ExpectedFunctionOrMethod;
+      return;
+    }
     Sanitizers.push_back(SanitizerName);
   }
 
@@ -5365,9 +5367,11 @@
                                 .Case("no_sanitize_address", "address")
                                 .Case("no_sanitize_thread", "thread")
                                 .Case("no_sanitize_memory", "memory");
-  if (isGlobalVar(D) && SanitizerName != "address")
+  if (isGlobalVar(D) && SanitizerName != "address") {
     S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
         << Attr.getName() << ExpectedFunction;
+    return;
+  }
   D->addAttr(::new (S.Context)
                  NoSanitizeAttr(Attr.getRange(), S.Context, &SanitizerName, 1,
                                 Attr.getAttributeSpellingListIndex()));
Index: lib/CodeGen/SanitizerMetadata.cpp
===================================================================
--- lib/CodeGen/SanitizerMetadata.cpp
+++ lib/CodeGen/SanitizerMetadata.cpp
@@ -65,7 +65,7 @@
   D.printQualifiedName(OS);
 
   bool IsBlacklisted = false;
-  for (auto Attr : D.specific_attrs<NoSanitizeAttr>())
+  for (const auto *Attr : D.specific_attrs<NoSanitizeAttr>())
     if (Attr->getMask() & SanitizerKind::Address)
       IsBlacklisted = true;
   reportGlobalToASan(GV, D.getLocation(), OS.str(), D.getType(), IsDynInit,
Index: docs/AddressSanitizer.rst
===================================================================
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -199,7 +199,9 @@
 Some code should not be instrumented by AddressSanitizer. One may use the
 function attribute ``__attribute__((no_sanitize("address")))`` (which has
 deprecated synonyms `no_sanitize_address` and `no_address_safety_analysis`) to
-disable instrumentation of a particular function. This attribute may not be
+disable instrumentation of a particular function. A global variable may
+be similarly marked, as is typically necessary if its address corresponds
+to a memory-mapped I/O range. This attribute may not be
 supported by other compilers, so we suggest to use it together with
 ``__has_feature(address_sanitizer)``.
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to