From b8a5f994a88662e87de1ca45daaf106d970ab7d5 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad@gmail.com>
Date: Thu, 25 Jun 2015 10:35:19 +0000
Subject: [PATCH] Teach Clang about the PPC64 memory sanitizer implementation.

Summary:
This is the Clang part of the PPC64 memory sanitizer implementation in
D10648.

Reviewers: kcc, eugenis, willschm, wschmidt, samsonov

Reviewed By: samsonov

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D10650

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240628 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Driver/ToolChains.cpp |  5 ++++-
 test/Driver/fsanitize.c   |  4 ++++
 test/Driver/msan.c        | 12 ++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 test/Driver/msan.c

diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 4c69716dc14..6ca80166506 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -3669,6 +3669,8 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
   const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 ||
                         getTriple().getArch() == llvm::Triple::mips64el;
+  const bool IsPowerPC64 = getTriple().getArch() == llvm::Triple::ppc64 ||
+                           getTriple().getArch() == llvm::Triple::ppc64le;
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
@@ -3676,9 +3678,10 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   if (IsX86_64 || IsMIPS64) {
     Res |= SanitizerKind::DataFlow;
     Res |= SanitizerKind::Leak;
-    Res |= SanitizerKind::Memory;
     Res |= SanitizerKind::Thread;
   }
+  if (IsX86_64 || IsMIPS64 || IsPowerPC64)
+    Res |= SanitizerKind::Memory;
   if (IsX86 || IsX86_64) {
     Res |= SanitizerKind::Function;
     Res |= SanitizerKind::SafeStack;
diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c
index 1c39feb3d82..b124b5b4b75 100644
--- a/test/Driver/fsanitize.c
+++ b/test/Driver/fsanitize.c
@@ -263,3 +263,7 @@
 // SP: "-fsanitize=safe-stack"
 // SP-ASAN-NOT: stack-protector
 // SP-ASAN: "-fsanitize=address,safe-stack"
+
+// RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
+// CHECK-SANM: "-fsanitize=memory"
diff --git a/test/Driver/msan.c b/test/Driver/msan.c
new file mode 100644
index 00000000000..22f7471510a
--- /dev/null
+++ b/test/Driver/msan.c
@@ -0,0 +1,12 @@
+// RUN: %clang     -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O1 -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O2 -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -O3 -target x86_64-unknown-linux -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -target mips64-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -target mips64el-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -S -emit-llvm -o - | FileCheck %s
+// Verify that -fsanitize=memory invokes msan instrumentation.
+
+int foo(int *a) { return *a; }
+// CHECK: __msan_init
-- 
GitLab