[clang] split StringLiterals into chunks

Summary:
This avoids exhausting the biniou buffer.

update-submodule: facebook-clang-plugins

Reviewed By: mbouaziz

Differential Revision: D5977221

fbshipit-source-id: c29d32a
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent e5ee17e8aa
commit 810d756f79

@ -1 +1 @@
Subproject commit 18ea5ae4205367ba3411210cb644ac983323818a
Subproject commit 6fe0516240c68e8a8aa123996ba54c6f9247f64a

@ -13,15 +13,13 @@ module L = Logging
(** enable debug mode (to get more data saved to disk for future inspections) *)
let debug_mode = Config.debug_mode || Config.frontend_stats
let buffer_len = 262143
(* This function reads the json file in fname, validates it, and encoded in the AST data structure
(** This function reads the json file in fname, validates it, and encodes in the AST data structure
defined in Clang_ast_t. *)
let validate_decl_from_file fname =
Ag_util.Biniou.from_file ~len:buffer_len Clang_ast_b.read_decl fname
Ag_util.Biniou.from_file ~len:CFrontend_config.biniou_buffer_size Clang_ast_b.read_decl fname
let validate_decl_from_channel chan =
Ag_util.Biniou.from_channel ~len:buffer_len Clang_ast_b.read_decl chan
Ag_util.Biniou.from_channel ~len:CFrontend_config.biniou_buffer_size Clang_ast_b.read_decl chan
let register_perf_stats_report source_file =
let stats_dir = Filename.concat Config.results_dir Config.frontend_stats_dir_name in
@ -150,15 +148,14 @@ let cc1_capture clang_cmd =
then (
L.(debug Capture Quiet) "@\n Skip compilation and analysis of source file %s@\n@\n" source_path ;
() )
else (
( match Config.clang_biniou_file with
else
match Config.clang_biniou_file with
| Some fname
-> run_and_validate_clang_frontend (`File fname)
| None
-> run_plugin_and_frontend source_path
(fun chan_in -> run_and_validate_clang_frontend (`Pipe chan_in))
clang_cmd ) ;
() )
clang_cmd
let capture clang_cmd =
if ClangCommand.can_attach_ast_exporter clang_cmd then

@ -147,6 +147,7 @@ let command_to_run cmd =
let with_exec exec args = {args with exec}
let with_plugin_args args =
let plugin_arg_flag = "-plugin-arg-" ^ plugin_name in
let args_before_rev =
[]
|> (* -cc1 has to be the first argument or clang will think it runs in driver mode *)
@ -162,10 +163,12 @@ let with_plugin_args args =
xcodebuild plus all the sub-steps happy. *)
(if has_flag args "-fmodules" then "-plugin" else "-add-plugin")
; plugin_name
; ("-plugin-arg-" ^ plugin_name)
; plugin_arg_flag
; "-"
; ("-plugin-arg-" ^ plugin_name)
; "PREPEND_CURRENT_DIR=1" ]
; plugin_arg_flag
; "PREPEND_CURRENT_DIR=1"
; plugin_arg_flag
; ("MAX_STRING_SIZE=" ^ string_of_int CFrontend_config.biniou_buffer_size) ]
in
(* add -O0 option to avoid compiler obfuscation of AST *)
let args_after_rev =

@ -40,6 +40,10 @@ let atomic_att = "<\"Atomic\">"
let autorelease = "autorelease"
let biniou_buffer_size =
(* the C++ standard suggests that implementation should support string literals up to this length *)
65535
let block = "block"
let builtin_expect = "__builtin_expect"

@ -43,6 +43,8 @@ val atomic_att : string
val autorelease : string
val biniou_buffer_size : int
val block : string
val builtin_expect : string

@ -752,7 +752,7 @@ let has_value an al_exp =
| Stmt IntegerLiteral (_, _, _, integer_literal_info)
-> let value = integer_literal_info.Clang_ast_t.ili_value in
ALVar.compare_str_with_alexp value al_exp
| Stmt StringLiteral (_, _, _, s)
-> ALVar.compare_str_with_alexp s al_exp
| Stmt StringLiteral (_, _, _, l)
-> ALVar.compare_str_with_alexp (String.concat ~sep:"" l) al_exp
| _
-> false

@ -3132,8 +3132,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
-> cast_exprs_trans trans_state stmt_info stmt_list expr_info cast_kind
| IntegerLiteral (_, _, expr_info, integer_literal_info)
-> integerLiteral_trans trans_state expr_info integer_literal_info
| StringLiteral (_, _, expr_info, str)
-> stringLiteral_trans trans_state expr_info str
| StringLiteral (_, _, expr_info, str_list)
-> stringLiteral_trans trans_state expr_info (String.concat ~sep:"" str_list)
| GNUNullExpr (_, _, expr_info)
-> gNUNullExpr_trans trans_state expr_info
| CXXNullPtrLiteralExpr (_, _, expr_info)

@ -69,8 +69,8 @@ let rec ast_node_name an =
match decl_ref.dr_name with Some name -> name.ni_name | None -> ""
in
ast_node_name (Stmt stmt) ^ "." ^ property_str
| Stmt StringLiteral (_, _, _, s)
-> s
| Stmt StringLiteral (_, _, _, l)
-> String.concat ~sep:"" l
| Stmt ObjCStringLiteral (_, [stmt], _)
-> "@" ^ ast_node_name (Stmt stmt)
| Stmt ObjCBoxedExpr (_, [stmt], _, objc_boxed_expr_info)

Loading…
Cancel
Save