From de9d8f45ff40d3d197da2c46536d52007f6061a5 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 31 Aug 2017 11:25:45 -0700 Subject: [PATCH] [clang] partial translation of vector instructions Reviewed By: jvillard Differential Revision: D5701932 fbshipit-source-id: 8bdef6d --- infer/src/clang/cFrontend_decl.ml | 4 ++++ infer/src/clang/cTrans.ml | 13 +++++++++---- infer/src/clang/cTrans_utils.ml | 2 ++ infer/src/clang/cTrans_utils.mli | 2 ++ .../cpp/frontend/vectors/shuffle_vector.cpp | 12 ++++++++++++ .../cpp/frontend/vectors/shuffle_vector.cpp.dot | 14 ++++++++++++++ 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp.dot diff --git a/infer/src/clang/cFrontend_decl.ml b/infer/src/clang/cFrontend_decl.ml index 6a6551c6c..54a1c9333 100644 --- a/infer/src/clang/cFrontend_decl.ml +++ b/infer/src/clang/cFrontend_decl.ml @@ -57,6 +57,10 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron | CTrans_utils.TemplatedCodeException _ -> L.internal_error "Fatal error: frontend doesn't support translation of templated code@\n" ; handle_translation_failure () + | CTrans_utils.UnsupportedStatementException stmt when Config.keep_going + -> L.internal_error "Unimplemented: translation for statement %s" + (Clang_ast_proj.get_stmt_kind_string stmt) ; + handle_translation_failure () | Assert_failure (file, line, column) when Config.keep_going -> L.internal_error "Fatal error: exception Assert_failure(%s, %d, %d)@\n%!" file line column ; handle_translation_failure () diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index f94bfb6fd..7a1fa50e7 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2903,6 +2903,9 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let typ = CType_decl.get_type_from_expr_info expr_info tenv in {empty_res_trans with exps= [(CTrans_utils.undefined_expression (), typ)]} + (* no-op translated for unsupported instructions that will at least translate subexpressions *) + and skip_unimplemented trans_state stmts = instructions trans_state stmts + (* Translates a clang instruction into SIL instructions. It takes a *) (* a trans_state containing current info on the translation and it returns *) (* a result_state.*) @@ -3120,6 +3123,11 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s -> trans_into_undefined_expr trans_state expr_info | ArrayInitIndexExpr _ | ArrayInitLoopExpr _ -> no_op_trans trans_state.succ_nodes + (* vector instructions for OpenCL etc. we basically ignore these for now; just translate the + sub-expressions *) + | ExtVectorElementExpr (_, stmts, _) + | ShuffleVectorExpr (_, stmts, _) + -> skip_unimplemented trans_state stmts (* Infer somehow ended up in templated non instantiated code - right now it's not supported and failure in those cases is expected. *) | SubstNonTypeTemplateParmExpr _ @@ -3127,10 +3135,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s | CXXDependentScopeMemberExpr _ -> raise (CTrans_utils.TemplatedCodeException instr) | s - -> L.(debug Capture Medium) - "@\n!!!!WARNING: found statement %s. @\nACTION REQUIRED: Translation need to be defined. Statement ignored.... @\n" - (Clang_ast_proj.get_stmt_kind_string s) ; - assert false + -> raise (CTrans_utils.UnsupportedStatementException s) (* Function similar to instruction function, but it takes C++ constructor initializer as an input parameter. *) diff --git a/infer/src/clang/cTrans_utils.ml b/infer/src/clang/cTrans_utils.ml index 5910a5c00..2ad0784d9 100644 --- a/infer/src/clang/cTrans_utils.ml +++ b/infer/src/clang/cTrans_utils.ml @@ -16,6 +16,8 @@ module L = Logging exception TemplatedCodeException of Clang_ast_t.stmt +exception UnsupportedStatementException of Clang_ast_t.stmt + (* Extract the element of a singleton list. If the list is not a singleton *) (* It stops the computation giving a warning. We use this because we *) (* assume in many places that a list is just a singleton. We use the *) diff --git a/infer/src/clang/cTrans_utils.mli b/infer/src/clang/cTrans_utils.mli index b338fe2bf..6edf6fdec 100644 --- a/infer/src/clang/cTrans_utils.mli +++ b/infer/src/clang/cTrans_utils.mli @@ -38,6 +38,8 @@ type trans_result = exception TemplatedCodeException of Clang_ast_t.stmt +exception UnsupportedStatementException of Clang_ast_t.stmt + val empty_res_trans : trans_result val undefined_expression : unit -> Exp.t diff --git a/infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp b/infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp new file mode 100644 index 000000000..474780290 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp @@ -0,0 +1,12 @@ +/* +1;95;0c * Copyright (c) 2017 - 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. + */ + +typedef __attribute__((ext_vector_type(2))) float vec_float2; + +vec_float2 simple(vec_float2 vec) { return vec.xy; } diff --git a/infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp.dot new file mode 100644 index 000000000..d7e122643 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/vectors/shuffle_vector.cpp.dot @@ -0,0 +1,14 @@ +/* @generated */ +digraph iCFG { +"simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_1" [label="1: Start simple\nFormals: vec:void\nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled] + + + "simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_1" -> "simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_3" ; +"simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_2" [label="2: Exit simple \n " color=yellow style=filled] + + +"simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_3" [label="3: Return Stmt \n n$0=*&vec:void [line 12]\n *&return:void=n$0 [line 12]\n " shape="box"] + + + "simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_3" -> "simple#_Z6simpleDv2_f.e9c9c4d600ba08c47099d8822b175fec_2" ; +}