diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index ce42fb952..6d6ed6f1f 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2253,6 +2253,8 @@ struct | ImplicitValueInitExpr (_, _, expr_info) -> implicitValueInitExpr_trans trans_state expr_info + | GenericSelectionExpr _ -> (* to be fixed when we dump the right info in the ast *) + { empty_res_trans with exps = [(Sil.exp_get_undefined false, Sil.Tvoid)] } | s -> (Printing.log_stats "\n!!!!WARNING: found statement %s. \nACTION REQUIRED: Translation need to be defined. Statement ignored.... \n" diff --git a/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c b/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c new file mode 100644 index 000000000..80f830052 --- /dev/null +++ b/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2016 - 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. + */ + +#define test(x) _Generic((x), _Bool : 1, char : 2, int : 3, default : 4) + +int test_typename(void) { + char s; + int y; + int x = test(s); + int z = test(y); diff --git a/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot b/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot new file mode 100644 index 000000000..d40e4667a --- /dev/null +++ b/infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c.dot @@ -0,0 +1,17 @@ +digraph iCFG { +4 [label="4: DeclStmt \n *&x:void =_t$1 [line 15]\n NULLIFY(&x,false); [line 15]\n " shape="box"] + + + 4 -> 3 ; +3 [label="3: DeclStmt \n *&z:void =_t$0 [line 16]\n NULLIFY(&z,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit test_typename \n " color=yellow style=filled] + + +1 [label="1: Start test_typename\nFormals: \nLocals: z:int x:int y:int s:char \n DECLARE_LOCALS(&return,&z,&x,&y,&s); [line 12]\n NULLIFY(&s,false); [line 12]\n NULLIFY(&x,false); [line 12]\n NULLIFY(&y,false); [line 12]\n NULLIFY(&z,false); [line 12]\n " color=yellow style=filled] + + + 1 -> 4 ; +} diff --git a/infer/tests/frontend/c/UnusualExprTest.java b/infer/tests/frontend/c/UnusualExprTest.java new file mode 100644 index 000000000..2e1335904 --- /dev/null +++ b/infer/tests/frontend/c/UnusualExprTest.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013 - 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. + */ + +package frontend.c; + +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; + +import utils.DebuggableTemporaryFolder; +import utils.InferException; +import utils.ClangFrontendUtils; + +public class UnusualExprTest { + + @Rule + public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); + + @Test + public void whenCaptureRunEnumThenDotFilesAreTheSame() + throws InterruptedException, IOException, InferException { + String src = "infer/tests/codetoanalyze/c/frontend/unusual_exps/generic_exp.c"; + ClangFrontendUtils.createAndCompareCDotFiles(folder, src); + } +}