Fixing the treatment of annotations in the clang frontend

Reviewed By: jvillard

Differential Revision: D3488426

fbshipit-source-id: fe3cb1b
master
Dulma Churchill 9 years ago committed by Facebook Github Bot 8
parent c7d6d904f7
commit c06795e631

@ -348,11 +348,11 @@ let sil_method_annotation_of_args args : Typ.method_annotation =
let mk_annot param_name annot_name = let mk_annot param_name annot_name =
let annot = { Typ.class_name = annot_name; Typ.parameters = [param_name]; } in let annot = { Typ.class_name = annot_name; Typ.parameters = [param_name]; } in
annot, default_visibility in annot, default_visibility in
let arg_to_sil_annot acc (arg_name, type_ptr) = let arg_to_sil_annot (arg_name, type_ptr) acc =
if CFrontend_utils.Ast_utils.is_type_nullable type_ptr then if CFrontend_utils.Ast_utils.is_type_nullable type_ptr then
[mk_annot arg_name Annotations.nullable] :: acc [mk_annot arg_name Annotations.nullable] :: acc
else acc in else Typ.item_annotation_empty::acc in
let param_annots = IList.fold_left arg_to_sil_annot [] args in let param_annots = IList.fold_right arg_to_sil_annot args [] in
(* TODO: parse annotations on return value *) (* TODO: parse annotations on return value *)
let retval_annot = [] in let retval_annot = [] in
retval_annot, param_annots retval_annot, param_annots

@ -38,6 +38,20 @@ A* derefNullableParamOk(A* __nullable param) {
return param; return param;
} }
int parameter_nullable_ok(NSString* body,
__nullable NSString* linkTapAction,
A* options) {
return options->fld;
}
int parameter_nullable_bug(__nullable A* options,
NSAttributedString* body,
NSString* linkTapAction)
{
return options->fld;
}
int readNullableParamPropertyOk(B* __nullable param) { return param.prop; } int readNullableParamPropertyOk(B* __nullable param) { return param.prop; }
void writeNullableParamPropertyOk(B* __nullable param) { param.prop = 7; } void writeNullableParamPropertyOk(B* __nullable param) { param.prop = 7; }

@ -49,8 +49,9 @@ public class NullableTest {
public void nullDereferenceTest() throws InterruptedException, IOException, InferException { public void nullDereferenceTest() throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferC(inferCmdNPD); InferResults inferResults = InferRunner.runInferC(inferCmdNPD);
String[] procedures = { String[] procedures = {
"derefNullableParamDirect", "derefNullableParamDirect",
"derefNullableParamIndirect" "derefNullableParamIndirect",
"parameter_nullable_bug"
}; };
assertThat( assertThat(
"Results should contain null pointer dereference error", "Results should contain null pointer dereference error",

Loading…
Cancel
Save