diff --git a/ClangVisitor.cpp b/ClangVisitor.cpp index 67b951103b2714484474256d925272de376301c7..e58334e41e500c5cb11a2ba995b8911b9064b9f1 100644 --- a/ClangVisitor.cpp +++ b/ClangVisitor.cpp @@ -9169,8 +9169,7 @@ bool FramacVisitor::VisitVarDecl(clang::VarDecl* Decl) { clang::APValue* resultingValue = Decl->evaluateValue(); if (resultingValue) { constantType = Decl->hasExternalStorage()?ICEXTERNCONST:ICSTATICCONST; - clang::APValue* resultingValue = Decl->evaluateValue(); - value=(int64_t) resultingValue->getInt().getLimitedValue(UINT64_MAX); + value = resultingValue->getInt().getExtValue(); } }; }; diff --git a/convert.ml b/convert.ml index 57374686848f0cf0c66882b25e9644f6ac22b8ee..a793c7c941d42a1efb8e5c3dbf68a5d39551582f 100644 --- a/convert.ml +++ b/convert.ml @@ -200,7 +200,7 @@ let mk_int64_cst_n env ?(kind=IInt) i = let m = Int64.neg (Int64.succ i) in BINARY( SUB, mk_expr env (UNARY (MINUS, (mk_exp_64 m))), mk_exp_64 Int64.one) - end else UNARY(MINUS, mk_exp_64 i) + end else UNARY(MINUS, mk_exp_64 (Int64.neg i)) end else mk_node_64 i let mk_int64_cst env ?kind i = mk_expr env (mk_int64_cst_n env ?kind i) @@ -2043,16 +2043,7 @@ and convert_initializer env typ var init_exp does_remove_virtual = loc) in let eidx = { expr_loc = loc; expr_node = VARIABLE idx } in - let end_test = - { expr_loc = loc; - expr_node = - BINARY( - LT, - eidx, - { expr_loc = loc; - expr_node = - CONSTANT (CONST_INT (Int64.to_string v)) }) } - in + let end_test = mk_expr env (BINARY(LT,eidx,mk_int64_cst env v)) in let increment = { expr_loc = loc; expr_node = UNARY(POSINCR, eidx)} in @@ -2532,9 +2523,7 @@ let convert_static_const env loc name ikind kind value does_remove_virtual = | ICStaticConst -> SpecStorage STATIC :: spec | ICLiteral | ICExternConst -> spec in - let init = { expr_loc = cloc; - expr_node = CONSTANT (CONST_INT (Int64.to_string value))} - in + let init = mk_int64_cst env value in let env = Convert_env.add_global_var env qualified_name plain in DECDEF(None,(spec,[(name,JUSTBASE,[],cloc),SINGLE_INIT init]),cloc), env diff --git a/tests/basic/init.cc b/tests/basic/init.cc index 337d8039ffda7351e53f17608a6025066374c31f..8047500a3a0952bc76738ca206b65b725421c986 100644 --- a/tests/basic/init.cc +++ b/tests/basic/init.cc @@ -11,8 +11,13 @@ typedef struct myStruct { myStruct s = {}; +const int I = -1; +const long L = -1L; +const long long LL = -1LL; + int main() { - int x = 0; + int x = -1; + long long ll = I + L + LL; A y = { x, 1 }; y.a++; return x; diff --git a/tests/basic/oracle/init.res.oracle b/tests/basic/oracle/init.res.oracle index c9baccadd71f549820265aca2272ddc756e26fdd..45b89a05d3807f6e6eeb040e364cd86673e52a77 100644 --- a/tests/basic/oracle/init.res.oracle +++ b/tests/basic/oracle/init.res.oracle @@ -46,9 +46,13 @@ struct _frama_c_rtti_name_info_node _frama_c_rtti_name_info = .number_of_base_classes = 0, .pvmt = (struct _frama_c_vmt *)0}; myStruct s = {.a = {(char)0}}; +static int const I = -1; +static long const L = (long)(-1); +static long long const LL = (long long)(-1); int main(void) { - int x = 0; + int x = -1; + long long ll = (long long)((long)I + L) + LL; struct A y = {.a = & x, .b = 1}; (*(y.a)) ++; return x;