diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -439,6 +439,14 @@ 0x0200000000000, // OriginBase }; +// loongarch64 Linux +static const MemoryMapParams Linux_LoongArch64_MemoryMapParams = { + 0, // AndMask (not used) + 0x500000000000, // XorMask + 0, // ShadowBase (not used) + 0x100000000000, // OriginBase +}; + // aarch64 FreeBSD static const MemoryMapParams FreeBSD_AArch64_MemoryMapParams = { 0x1800000000000, // AndMask @@ -496,6 +504,11 @@ &Linux_AArch64_MemoryMapParams, }; +static const PlatformMemoryMapParams Linux_LoongArch_MemoryMapParams = { + nullptr, + &Linux_LoongArch64_MemoryMapParams, +}; + static const PlatformMemoryMapParams FreeBSD_ARM_MemoryMapParams = { nullptr, &FreeBSD_AArch64_MemoryMapParams, @@ -1017,6 +1030,9 @@ case Triple::aarch64_be: MapParams = Linux_ARM_MemoryMapParams.bits64; break; + case Triple::loongarch64: + MapParams = Linux_LoongArch_MemoryMapParams.bits64; + break; default: report_fatal_error("unsupported architecture"); } diff --git a/llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg.ll b/llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg.ll @@ -0,0 +1,14 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 +; Test that code using va_start can be compiled on LoongArch. + +target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128" +target triple = "loongarch64-unknown-linux-gnu" + +define void @VaStart(ptr %s, ...) { +entry: + %vl = alloca ptr, align 4 + call void @llvm.va_start(ptr %vl) + ret void +} + +declare void @llvm.va_start(ptr)