From 8fbe358b34178b55097b76f1e74858345ce1fd10 Mon Sep 17 00:00:00 2001 From: Rohan Jacob-Rao Date: Tue, 4 Aug 2015 11:00:29 -0700 Subject: [PATCH] Add tiny C example of null pointer error. --- infer/src/llvm/examples/null_deref.c | 4 ++++ infer/src/llvm/examples/null_deref.ll | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 infer/src/llvm/examples/null_deref.c create mode 100644 infer/src/llvm/examples/null_deref.ll diff --git a/infer/src/llvm/examples/null_deref.c b/infer/src/llvm/examples/null_deref.c new file mode 100644 index 000000000..01201b7b1 --- /dev/null +++ b/infer/src/llvm/examples/null_deref.c @@ -0,0 +1,4 @@ +void foo(void) { + int *p = 0; + *p = 42; +} diff --git a/infer/src/llvm/examples/null_deref.ll b/infer/src/llvm/examples/null_deref.ll new file mode 100644 index 000000000..52d06ee34 --- /dev/null +++ b/infer/src/llvm/examples/null_deref.ll @@ -0,0 +1,18 @@ +; ModuleID = 'null_deref.c' +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.10.0" + +; Function Attrs: nounwind ssp uwtable +define void @foo() #0 { + %p = alloca i32*, align 8 + store i32* null, i32** %p, align 8 + %1 = load i32** %p, align 8 + store i32 42, i32* %1, align 4 + ret void +} + +attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = metadata !{metadata !"Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)"}