[clang] [clang] Add test for memcpy from nullptr. NFC (PR #196283)
eleviant wrote: MSVC may omit null pointer checks even if /kernel is set: https://godbolt.org/z/3MM8xd6rs https://github.com/llvm/llvm-project/pull/196283 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for memcpy from nullptr. NFC (PR #196283)
https://github.com/eleviant closed https://github.com/llvm/llvm-project/pull/196283 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for memcpy from nullptr. NFC (PR #196283)
eleviant wrote: > Is this dependent on #193800 ? Yep. I think it makes sense to wait with this till we reland that patch again. https://github.com/llvm/llvm-project/pull/196283 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for memcpy from nullptr. NFC (PR #196283)
dpaoliello wrote: Is this dependent on #193800 ? https://github.com/llvm/llvm-project/pull/196283 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for memcpy from nullptr. NFC (PR #196283)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clang
Author: eleviant
Changes
Patch tests that memcpy from nullptr is not treated as UB and is not optimized
out when -fms-kernel is provided, because null pointer is a valid address in
kernel space.
---
Full diff: https://github.com/llvm/llvm-project/pull/196283.diff
1 Files Affected:
- (added) clang/test/CodeGen/MSKernel/memcpy0.c (+21)
``diff
diff --git a/clang/test/CodeGen/MSKernel/memcpy0.c
b/clang/test/CodeGen/MSKernel/memcpy0.c
new file mode 100644
index 0..7c31e6b86ec56
--- /dev/null
+++ b/clang/test/CodeGen/MSKernel/memcpy0.c
@@ -0,0 +1,21 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -fms-kernel -triple x86_64-windows-msvc -O2 -emit-llvm %s
-o - | FileCheck %s --check-prefix=IR
+// RUN: %clang_cc1 -fms-kernel -triple x86_64-windows-msvc -O2 -S %s -o - |
FileCheck %s --check-prefix=ASM
+
+// LLVM selects alignment of 1 << 32 for null pointer,
+// which is a maximum allowed value according to
https://llvm.org/docs/LangRef.html
+// IR: define {{.*}} void @builtin_copy_from_nullptr
+// IR-NEXT: entry:
+// IR-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %dst, ptr align
4294967296 null, i64 %n, i1 false)
+// IR-NEXT: ret void
+
+// ASM: builtin_copy_from_nullptr:
+// ASM-NEXT: # %bb.0:
+// ASM-NEXT: movq %rdx, %r8
+// ASM-NEXT: xorl %edx, %edx
+// ASM-NEXT: jmp memcpy
+
+void builtin_copy_from_nullptr(void* dst, long long n) {
+__builtin_memcpy(dst, (void*)0, n);
+}
+
``
https://github.com/llvm/llvm-project/pull/196283
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Add test for memcpy from nullptr. NFC (PR #196283)
https://github.com/eleviant created
https://github.com/llvm/llvm-project/pull/196283
Patch tests that memcpy from nullptr is not treated as UB and is not optimized
out when -fms-kernel is provided, because null pointer is a valid address in
kernel space.
>From fc3ea0f3a413b322978545e841c31b9fa319acad Mon Sep 17 00:00:00 2001
From: Evgeny Leviant
Date: Wed, 15 Apr 2026 12:02:58 +0200
Subject: [PATCH] [clang] Add test for memcpy from nullptr. NFC
Patch tests that memcpy from nullptr is not treated as UB and is not
optimized out when -fms-kernel is provided, because null pointer is a
valid address in kernel space.
---
clang/test/CodeGen/MSKernel/memcpy0.c | 21 +
1 file changed, 21 insertions(+)
create mode 100644 clang/test/CodeGen/MSKernel/memcpy0.c
diff --git a/clang/test/CodeGen/MSKernel/memcpy0.c
b/clang/test/CodeGen/MSKernel/memcpy0.c
new file mode 100644
index 0..7c31e6b86ec56
--- /dev/null
+++ b/clang/test/CodeGen/MSKernel/memcpy0.c
@@ -0,0 +1,21 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -fms-kernel -triple x86_64-windows-msvc -O2 -emit-llvm %s
-o - | FileCheck %s --check-prefix=IR
+// RUN: %clang_cc1 -fms-kernel -triple x86_64-windows-msvc -O2 -S %s -o - |
FileCheck %s --check-prefix=ASM
+
+// LLVM selects alignment of 1 << 32 for null pointer,
+// which is a maximum allowed value according to
https://llvm.org/docs/LangRef.html
+// IR: define {{.*}} void @builtin_copy_from_nullptr
+// IR-NEXT: entry:
+// IR-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %dst, ptr align
4294967296 null, i64 %n, i1 false)
+// IR-NEXT: ret void
+
+// ASM: builtin_copy_from_nullptr:
+// ASM-NEXT: # %bb.0:
+// ASM-NEXT: movq %rdx, %r8
+// ASM-NEXT: xorl %edx, %edx
+// ASM-NEXT: jmp memcpy
+
+void builtin_copy_from_nullptr(void* dst, long long n) {
+__builtin_memcpy(dst, (void*)0, n);
+}
+
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
