[clang] translate user-defined literals

Summary: We used to crash whenever we hit these. The simple translation implemented here is not particularly inspiring, but it is better than crashing.

Reviewed By: jvillard

Differential Revision: D5702095

fbshipit-source-id: 3795d43
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent de9d8f45ff
commit 9772b2299d

@ -1089,7 +1089,9 @@ let pp_proplist_parsed2dotty_file filename plist =
(* channel. You have to compute an interprocedural cfg first *)
let pp_cfgnodename pname fmt (n: Procdesc.Node.t) =
F.fprintf fmt "\"%s_%d\"" (Typ.Procname.to_filename pname) (Procdesc.Node.get_id n :> int)
F.fprintf fmt "\"%s_%d\""
(Escape.escape_dotty (Typ.Procname.to_filename pname))
(Procdesc.Node.get_id n :> int)
let pp_etlist byvals fmt etl =
List.iteri
@ -1110,7 +1112,7 @@ let pp_cfgnodelabel pdesc fmt (n: Procdesc.Node.t) =
let pp_label fmt n =
match Procdesc.Node.get_kind n with
| Procdesc.Node.Start_node pname
-> let pname_string = Typ.Procname.to_string pname in
-> let pname_string = Escape.escape_dotty (Typ.Procname.to_string pname) in
let attributes = Procdesc.get_attributes pdesc in
let byvals = attributes.ProcAttributes.by_vals in
Format.fprintf fmt "Start %s\\nFormals: %a\\nLocals: %a" pname_string (pp_etlist byvals)
@ -1121,7 +1123,7 @@ let pp_cfgnodelabel pdesc fmt (n: Procdesc.Node.t) =
if not (Annot.Method.is_empty method_annotation) then
Format.fprintf fmt "\\nAnnotation: %a" (Annot.Method.pp pname_string) method_annotation
| Procdesc.Node.Exit_node pname
-> Format.fprintf fmt "Exit %s" (Typ.Procname.to_string pname)
-> Format.fprintf fmt "Exit %s" (Escape.escape_dotty (Typ.Procname.to_string pname))
| Procdesc.Node.Join_node
-> Format.fprintf fmt "+"
| Procdesc.Node.Prune_node (is_true_branch, _, _)

@ -3127,6 +3127,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
sub-expressions *)
| ExtVectorElementExpr (_, stmts, _)
| ShuffleVectorExpr (_, stmts, _)
| UserDefinedLiteral (_, 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. *)

@ -0,0 +1,12 @@
/*
* Copyright (c) 2015 - 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.
*/
int operator"" _literal(unsigned long long i) { return i; }
int foo() { return 0_literal; }

@ -0,0 +1,25 @@
/* @generated */
digraph iCFG {
"foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_1" [label="1: Start foo\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled]
"foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_1" -> "foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_3" ;
"foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_2" [label="2: Exit foo \n " color=yellow style=filled]
"foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_3" [label="3: Return Stmt \n *&return:int=-1 [line 12]\n " shape="box"]
"foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_3" -> "foo#_Z3foov.69dc85dbfdb3da90badccdb11670a4ca_2" ;
"operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_1" [label="1: Start operator\"\"_literal\nFormals: i:unsigned long long\nLocals: \n DECLARE_LOCALS(&return); [line 10]\n " color=yellow style=filled]
"operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_1" -> "operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_3" ;
"operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_2" [label="2: Exit operator\"\"_literal \n " color=yellow style=filled]
"operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_3" [label="3: Return Stmt \n n$0=*&i:unsigned long long [line 10]\n *&return:int=n$0 [line 10]\n " shape="box"]
"operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_3" -> "operator\"\"_literal#_Zli8_literaly.5b4cb9a2f3419057428a12f4b4e6b72b_2" ;
}
Loading…
Cancel
Save