Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2732,10 +2732,10 @@ defm rewrite_includes : BoolFOption<"rewrite-includes",
defm directives_only : OptInCC1FFlag<"directives-only", "">;

defm delete_null_pointer_checks : BoolFOption<"delete-null-pointer-checks",
CodeGenOpts<"NullPointerIsValid">, DefaultFalse,
CodeGenOpts<"NullPointerIsValid">, Default<"LangOpts->Kernel">,
NegFlag<SetTrue, [], [ClangOption, CC1Option],
"Do not treat usage of null pointers as undefined behavior">,
PosFlag<SetFalse, [], [ClangOption], "Treat usage of null pointers as undefined behavior (default)">,
PosFlag<SetFalse, [], [ClangOption, CC1Option], "Treat usage of null pointers as undefined behavior (default)">,
BothFlags<[], [ClangOption, CLOption]>>,
DocBrief<[{When enabled, treat null pointer dereference, creation of a reference to null,
or passing a null pointer to a function parameter annotated with the "nonnull"
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CodeGen/MSKernel/null-deref.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 %s -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -fms-kernel -fms-extensions -triple x86_64-pc-windows-msvc -fdelete-null-pointer-checks %s -emit-llvm -o - | FileCheck %s --check-prefix=NOCHECK

// CHECK: define dso_local i32 @process(ptr noundef %p) #0
// CHECK: attributes #0 = {{.*}} null_pointer_is_valid
// NOCHECK-NOT: null_pointer_is_valid

struct Obj { int value; int extra; };

int process(struct Obj* p) {
int v = p->value;
if (!p)
return -1;
return v + p->extra;
}