Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -122,8 +122,10 @@ static const uint64_t kShadowMask32 = 1ULL << 31; 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 kOriginOffset64 = 1ULL << 45; +static const uint64_t kMIPS64_OriginOffset64 = 0x2000000000ULL; static const unsigned kMinOriginAlignment = 4; static const unsigned kShadowTLSAlignment = 8; @@ -424,6 +426,12 @@ /// /// inserts a call to __msan_init to the module's constructor list. bool MemorySanitizer::doInitialization(Module &M) { + llvm::Triple TargetTriple(M.getTargetTriple()); + bool IsX86_64 = TargetTriple.getArch() == llvm::Triple::x86_64; + bool IsX86 = TargetTriple.getArch() == llvm::Triple::x86; + bool IsMIPS64 = TargetTriple.getArch() == llvm::Triple::mips64 || + TargetTriple.getArch() == llvm::Triple::mips64el; + DataLayoutPass *DLP = getAnalysisIfAvailable(); if (!DLP) report_fatal_error("data layout missing"); @@ -433,12 +441,23 @@ unsigned PtrSize = DL->getPointerSizeInBits(/* AddressSpace */0); switch (PtrSize) { case 64: - ShadowMask = kShadowMask64; - OriginOffset = kOriginOffset64; + if (IsX86_64) { + ShadowMask = kShadowMask64; + OriginOffset = kOriginOffset64; + } else if (IsMIPS64) { + ShadowMask = kMIPS64_ShadowMask64; + OriginOffset = kMIPS64_OriginOffset64; + } else { + report_fatal_error("unsupported triple"); + } break; case 32: - ShadowMask = kShadowMask32; - OriginOffset = kOriginOffset32; + if (IsX86) { + ShadowMask = kShadowMask32; + OriginOffset = kOriginOffset32; + } else { + report_fatal_error("unsupported triple"); + } break; default: report_fatal_error("unsupported pointer size");