Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -121,8 +121,12 @@ #define DEBUG_TYPE "msan" static const uint64_t kShadowMask32 = 1ULL << 31; +static const uint64_t kMIPS32_ShadowMask32 = 0x40000000UL; static const uint64_t kShadowMask64 = 1ULL << 46; +static const uint64_t kMIPS64_ShadowMask64 = 0x4000000000ULL; static const uint64_t kOriginOffset32 = 1ULL << 30; +static const uint64_t kMIPS32_OriginOffset32 = 0x20000000UL; +static const uint64_t kMIPS64_OriginOffset64 = 0x2000000000ULL; static const uint64_t kOriginOffset64 = 1ULL << 45; static const unsigned kMinOriginAlignment = 4; static const unsigned kShadowTLSAlignment = 8; @@ -423,6 +427,14 @@ /// /// inserts a call to __msan_init to the module's constructor list. bool MemorySanitizer::doInitialization(Module &M) { + llvm::Triple TargetTriple(M.getTargetTriple()); + bool IsMIPS32 = TargetTriple.getArch() == llvm::Triple::mips || + TargetTriple.getArch() == llvm::Triple::mipsel; + bool IsMIPS64 = TargetTriple.getArch() == llvm::Triple::mips64 || + TargetTriple.getArch() == llvm::Triple::mips64el; + bool IsX86_64 = TargetTriple.getArch() == llvm::Triple::x86_64; + bool IsX86 = TargetTriple.getArch() == llvm::Triple::x86; + DataLayoutPass *DLP = getAnalysisIfAvailable(); if (!DLP) report_fatal_error("data layout missing"); @@ -432,12 +444,22 @@ unsigned PtrSize = DL->getPointerSizeInBits(/* AddressSpace */0); switch (PtrSize) { case 64: - ShadowMask = kShadowMask64; - OriginOffset = kOriginOffset64; + if (IsMIPS64) { + ShadowMask = kMIPS64_ShadowMask64; + OriginOffset = kMIPS64_OriginOffset64; + } else if (IsX86_64) { + ShadowMask = kShadowMask64; + OriginOffset = kOriginOffset64; + } break; case 32: - ShadowMask = kShadowMask32; - OriginOffset = kOriginOffset32; + if (IsMIPS32) { + ShadowMask = kMIPS32_ShadowMask32; + OriginOffset = kMIPS32_OriginOffset32; + } else if (IsX86) { + ShadowMask = kShadowMask32; + OriginOffset = kOriginOffset32; + } break; default: report_fatal_error("unsupported pointer size");