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

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
5 changes: 5 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions clang/test/CodeGen/MSKernel/null-deref.c
Original file line number Diff line number Diff line change
@@ -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.

// 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;
}