[PATCH] D62559: [WebAssembly] Support VPtr sanitizer for Emscripten

Guanzhong Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 28 18:11:08 PDT 2019


quantum updated this revision to Diff 201803.
quantum marked an inline comment as done.
quantum added a comment.

Add a test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62559/new/

https://reviews.llvm.org/D62559

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/lib/Driver/ToolChains/WebAssembly.h
  clang/test/CodeGenCXX/wasm-sanitize-vptr.cpp


Index: clang/test/CodeGenCXX/wasm-sanitize-vptr.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/wasm-sanitize-vptr.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsanitize=vptr -emit-llvm %s -o - -triple wasm32-unknown-emscripten | FileCheck %s
+
+struct S {
+  virtual ~S() {}
+  int a;
+};
+
+struct T : S {
+  int b;
+};
+
+// CHECK-LABEL: @_Z15bad_static_castv
+void bad_static_cast() {
+  S s;
+  // CHECK: br i1 %[[NONNULL:.*]], label %[[CONT:.*]], label %[[MISS:.*]], !prof
+  // CHECK: [[MISS]]:
+  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss_abort
+  // CHECK: [[CONT]]:
+  T &r = static_cast<T &>(s);
+}
Index: clang/lib/Driver/ToolChains/WebAssembly.h
===================================================================
--- clang/lib/Driver/ToolChains/WebAssembly.h
+++ clang/lib/Driver/ToolChains/WebAssembly.h
@@ -66,6 +66,7 @@
       llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
                            llvm::opt::ArgStringList &CmdArgs) const override;
+  SanitizerMask getSupportedSanitizers() const override;
 
   const char *getDefaultLinker() const override { return "wasm-ld"; }
 
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===================================================================
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -208,6 +208,14 @@
   }
 }
 
+SanitizerMask WebAssembly::getSupportedSanitizers() const {
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (getTriple().isOSEmscripten()) {
+    Res |= SanitizerKind::Vptr;
+  }
+  return Res;
+}
+
 Tool *WebAssembly::buildLinker() const {
   return new tools::wasm::Linker(*this);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62559.201803.patch
Type: text/x-patch
Size: 1808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190529/79d61893/attachment-0001.bin>


More information about the cfe-commits mailing list