Summary: This frontend is not supported. Reviewed By: sblackshear Differential Revision: D3981323 fbshipit-source-id: 82b7422master
parent
b736f672e7
commit
eb391d7875
@ -1,3 +0,0 @@
|
||||
REC
|
||||
S *
|
||||
B ../../_build/llvm/**
|
@ -1,82 +0,0 @@
|
||||
(*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! Utils
|
||||
|
||||
(** Representation of LLVM constructs *)
|
||||
|
||||
module MetadataMap = IntMap;;
|
||||
|
||||
type variable_id =
|
||||
| Name of string
|
||||
| Number of int
|
||||
|
||||
type variable =
|
||||
| Global of variable_id
|
||||
| Local of variable_id
|
||||
|
||||
type constant =
|
||||
| Cint of int
|
||||
| Cnull
|
||||
|
||||
type operand =
|
||||
| Var of variable
|
||||
| Const of constant
|
||||
|
||||
type typ =
|
||||
| Tint of int
|
||||
| Tfloat (* just one type for now *)
|
||||
| Tptr of typ
|
||||
| Tvector of int * typ
|
||||
| Tarray of int * typ
|
||||
| Tfunc of typ option * typ list
|
||||
| Tlabel
|
||||
| Tmetadata
|
||||
|
||||
type metadata_value =
|
||||
| MetadataVar of int
|
||||
| MetadataString of string
|
||||
| MetadataNode of metadata_component list
|
||||
|
||||
and metadata_component =
|
||||
| TypOperand of typ option * operand
|
||||
| MetadataVal of metadata_value
|
||||
|
||||
type metadata_location = { line : int; col : int; scope : metadata_value }
|
||||
|
||||
type metadata_aggregate =
|
||||
| Components of metadata_component list
|
||||
| Location of metadata_location
|
||||
|
||||
type instruction =
|
||||
| Ret of (typ * operand) option
|
||||
| UncondBranch of variable
|
||||
| CondBranch of operand * variable * variable
|
||||
| Load of variable * typ * variable
|
||||
| Store of operand * typ * variable
|
||||
| Alloc of variable * typ * int (* return variable, element type, number of elements *)
|
||||
| Call of variable * variable * (typ * operand) list (* return variable, function pointer, arguments *)
|
||||
| Binop
|
||||
|
||||
type annotation = Annotation of int
|
||||
|
||||
type annotated_instruction = instruction * annotation option
|
||||
|
||||
type function_def = FunctionDef of variable * typ option * (typ * string) list * annotated_instruction list
|
||||
|
||||
type metadata_map = metadata_aggregate MetadataMap.t
|
||||
|
||||
type program = Program of function_def list * metadata_map
|
||||
|
||||
let string_of_variable : variable -> string = function
|
||||
| Global var_id | Local var_id ->
|
||||
begin match var_id with
|
||||
| Name str -> str
|
||||
| Number i -> string_of_int i
|
||||
end
|
@ -1,60 +0,0 @@
|
||||
(*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! Utils
|
||||
|
||||
let register_perf_stats_report source_file =
|
||||
let stats_dir = Filename.concat Config.results_dir Config.frontend_stats_dir_name in
|
||||
let abbrev_source_file = DB.source_file_encoding source_file in
|
||||
let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json" in
|
||||
create_dir Config.results_dir ;
|
||||
create_dir stats_dir ;
|
||||
PerfStats.register_report_at_exit (Filename.concat stats_dir stats_file)
|
||||
|
||||
let init_global_state source_file =
|
||||
Config.curr_language := Config.Clang;
|
||||
register_perf_stats_report source_file;
|
||||
DB.Results_dir.init source_file;
|
||||
Ident.NameGenerator.reset ();
|
||||
Config.nLOC := FileLOC.file_get_loc (DB.source_file_to_string source_file)
|
||||
|
||||
let store_icfg source_file cg cfg =
|
||||
let source_dir = DB.source_dir_from_source_file source_file in
|
||||
let get_internal_file = DB.source_dir_get_internal_file source_dir in
|
||||
let cg_file = get_internal_file ".cg" in
|
||||
let cfg_file = get_internal_file ".cfg" in
|
||||
Cg.store_to_file cg_file cg;
|
||||
Cfg.store_cfg_to_file ~source_file cfg_file cfg;
|
||||
if Config.debug_mode || Config.frontend_tests then
|
||||
begin
|
||||
Dotty.print_icfg_dotty source_file cfg;
|
||||
Cg.save_call_graph_dotty source_file Specs.get_specs cg
|
||||
end
|
||||
|
||||
let store_tenv tenv =
|
||||
if DB.file_exists DB.global_tenv_fname then DB.file_remove DB.global_tenv_fname;
|
||||
Tenv.store_to_file DB.global_tenv_fname tenv
|
||||
|
||||
let () =
|
||||
let source_file = match Config.source_file with
|
||||
| None ->
|
||||
Config.print_usage_exit ()
|
||||
| Some source_file ->
|
||||
begin match Config.project_root with
|
||||
| None ->
|
||||
DB.abs_source_file_from_path source_file
|
||||
| Some project_root ->
|
||||
DB.rel_source_file_from_abs_path project_root (filename_to_absolute source_file)
|
||||
end in
|
||||
init_global_state source_file;
|
||||
let lexbuf = Lexing.from_channel stdin in
|
||||
let prog = LParser.program LLexer.token lexbuf in
|
||||
let (cfg, cg, tenv) = LTrans.trans_program source_file prog in
|
||||
store_icfg source_file cg cfg;
|
||||
store_tenv tenv
|
@ -1,59 +0,0 @@
|
||||
(*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! Utils
|
||||
|
||||
open LAst
|
||||
|
||||
let concatmap (sep : string) (f : 'a -> string) (l : 'a list) : string =
|
||||
String.concat sep (List.map f l)
|
||||
|
||||
let pretty_variable : variable -> string = function
|
||||
| Global id -> "@" ^ id
|
||||
| Local id -> "%" ^ id
|
||||
|
||||
let pretty_constant : constant -> string = function
|
||||
| Cint i -> string_of_int i
|
||||
| Cnull -> "null"
|
||||
|
||||
let pretty_operand : operand -> string = function
|
||||
| Var var -> pretty_variable var
|
||||
| Const const -> pretty_constant const
|
||||
|
||||
let rec pretty_typ : typ -> string = function
|
||||
| Tint width -> "i" ^ string_of_int width
|
||||
| Tfloat (* just one type for now *) -> "float"
|
||||
| Tptr tp -> pretty_typ tp ^ "*"
|
||||
| Tvector (sz, tp) -> "<" ^ string_of_int sz ^ " x " ^ pretty_typ tp ^ ">"
|
||||
| Tlabel -> "label"
|
||||
| Tmetadata -> "metadata"
|
||||
| Tarray (sz, tp) -> "[" ^ string_of_int sz ^ " x " ^ pretty_typ tp ^ "]"
|
||||
|
||||
let pretty_ret_typ : typ option -> string = function
|
||||
| None -> "void"
|
||||
| Some tp -> pretty_typ tp
|
||||
|
||||
let pretty_instr : instr -> string = function
|
||||
| Ret None -> "ret void"
|
||||
| Ret (Some (tp, op)) -> "ret " ^ pretty_typ tp ^ " " ^ pretty_operand op
|
||||
| UncondBranch label -> "br label " ^ pretty_variable label
|
||||
| CondBranch (op, label1, label2) ->
|
||||
"br i1 " ^ pretty_operand op ^ ", label " ^ pretty_variable label1 ^
|
||||
", label " ^ pretty_variable label2
|
||||
|
||||
let pretty_instr_ln (i : instr) : string = pretty_instr i ^ "\n"
|
||||
|
||||
let pretty_func_def : func_def -> string = function
|
||||
FuncDef (name, ret_tp, params, instrs) ->
|
||||
"define " ^ pretty_ret_typ ret_tp ^ " " ^ pretty_variable name ^ "(" ^
|
||||
concatmap ", " (fun (tp, id) -> pretty_typ tp ^ " " ^ id) params ^ ") {\n" ^
|
||||
concatmap "" pretty_instr_ln instrs ^ "}\n"
|
||||
|
||||
let pretty_prog : prog -> string = function
|
||||
Prog func_defs -> concatmap "" pretty_func_def func_defs
|
@ -1,175 +0,0 @@
|
||||
(*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! Utils
|
||||
|
||||
open LAst
|
||||
|
||||
exception ImproperTypeError of string
|
||||
exception MalformedMetadata of string
|
||||
exception Unimplemented of string
|
||||
|
||||
let source_only_location source_file : Location.t =
|
||||
let open Location in { line = -1; col = -1; file = source_file; nLOC = !Config.nLOC }
|
||||
|
||||
let ident_of_variable (var : LAst.variable) : Ident.t = (* TODO: use unique stamps *)
|
||||
Ident.create_normal (Ident.string_to_name (LAst.string_of_variable var)) 0
|
||||
|
||||
let trans_variable (var : LAst.variable) : Exp.t = Exp.Var (ident_of_variable var)
|
||||
|
||||
let trans_constant : LAst.constant -> Exp.t = function
|
||||
| Cint i -> Exp.Const (Const.Cint (IntLit.of_int i))
|
||||
| Cnull -> Exp.null
|
||||
|
||||
let trans_operand : LAst.operand -> Exp.t = function
|
||||
| Var var -> trans_variable var
|
||||
| Const const -> trans_constant const
|
||||
|
||||
let rec trans_typ : LAst.typ -> Typ.t = function
|
||||
| Tint _i -> Typ.Tint Typ.IInt (* TODO: check what size int is needed here *)
|
||||
| Tfloat -> Typ.Tfloat Typ.FFloat
|
||||
| Tptr tp -> Typ.Tptr (trans_typ tp, Typ.Pk_pointer)
|
||||
| Tvector (i, tp)
|
||||
| Tarray (i, tp) -> Typ.Tarray (trans_typ tp, Some (IntLit.of_int i))
|
||||
| Tfunc _ -> Typ.Tfun false
|
||||
| Tlabel -> raise (ImproperTypeError "Tried to generate Sil type from LLVM label type.")
|
||||
| Tmetadata -> raise (ImproperTypeError "Tried to generate Sil type from LLVM metadata type.")
|
||||
|
||||
let location_of_annotation_option source_file (metadata : LAst.metadata_map)
|
||||
: LAst.annotation option -> Location.t = function
|
||||
| None -> source_only_location source_file (* no source line/column numbers *)
|
||||
| Some (Annotation i) ->
|
||||
begin match MetadataMap.find i metadata with
|
||||
| Components (TypOperand (_, Const (Cint line_num)) :: _) ->
|
||||
let open Location in
|
||||
{ line = line_num; col = -1; file = source_file; nLOC = !Config.nLOC }
|
||||
| Location loc ->
|
||||
let open Location in
|
||||
{ line = loc.line; col = loc.col; file = source_file; nLOC = !Config.nLOC }
|
||||
| _ -> raise (MalformedMetadata ("Instruction annotation refers to metadata node " ^
|
||||
"without line number as first component."))
|
||||
end
|
||||
|
||||
let procname_of_function_variable (func_var : LAst.variable) : Procname.t =
|
||||
Procname.from_string_c_fun (LAst.string_of_variable func_var)
|
||||
|
||||
(* Generate list of SIL instructions and list of local variables *)
|
||||
let rec trans_annotated_instructions
|
||||
source_file
|
||||
(cfg : Cfg.cfg) (procdesc : Cfg.Procdesc.t) (metadata : LAst.metadata_map)
|
||||
: LAst.annotated_instruction list -> Sil.instr list * (Mangled.t * Typ.t) list = function
|
||||
| [] -> ([], [])
|
||||
| (instr, anno) :: t ->
|
||||
let (sil_instrs, locals) = trans_annotated_instructions source_file cfg procdesc metadata t in
|
||||
let location = location_of_annotation_option source_file metadata anno in
|
||||
begin match instr with
|
||||
| Ret None -> (sil_instrs, locals)
|
||||
| Ret (Some (tp, exp)) ->
|
||||
let procname = Cfg.Procdesc.get_proc_name procdesc in
|
||||
let ret_var = Pvar.get_ret_pvar procname in
|
||||
let new_sil_instr =
|
||||
Sil.Store (Exp.Lvar ret_var, trans_typ tp, trans_operand exp, location) in
|
||||
(new_sil_instr :: sil_instrs, locals)
|
||||
| Load (var, tp, ptr) ->
|
||||
let new_sil_instr =
|
||||
Sil.Load (ident_of_variable var, trans_variable ptr, trans_typ tp, location) in
|
||||
(new_sil_instr :: sil_instrs, locals)
|
||||
| Store (op, tp, var) ->
|
||||
let new_sil_instr =
|
||||
Sil.Store (trans_variable var, trans_typ tp, trans_operand op, location) in
|
||||
(new_sil_instr :: sil_instrs, locals)
|
||||
| Alloc (var, tp, _num_elems) ->
|
||||
(* num_elems currently ignored *)
|
||||
begin match var with
|
||||
| Global (Name var_name) | Local (Name var_name) ->
|
||||
let new_local = (Mangled.from_string var_name, trans_typ (Tptr tp)) in
|
||||
(sil_instrs, new_local :: locals)
|
||||
| _ ->
|
||||
raise
|
||||
(ImproperTypeError
|
||||
"Not expecting alloca instruction to a numbered variable.")
|
||||
end
|
||||
| Call (ret_var, func_var, typed_args) ->
|
||||
let new_sil_instr = Sil.Call (
|
||||
(* TODO: translate type of ret_var *)
|
||||
Some (ident_of_variable ret_var, Tvoid),
|
||||
Exp.Const (Const.Cfun (procname_of_function_variable func_var)),
|
||||
IList.map (fun (tp, arg) -> (trans_operand arg, trans_typ tp)) typed_args,
|
||||
location, CallFlags.default) in
|
||||
(new_sil_instr :: sil_instrs, locals)
|
||||
| _ -> raise (Unimplemented "Need to translate instruction to SIL.")
|
||||
end
|
||||
|
||||
let callees_of_function_def : LAst.function_def -> Procname.t list = function
|
||||
FunctionDef (_, _, _, annotated_instrs) ->
|
||||
let callee_of_instruction : LAst.instruction -> Procname.t option = begin function
|
||||
| Call (_, func_var, _) -> Some (procname_of_function_variable func_var)
|
||||
| _ -> None
|
||||
end in
|
||||
IList.flatten_options (
|
||||
IList.map
|
||||
(fun annotated_instr -> callee_of_instruction (fst annotated_instr))
|
||||
annotated_instrs)
|
||||
|
||||
(* Update CFG and call graph with new function definition *)
|
||||
let trans_function_def source_file (cfg : Cfg.cfg) (cg: Cg.t) (metadata : LAst.metadata_map)
|
||||
(func_def : LAst.function_def) : unit =
|
||||
|
||||
(* each procedure has different scope: start names from id 0 *)
|
||||
Ident.NameGenerator.reset ();
|
||||
|
||||
match func_def with
|
||||
FunctionDef (func_name, ret_tp_opt, params, annotated_instrs) ->
|
||||
let proc_name = procname_of_function_variable func_name in
|
||||
let ret_type =
|
||||
match ret_tp_opt with
|
||||
| None -> Typ.Tvoid
|
||||
| Some ret_tp -> trans_typ ret_tp in
|
||||
let (proc_attrs : ProcAttributes.t) =
|
||||
{ (ProcAttributes.default proc_name Config.Clang) with
|
||||
ProcAttributes.formals =
|
||||
IList.map (fun (tp, name) -> (Mangled.from_string name, trans_typ tp)) params;
|
||||
is_defined = true; (* is defined and not just declared *)
|
||||
loc = source_only_location source_file;
|
||||
locals = []; (* TODO *)
|
||||
ret_type;
|
||||
} in
|
||||
let procdesc = Cfg.Procdesc.create cfg proc_attrs in
|
||||
let start_kind = Cfg.Node.Start_node procdesc in
|
||||
let start_node =
|
||||
Cfg.Node.create cfg (source_only_location source_file) start_kind [] procdesc in
|
||||
let exit_kind = Cfg.Node.Exit_node procdesc in
|
||||
let exit_node =
|
||||
Cfg.Node.create cfg (source_only_location source_file) exit_kind [] procdesc in
|
||||
let node_of_sil_instr cfg procdesc sil_instr =
|
||||
Cfg.Node.create cfg (Sil.instr_get_loc sil_instr) (Cfg.Node.Stmt_node "method_body")
|
||||
[sil_instr] procdesc in
|
||||
let rec link_nodes (start_node : Cfg.Node.t) : Cfg.Node.t list -> unit = function
|
||||
(* link all nodes in a chain for now *)
|
||||
| [] ->
|
||||
Cfg.Node.set_succs_exn cfg start_node [exit_node] [exit_node]
|
||||
| nd :: nds ->
|
||||
Cfg.Node.set_succs_exn cfg start_node [nd] [exit_node]; link_nodes nd nds in
|
||||
let (sil_instrs, locals) =
|
||||
trans_annotated_instructions source_file cfg procdesc metadata annotated_instrs in
|
||||
let nodes = IList.map (node_of_sil_instr cfg procdesc) sil_instrs in
|
||||
Cfg.Procdesc.set_start_node procdesc start_node;
|
||||
Cfg.Procdesc.set_exit_node procdesc exit_node;
|
||||
link_nodes start_node nodes;
|
||||
Cfg.Node.add_locals_ret_declaration start_node locals;
|
||||
Cg.add_defined_node cg proc_name;
|
||||
IList.iter (Cg.add_edge cg proc_name) (callees_of_function_def func_def)
|
||||
|
||||
let trans_program source_file : LAst.program -> Cfg.cfg * Cg.t * Tenv.t = function
|
||||
Program (func_defs, metadata) ->
|
||||
let cfg = Cfg.Node.create_cfg () in
|
||||
let cg = Cg.create (Some source_file) in
|
||||
let tenv = Tenv.create () in
|
||||
IList.iter (trans_function_def source_file cfg cg metadata) func_defs;
|
||||
(cfg, cg, tenv)
|
@ -1,187 +0,0 @@
|
||||
(*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
{
|
||||
open LParser
|
||||
|
||||
exception LexingError of string
|
||||
}
|
||||
|
||||
let space = [' ' '\t']
|
||||
let newline = '\n'
|
||||
let comment = ';' [^ '\n']*
|
||||
|
||||
let nonzero_digit = ['1'-'9']
|
||||
let digit = ['0'-'9']
|
||||
let pos_int = nonzero_digit digit*
|
||||
let nonneg_int = '0' | pos_int
|
||||
let intlit = '-'? digit+
|
||||
|
||||
let lower = ['a'-'z']
|
||||
let upper = ['A'-'Z']
|
||||
let id_special_char = ['-' '$' '.' '_']
|
||||
let id_char = lower | upper | id_special_char
|
||||
let id = id_char (id_char | digit)*
|
||||
|
||||
(* some top level constructs currently ignored *)
|
||||
let declaration = "declare " [^ '\n']*
|
||||
let attribute_group = "attributes " [^ '\n']*
|
||||
|
||||
let string_content = [^ '"']*
|
||||
|
||||
rule token = parse
|
||||
| space | comment { token lexbuf }
|
||||
| newline { token lexbuf }
|
||||
|
||||
(* keywords *)
|
||||
| "target" { TARGET }
|
||||
| "datalayout" { DATALAYOUT }
|
||||
| "triple" { TRIPLE }
|
||||
| "define" { DEFINE }
|
||||
|
||||
(* delimiters *)
|
||||
| ',' { COMMA }
|
||||
| '(' { LPAREN }
|
||||
| ')' { RPAREN }
|
||||
| '{' { LBRACE }
|
||||
| '}' { RBRACE }
|
||||
| '<' { LANGLE }
|
||||
| '>' { RANGLE }
|
||||
| '[' { LSQBRACK }
|
||||
| ']' { RSQBRACK }
|
||||
| ':' { COLON }
|
||||
(* symbols *)
|
||||
| '=' { EQUALS }
|
||||
| '*' { STAR }
|
||||
| ['x' 'X'] { X }
|
||||
|
||||
(* TYPES *)
|
||||
| "void" { VOID }
|
||||
| 'i' (pos_int as width) { INT (int_of_string width) }
|
||||
| "half" { HALF }
|
||||
| "float" { FLOAT }
|
||||
| "double" { DOUBLE }
|
||||
| "fp128" { FP128 }
|
||||
| "x86_fp80" { X86_FP80 }
|
||||
| "ppc_fp128" { PPC_FP128 }
|
||||
(*| "x86_mmx" { X86_MMX }*)
|
||||
| "label" { LABEL }
|
||||
| "metadata" { METADATA }
|
||||
|
||||
| '"' (string_content as str) '"' { CONSTANT_STRING str }
|
||||
(* CONSTANTS *)
|
||||
| "true" { CONSTANT_INT 1 }
|
||||
| "false" { CONSTANT_INT 0 }
|
||||
| intlit as i { CONSTANT_INT (int_of_string i) }
|
||||
(* floating point constants *)
|
||||
| "null" { NULL }
|
||||
|
||||
(* INSTRUCTIONS *)
|
||||
(* terminator instructions *)
|
||||
| "ret" { RET }
|
||||
| "br" { BR }
|
||||
(*| "switch" { SWITCH }
|
||||
| "indirectbr" { INDIRECTBR }
|
||||
| "invoke" { INVOKE }
|
||||
| "resume" { RESUME }
|
||||
| "unreachable" { UNREACHABLE }*)
|
||||
(* binary operations *)
|
||||
| "add" { ADD }
|
||||
| "fadd" { FADD }
|
||||
| "sub" { SUB }
|
||||
| "fsub" { FSUB }
|
||||
| "mul" { MUL }
|
||||
| "fmul" { FMUL }
|
||||
| "udiv" { UDIV }
|
||||
| "sdiv" { SDIV }
|
||||
| "fdiv" { FDIV }
|
||||
| "urem" { UREM }
|
||||
| "srem" { SREM }
|
||||
| "frem" { FREM }
|
||||
(* arithmetic options *)
|
||||
| "nuw" { NUW }
|
||||
| "nsw" { NSW }
|
||||
| "exact" { EXACT }
|
||||
(* floating point options *)
|
||||
| "nnan" { NNAN }
|
||||
| "ninf" { NINF }
|
||||
| "nsz" { NSZ }
|
||||
| "arcp" { ARCP }
|
||||
| "fast" { FAST }
|
||||
(* bitwise binary operations *)
|
||||
| "shl" { SHL }
|
||||
| "lshr" { LSHR }
|
||||
| "ashr" { ASHR }
|
||||
| "and" { AND }
|
||||
| "or" { OR }
|
||||
| "xor" { XOR }
|
||||
(* vector operations *)
|
||||
| "extractelement" { EXTRACTELEMENT }
|
||||
| "insertelement" { INSERTELEMENT }
|
||||
(*| "shufflevector" { SHUFFLEVECTOR }*)
|
||||
(* aggregate operations *)
|
||||
(*| "extractvalue" { EXTRACTVALUE }*)
|
||||
(*| "insertvalue" { INSERTVALUE }*)
|
||||
(* memory access and addressing operations *)
|
||||
| "align" { ALIGN }
|
||||
| "alloca" { ALLOCA }
|
||||
| "load" { LOAD }
|
||||
| "store" { STORE }
|
||||
(*| "fence" { FENCE }*)
|
||||
(*| "cmpxchg" { CMPXCHG }*)
|
||||
(*| "atomicrmw" { ATOMICRMW }*)
|
||||
(*| "getelementptr" { GETELEMENTPTR }*)
|
||||
(* conversion operations *)
|
||||
(*| "trunc" { TRUNC }*) (* e.g. trunc ... to ... *)
|
||||
(*| "zext" { ZEXT }*)
|
||||
(*| "sext" { SEXT }*)
|
||||
(*| "fptrunc" { FPTRUNC }*)
|
||||
(*| "fpext" { FPEXT }*)
|
||||
(*| "fptoui" { FPTOUI }*)
|
||||
(*| "fptosi" { FPTOSI }*)
|
||||
(*| "uitofp" { UITOFP }*)
|
||||
(*| "sitofp" { SITOFP }*)
|
||||
(*| "ptrtoint" { PTRTOINT }*)
|
||||
(*| "inttoptr" { INTTOPTR }*)
|
||||
(*| "bitcast" { BITCAST }*)
|
||||
(*| "addrspacecast" { ADDRSPACECAST }*)
|
||||
(*| "to" { TO }*) (* all conversion operations include this keyword *)
|
||||
(* other operations *)
|
||||
(*| "icmp" { ICMP }*)
|
||||
(*| "fcmp" { FCMP }*)
|
||||
(*| "phi" { PHI }*)
|
||||
(*| "select" { SELECT }*)
|
||||
| "call" { CALL }
|
||||
(*| "va_arg" { VA_ARG }*)
|
||||
(*| "landingpad" { LANDINGPAD }*)
|
||||
|
||||
|
||||
(* IDENTIFIERS *)
|
||||
| "@llvm.dbg.declare" { DBG_DECLARE }
|
||||
| '@' (id as str) { NAMED_GLOBAL str }
|
||||
| '%' (id as str) { NAMED_LOCAL str }
|
||||
| '@' (nonneg_int as i) { NUMBERED_GLOBAL (int_of_string i) }
|
||||
| '%' (nonneg_int as i) { NUMBERED_LOCAL (int_of_string i) }
|
||||
| id as str { IDENT str }
|
||||
|
||||
(* METADATA *)
|
||||
| "!dbg" { DEBUG_ANNOTATION }
|
||||
| "!MDLocation" { METADATA_LOCATION }
|
||||
| '!' (id as str) { NAMED_METADATA str }
|
||||
| '!' (nonneg_int as i) { NUMBERED_METADATA (int_of_string i) }
|
||||
| '!' '"' ([^ '"']* as str) '"' { METADATA_STRING str }
|
||||
| "!{" { METADATA_NODE_BEGIN }
|
||||
|
||||
| declaration { token lexbuf }
|
||||
|
||||
(* attribute groups *)
|
||||
| '#' (nonneg_int as i) { ATTRIBUTE_GROUP (int_of_string i) }
|
||||
| attribute_group { token lexbuf }
|
||||
|
||||
| eof { EOF }
|
@ -1,335 +0,0 @@
|
||||
(*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
%{
|
||||
open LAst
|
||||
%}
|
||||
|
||||
(* keywords *)
|
||||
%token TARGET
|
||||
%token DATALAYOUT
|
||||
%token TRIPLE
|
||||
%token DEFINE
|
||||
|
||||
(* delimiters *)
|
||||
%token COMMA
|
||||
%token LPAREN
|
||||
%token RPAREN
|
||||
%token LBRACE
|
||||
%token RBRACE
|
||||
%token LANGLE
|
||||
%token RANGLE
|
||||
%token LSQBRACK
|
||||
%token RSQBRACK
|
||||
%token COLON
|
||||
(* symbols *)
|
||||
%token EQUALS
|
||||
%token STAR
|
||||
%token X
|
||||
|
||||
(* TYPES *)
|
||||
%token VOID
|
||||
%token <int> INT
|
||||
%token HALF
|
||||
%token FLOAT
|
||||
%token DOUBLE
|
||||
%token FP128
|
||||
%token X86_FP80
|
||||
%token PPC_FP128
|
||||
(*%token X86_MMX*)
|
||||
%token LABEL
|
||||
%token METADATA
|
||||
|
||||
%token <string> CONSTANT_STRING
|
||||
(* CONSTANTS *)
|
||||
%token <int> CONSTANT_INT
|
||||
%token NULL
|
||||
|
||||
(* INSTRUCTIONS *)
|
||||
(* terminator instructions *)
|
||||
%token RET
|
||||
%token BR
|
||||
(*%token SWITCH*)
|
||||
(*%token INDIRECTBR*)
|
||||
(*%token INVOKE*)
|
||||
(*%token RESUME*)
|
||||
(*%token UNREACHABLE*)
|
||||
(* binary operations *)
|
||||
%token ADD
|
||||
%token FADD
|
||||
%token SUB
|
||||
%token FSUB
|
||||
%token MUL
|
||||
%token FMUL
|
||||
%token UDIV
|
||||
%token SDIV
|
||||
%token FDIV
|
||||
%token UREM
|
||||
%token SREM
|
||||
%token FREM
|
||||
(* arithmetic options *)
|
||||
%token NUW
|
||||
%token NSW
|
||||
%token EXACT
|
||||
(* floating point options *)
|
||||
%token NNAN
|
||||
%token NINF
|
||||
%token NSZ
|
||||
%token ARCP
|
||||
%token FAST
|
||||
(* bitwise binary operations *)
|
||||
%token SHL
|
||||
%token LSHR
|
||||
%token ASHR
|
||||
%token AND
|
||||
%token OR
|
||||
%token XOR
|
||||
(* vector operations *)
|
||||
%token EXTRACTELEMENT
|
||||
%token INSERTELEMENT
|
||||
(*%token SHUFFLEVECTOR*)
|
||||
(* aggregate operations *)
|
||||
(*%token EXTRACTVALUE*)
|
||||
(*%token INSERTVALUE*)
|
||||
(* memory access and addressing operations *)
|
||||
%token ALIGN (* argument for below operations *)
|
||||
%token ALLOCA
|
||||
%token LOAD
|
||||
%token STORE
|
||||
(*%token FENCE*)
|
||||
(*%token CMPXCHG*)
|
||||
(*%token ATOMICRMW*)
|
||||
(*%token GETELEMENTPTR*)
|
||||
(* conversion operations *)
|
||||
(*%token TRUNC*)
|
||||
(*%token ZEXT*)
|
||||
(*%token SEXT*)
|
||||
(*%token FPTRUNC*)
|
||||
(*%token FPEXT*)
|
||||
(*%token FPTOUI*)
|
||||
(*%token FPTOSI*)
|
||||
(*%token UITOFP*)
|
||||
(*%token SITOFP*)
|
||||
(*%token PTRTOINT*)
|
||||
(*%token INTTOPTR*)
|
||||
(*%token BITCAST*)
|
||||
(*%token ADDRSPACECAST*)
|
||||
(*%token TO*)
|
||||
(* other operations *)
|
||||
(*%token ICMP*)
|
||||
(*%token FCMP*)
|
||||
(*%token PHI*)
|
||||
(*%token SELECT*)
|
||||
%token CALL
|
||||
(*%token VA_ARG*)
|
||||
(*%token LANDINGPAD*)
|
||||
|
||||
%token DBG_DECLARE
|
||||
%token <string> NAMED_GLOBAL
|
||||
%token <string> NAMED_LOCAL
|
||||
%token <int> NUMBERED_GLOBAL
|
||||
%token <int> NUMBERED_LOCAL
|
||||
%token <string> IDENT
|
||||
|
||||
%token DEBUG_ANNOTATION
|
||||
%token <string> NAMED_METADATA
|
||||
%token <int> NUMBERED_METADATA
|
||||
%token <string> METADATA_STRING
|
||||
%token METADATA_NODE_BEGIN
|
||||
%token METADATA_LOCATION
|
||||
|
||||
%token <int> ATTRIBUTE_GROUP
|
||||
|
||||
%token EOF
|
||||
|
||||
%start program
|
||||
%type <LAst.program> program
|
||||
%type <LAst.function_def> function_def
|
||||
%type <LAst.typ option> ret_typ
|
||||
%type <LAst.typ> typ
|
||||
|
||||
%%
|
||||
|
||||
program:
|
||||
| targets func_defs = function_def* opt_mappings = metadata_def* EOF {
|
||||
let mappings = IList.flatten_options opt_mappings in
|
||||
let add_mapping map (metadata_id, aggregate) = MetadataMap.add metadata_id aggregate map in
|
||||
let metadata_map = IList.fold_left add_mapping MetadataMap.empty mappings in
|
||||
Program (func_defs, metadata_map) }
|
||||
|
||||
targets:
|
||||
| { (None, None) }
|
||||
| dl = datalayout { (Some dl, None) }
|
||||
| tt = target_triple { (None, Some tt) }
|
||||
| dl = datalayout tt = target_triple { (Some dl, Some tt) }
|
||||
| tt = target_triple dl = datalayout { (Some dl, Some tt) }
|
||||
|
||||
datalayout:
|
||||
| TARGET DATALAYOUT EQUALS str = CONSTANT_STRING { str }
|
||||
|
||||
target_triple:
|
||||
| TARGET TRIPLE EQUALS str = CONSTANT_STRING { str }
|
||||
|
||||
metadata_def:
|
||||
| NAMED_METADATA EQUALS numbered_metadata_node { None }
|
||||
| metadata_id = NUMBERED_METADATA EQUALS aggregate = metadata_aggregate { Some
|
||||
(metadata_id, aggregate) }
|
||||
|
||||
numbered_metadata_node:
|
||||
| METADATA_NODE_BEGIN metadata_ids = separated_list(COMMA, NUMBERED_METADATA) RBRACE { metadata_ids }
|
||||
|
||||
metadata_aggregate:
|
||||
| components = metadata_node { Components components }
|
||||
| location = metadata_location { Location location }
|
||||
|
||||
metadata_location:
|
||||
| METADATA_LOCATION LPAREN IDENT COLON line_num = CONSTANT_INT COMMA
|
||||
IDENT COLON col_num = CONSTANT_INT COMMA
|
||||
IDENT COLON i = NUMBERED_METADATA RPAREN
|
||||
{ { line = line_num; col = col_num; scope = MetadataVar i} }
|
||||
|
||||
metadata_node:
|
||||
| METADATA? METADATA_NODE_BEGIN components = separated_list(COMMA, metadata_component) RBRACE { components }
|
||||
|
||||
metadata_component:
|
||||
| METADATA? tp = typ? op = operand { TypOperand (tp, op) }
|
||||
| METADATA? value = metadata_value { MetadataVal value }
|
||||
|
||||
metadata_value:
|
||||
| i = NUMBERED_METADATA { MetadataVar i }
|
||||
| str = METADATA_STRING { MetadataString str }
|
||||
| components = metadata_node { MetadataNode components }
|
||||
|
||||
function_def:
|
||||
| DEFINE ret_tp = ret_typ name = variable LPAREN
|
||||
params = separated_list(COMMA, pair(first_class_typ, IDENT)) RPAREN attribute_group*
|
||||
annotated_instrs = block { FunctionDef (name, ret_tp, params, annotated_instrs) }
|
||||
|
||||
attribute_group:
|
||||
| i = ATTRIBUTE_GROUP { i }
|
||||
|
||||
ret_typ:
|
||||
| VOID { None }
|
||||
| tp = first_class_typ { Some tp }
|
||||
|
||||
typ:
|
||||
| tp = func_typ { tp }
|
||||
| tp = first_class_typ { tp }
|
||||
|
||||
func_typ:
|
||||
| ret_tp = ret_typ LPAREN param_tps = separated_list(COMMA, first_class_typ) RPAREN { Tfunc (ret_tp, param_tps) }
|
||||
|
||||
first_class_typ:
|
||||
| tp = element_typ { tp }
|
||||
(*| X86_MMX { () }*)
|
||||
| tp = vector_typ { tp }
|
||||
| LSQBRACK sz = CONSTANT_INT X tp = element_typ RSQBRACK { Tarray (sz, tp) } (* array type *)
|
||||
| LABEL { Tlabel }
|
||||
| METADATA { Tmetadata }
|
||||
(* TODO structs *)
|
||||
|
||||
vector_typ:
|
||||
| LANGLE sz = CONSTANT_INT X tp = element_typ RANGLE { Tvector (sz, tp) }
|
||||
|
||||
element_typ:
|
||||
| width = INT { Tint width }
|
||||
| floating_typ { Tfloat }
|
||||
| tp = ptr_typ { Tptr tp }
|
||||
|
||||
floating_typ:
|
||||
| HALF { () }
|
||||
| FLOAT { () }
|
||||
| DOUBLE { () }
|
||||
| FP128 { () }
|
||||
| X86_FP80 { () }
|
||||
| PPC_FP128 { () }
|
||||
|
||||
ptr_typ:
|
||||
| tp = typ STAR { tp }
|
||||
|
||||
block:
|
||||
| LBRACE annotated_instrs = annotated_instruction* RBRACE { IList.flatten_options annotated_instrs }
|
||||
|
||||
annotated_instruction:
|
||||
| instr = real_instruction anno = annotation? { Some (instr, anno) }
|
||||
| debug_instruction annotation? { None }
|
||||
|
||||
annotation:
|
||||
| COMMA DEBUG_ANNOTATION i = NUMBERED_METADATA { Annotation i }
|
||||
|
||||
real_instruction:
|
||||
(* terminator instructions *)
|
||||
| RET tp = typ op = operand { Ret (Some (tp, op)) }
|
||||
| RET VOID { Ret None }
|
||||
| BR LABEL lbl = variable { UncondBranch lbl }
|
||||
| BR _ = INT op = operand COMMA LABEL lbl1 = variable COMMA LABEL lbl2 = variable
|
||||
{ CondBranch (op, lbl1, lbl2) }
|
||||
(* Memory access operations *)
|
||||
| var = variable EQUALS ALLOCA tp = typ align? { Alloc (var, tp, 1) }
|
||||
| var = variable EQUALS LOAD tp = ptr_typ ptr = variable align? { Load (var, tp, ptr) }
|
||||
| STORE val_tp = typ value = operand COMMA _ptr_tp = ptr_typ var = variable align?
|
||||
{ Store (value, val_tp, var) }
|
||||
(* don't yet know why val_tp and _ptr_tp would be different *)
|
||||
(* Function call *)
|
||||
| ret_var = variable EQUALS CALL ret_typ func_var = variable LPAREN
|
||||
args = separated_list(COMMA, pair(typ, operand)) RPAREN { Call (ret_var, func_var, args) }
|
||||
| variable EQUALS binop { Binop }
|
||||
|
||||
debug_instruction:
|
||||
| CALL VOID DBG_DECLARE LPAREN separated_list(COMMA, metadata_component) RPAREN { () }
|
||||
|
||||
align:
|
||||
| COMMA ALIGN width = CONSTANT_INT { width }
|
||||
|
||||
binop:
|
||||
| ADD arith_options binop_args { () }
|
||||
| FADD fast_math_flags binop_args { () }
|
||||
| SUB arith_options binop_args { () }
|
||||
| FSUB fast_math_flags binop_args { () }
|
||||
| MUL binop_args { () }
|
||||
| FMUL fast_math_flags binop_args { () }
|
||||
| UDIV EXACT? binop_args { () }
|
||||
| SDIV EXACT? binop_args { () }
|
||||
| FDIV fast_math_flags binop_args { () }
|
||||
| UREM binop_args { () }
|
||||
| SREM binop_args { () }
|
||||
| FREM fast_math_flags binop_args { () }
|
||||
(* bitwise *)
|
||||
| SHL arith_options binop_args { () }
|
||||
| LSHR EXACT? binop_args { () }
|
||||
| ASHR EXACT? binop_args { () }
|
||||
| AND binop_args { () }
|
||||
| OR binop_args { () }
|
||||
| XOR binop_args { () }
|
||||
(* vector *)
|
||||
| EXTRACTELEMENT vector_typ operand COMMA typ operand { () }
|
||||
| INSERTELEMENT vector_typ operand COMMA typ operand COMMA typ operand { () }
|
||||
|
||||
arith_options:
|
||||
| NUW? NSW? { () }
|
||||
|
||||
fast_math_flags:
|
||||
| NNAN? NINF? NSZ? ARCP? FAST? { () }
|
||||
|
||||
binop_args:
|
||||
| typ operand COMMA operand { () }
|
||||
|
||||
operand:
|
||||
| var = variable { Var var }
|
||||
| const = constant { Const const }
|
||||
|
||||
variable:
|
||||
| name = NAMED_GLOBAL { Global (Name name) }
|
||||
| name = NAMED_LOCAL { Local (Name name) }
|
||||
| num = NUMBERED_GLOBAL { Global (Number num) }
|
||||
| num = NUMBERED_LOCAL { Local (Number num) }
|
||||
|
||||
constant:
|
||||
| i = CONSTANT_INT { Cint i }
|
||||
| NULL { Cnull }
|
@ -1,12 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; Allocate stack variable using alloca instruction
|
||||
define i32 @main() {
|
||||
%a = alloca i32
|
||||
ret i32 0
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
int* always_null(void) { return 0; }
|
||||
|
||||
void foo(void) {
|
||||
int* p = always_null();
|
||||
*p = 42;
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; ModuleID = 'interproc.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 i32* @always_null() #0 {
|
||||
ret i32* null, !dbg !16
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind ssp uwtable
|
||||
define void @foo() #0 {
|
||||
%p = alloca i32*, align 8
|
||||
call void @llvm.dbg.declare(metadata !{i32** %p}, metadata !17), !dbg !18
|
||||
%1 = call i32* @always_null(), !dbg !19
|
||||
store i32* %1, i32** %p, align 8, !dbg !19
|
||||
%2 = load i32** %p, align 8, !dbg !20
|
||||
store i32 42, i32* %2, align 4, !dbg !20
|
||||
ret void, !dbg !21
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare void @llvm.dbg.declare(metadata, metadata) #1
|
||||
|
||||
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" }
|
||||
attributes #1 = { nounwind readnone }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!13, !14}
|
||||
!llvm.ident = !{!15}
|
||||
|
||||
!0 = metadata !{i32 786449, metadata !1, i32 12, metadata !"Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/Users/rohanjr/infer/infer/tests/codetoanalyze/llvm/interproc.c] [DW_LANG_C99]
|
||||
!1 = metadata !{metadata !"interproc.c", metadata !"/Users/rohanjr/infer/infer/tests/codetoanalyze/llvm"}
|
||||
!2 = metadata !{}
|
||||
!3 = metadata !{metadata !4, metadata !10}
|
||||
!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"always_null", metadata !"always_null", metadata !"", i32 10, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32* ()* @always_null, null, null, metadata !2, i32 10} ; [ DW_TAG_subprogram ] [line 10] [def] [always_null]
|
||||
!5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/Users/rohanjr/infer/infer/tests/codetoanalyze/llvm/interproc.c]
|
||||
!6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
|
||||
!7 = metadata !{metadata !8}
|
||||
!8 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !9} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from int]
|
||||
!9 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
|
||||
!10 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"foo", metadata !"foo", metadata !"", i32 14, metadata !11, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void ()* @foo, null, null, metadata !2, i32 14} ; [ DW_TAG_subprogram ] [line 14] [def] [foo]
|
||||
!11 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !12, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
|
||||
!12 = metadata !{null}
|
||||
!13 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
|
||||
!14 = metadata !{i32 2, metadata !"Debug Info Version", i32 602053001}
|
||||
!15 = metadata !{metadata !"Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)"}
|
||||
!16 = metadata !{i32 11, i32 4, metadata !4, null} ; [ DW_TAG_lexical_block ] [/]
|
||||
!17 = metadata !{i32 786688, metadata !10, metadata !"p", metadata !5, i32 15, metadata !8, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [p] [line 15]
|
||||
!18 = metadata !{i32 15, i32 9, metadata !10, null}
|
||||
!19 = metadata !{i32 15, i32 13, metadata !10, null}
|
||||
!20 = metadata !{i32 16, i32 4, metadata !10, null}
|
||||
!21 = metadata !{i32 17, i32 1, metadata !10, null}
|
@ -1,12 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; Definition of main function
|
||||
define i32 @main() {
|
||||
%a = load i32* %b
|
||||
ret i32 0
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
void foo(void) {
|
||||
int* p = 0;
|
||||
*p = 42;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; 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
|
||||
call void @llvm.dbg.declare(metadata i32** %p, metadata !12, metadata !15), !dbg !16
|
||||
store i32* null, i32** %p, align 8, !dbg !16
|
||||
%1 = load i32** %p, align 8, !dbg !17
|
||||
store i32 42, i32* %1, align 4, !dbg !18
|
||||
ret void, !dbg !19
|
||||
}
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
|
||||
|
||||
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" }
|
||||
attributes #1 = { nounwind readnone }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!8, !9, !10}
|
||||
!llvm.ident = !{!11}
|
||||
|
||||
!0 = !{!"0x11\0012\00clang version 3.6.1 (tags/RELEASE_361/final)\000\00\000\00\001", !1, !2, !2, !3, !2, !2} ; [ DW_TAG_compile_unit ] [/Users/rohanjr/infer/infer/tests/codetoanalyze/llvm/null_deref.c] [DW_LANG_C99]
|
||||
!1 = !{!"null_deref.c", !"/Users/rohanjr/infer/infer/tests/codetoanalyze/llvm"}
|
||||
!2 = !{}
|
||||
!3 = !{!4}
|
||||
!4 = !{!"0x2e\00foo\00foo\00\0010\000\001\000\000\00256\000\0010", !1, !5, !6, null, void ()* @foo, null, null, !2} ; [ DW_TAG_subprogram ] [line 10] [def] [foo]
|
||||
!5 = !{!"0x29", !1} ; [ DW_TAG_file_type ] [/Users/rohanjr/infer/infer/tests/codetoanalyze/llvm/null_deref.c]
|
||||
!6 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !7, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
|
||||
!7 = !{null}
|
||||
!8 = !{i32 2, !"Dwarf Version", i32 2}
|
||||
!9 = !{i32 2, !"Debug Info Version", i32 2}
|
||||
!10 = !{i32 1, !"PIC Level", i32 2}
|
||||
!11 = !{!"clang version 3.6.1 (tags/RELEASE_361/final)"}
|
||||
!12 = !{!"0x100\00p\0011\000", !4, !5, !13} ; [ DW_TAG_auto_variable ] [p] [line 11]
|
||||
!13 = !{!"0xf\00\000\0064\0064\000\000", null, null, !14} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from int]
|
||||
!14 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
|
||||
!15 = !{!"0x102"} ; [ DW_TAG_expression ]
|
||||
!16 = !MDLocation(line: 11, column: 9, scope: !4)
|
||||
!17 = !MDLocation(line: 12, column: 5, scope: !4)
|
||||
!18 = !MDLocation(line: 12, column: 4, scope: !4)
|
||||
!19 = !MDLocation(line: 13, column: 1, scope: !4)
|
@ -1,11 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; Definition of main function
|
||||
define i32 @main() {
|
||||
ret i32 0
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; Definition of main function
|
||||
define i32 @main() {
|
||||
ret i32 %0
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; Definition of main function
|
||||
define void @main() {
|
||||
ret void
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
; Copyright (c) 2015 - present Facebook, Inc.
|
||||
; All rights reserved.
|
||||
;
|
||||
; This source code is licensed under the BSD style license found in the
|
||||
; LICENSE file in the root directory of this source tree. An additional grant
|
||||
; of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
; Function with store instruction
|
||||
define i32 @main() {
|
||||
store i32 0, i32* %i
|
||||
ret i32 0
|
||||
}
|
Loading…
Reference in new issue