Commit 72526845 authored by Franck Vedrine's avatar Franck Vedrine
Browse files

Merge branch 'fix/init-global-int' into 'stable/chromium'

Fix translation of negative integer litterals

See merge request frama-c/frama-clang!169
parents e390eaa0 03b66079
......@@ -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();
}
};
};
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment