Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Don't omit null pointer checks with -fms-kernel#193800

Open
eleviant wants to merge 1 commit intollvm:mainfrom
eleviant:null-checks-in-mskernel
Open

Don't omit null pointer checks with -fms-kernel#193800
eleviant wants to merge 1 commit intollvm:mainfrom
eleviant:null-checks-in-mskernel

Conversation

@eleviant
Copy link
Copy Markdown
Contributor

No description provided.

@eleviant eleviant requested a review from dpaoliello April 23, 2026 17:19
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 23, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Apr 23, 2026

@llvm/pr-subscribers-clang

Author: eleviant

Changes

Full diff: https://github.com/llvm/llvm-project/pull/193800.diff

2 Files Affected:

  • (modified) clang/lib/Frontend/CompilerInvocation.cpp (+5)
  • (added) clang/test/CodeGen/MSKernel/null-deref.c (+13)
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index c6e8644905964..a8a5d57155228 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1924,6 +1924,11 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
     Opts.DIBugsReportFilePath = "";
   }
 
+  if (LangOpts->Kernel &&
+      !Args.hasFlag(OPT_fdelete_null_pointer_checks,
+                    OPT_fno_delete_null_pointer_checks, false))
+    Opts.NullPointerIsValid = true;
+
   Opts.NewStructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa) &&
                            Args.hasArg(OPT_new_struct_path_tbaa);
   Opts.OptimizeSize = getOptimizationLevelSize(Args);
diff --git a/clang/test/CodeGen/MSKernel/null-deref.c b/clang/test/CodeGen/MSKernel/null-deref.c
new file mode 100644
index 0000000000000..c1b016f2b07ca
--- /dev/null
+++ b/clang/test/CodeGen/MSKernel/null-deref.c
@@ -0,0 +1,13 @@
+// Check that null pointer checks are not omited in kernel mode compilations
+// RUN: %clang_cc1 -fms-kernel -fms-extensions -triple x86_64-pc-windows-msvc -O2 %s -S -o - | FileCheck %s
+// CHECK:      # %bb.0
+// CHECK-NEXT:   testq %rcx, %rcx
+
+struct Obj { int value; int extra; };
+
+int process(struct Obj* p) {
+    int v = p->value;
+    if (!p)
+        return -1;
+    return v + p->extra;
+}

@@ -0,0 +1,13 @@
// Check that null pointer checks are not omited in kernel mode compilations
// RUN: %clang_cc1 -fms-kernel -fms-extensions -triple x86_64-pc-windows-msvc -O2 %s -S -o - | FileCheck %s
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check in the IR that the function has the correct attribute applied - otherwise this test requires the x86 target.

Copy link
Copy Markdown
Contributor

@dpaoliello dpaoliello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also want to update the title to include [clang]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants