From 87dfcdeb991f5716bfc84e9f09c03c08c332e5f5 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Tue, 20 Oct 2015 06:43:16 -0700 Subject: [PATCH] Replace '/' in anonymous type names Summary: public anonymous types have file:line in its name. Since file is relative path, type name can have '/' in its name. This is very fragile since we might create file wiht typename in its name (for example for methods). Replacing '/' with '_' should make frontend more resilient to failure. Translation of anonymous structs is still pretty fragile (due to relative path in its name), but at least it doesn't crash frontend Reviewed By: dulmarod Differential Revision: D2559936 fb-gh-sync-id: 647fd7f --- infer/src/clang/cTypes_decl.ml | 3 ++- .../codetoanalyze/c/frontend/nestedoperators/union.c.dot | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/infer/src/clang/cTypes_decl.ml b/infer/src/clang/cTypes_decl.ml index ea7e9d2fa..9add18735 100644 --- a/infer/src/clang/cTypes_decl.ml +++ b/infer/src/clang/cTypes_decl.ml @@ -69,7 +69,8 @@ let add_predefined_types tenv = let create_csu opt_type = match opt_type with | `Type s -> - (let buf = Str.split (Str.regexp "[ \t]+") s in + (let no_slash = Str.global_replace (Str.regexp "/") "_" s in + let buf = Str.split (Str.regexp "[ \t]+") no_slash in match buf with | "struct":: l ->Sil.Struct, General_utils.string_from_list l | "class":: l -> Sil.Class, General_utils.string_from_list l diff --git a/infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c.dot b/infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c.dot index 35158cbff..7009e551f 100644 --- a/infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c.dot @@ -1,5 +1,5 @@ digraph iCFG { -7 [label="7: BinaryOperatorStmt: Assign \n n$3=*&#GB$x:struct (anonymous at infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c:12:1) * [line 27]\n *n$3.a:int =1 [line 27]\n REMOVE_TEMPS(n$3); [line 27]\n " shape="box"] +7 [label="7: BinaryOperatorStmt: Assign \n n$3=*&#GB$x:struct (anonymous at infer_tests_codetoanalyze_c_frontend_nestedoperators_union.c:12:1) * [line 27]\n *n$3.a:int =1 [line 27]\n REMOVE_TEMPS(n$3); [line 27]\n " shape="box"] 7 -> 6 ; @@ -11,7 +11,7 @@ digraph iCFG { 5 -> 4 ; -4 [label="4: BinaryOperatorStmt: Assign \n n$0=*&#GB$x:struct (anonymous at infer/tests/codetoanalyze/c/frontend/nestedoperators/union.c:12:1) * [line 31]\n n$1=*n$0.b:int [line 31]\n *&#GB$y.g.w:int =n$1 [line 31]\n REMOVE_TEMPS(n$0,n$1); [line 31]\n " shape="box"] +4 [label="4: BinaryOperatorStmt: Assign \n n$0=*&#GB$x:struct (anonymous at infer_tests_codetoanalyze_c_frontend_nestedoperators_union.c:12:1) * [line 31]\n n$1=*n$0.b:int [line 31]\n *&#GB$y.g.w:int =n$1 [line 31]\n REMOVE_TEMPS(n$0,n$1); [line 31]\n " shape="box"] 4 -> 3 ;