Don't omit null pointer checks with -fms-kernel#193800
Open
Don't omit null pointer checks with -fms-kernel#193800
Conversation
Member
|
@llvm/pr-subscribers-clang Author: eleviant ChangesFull diff: https://github.com/llvm/llvm-project/pull/193800.diff 2 Files Affected:
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;
+}
|
dpaoliello
reviewed
Apr 23, 2026
| @@ -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 | |||
Contributor
There was a problem hiding this comment.
Please check in the IR that the function has the correct attribute applied - otherwise this test requires the x86 target.
dpaoliello
requested changes
Apr 23, 2026
Contributor
dpaoliello
left a comment
There was a problem hiding this comment.
You may also want to update the title to include [clang]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.