Commit 7ba8259e authored by Virgile Prevosto's avatar Virgile Prevosto Committed by Andre Maroneze
Browse files

[constfold] more aggressive constfolding in dead branches of global initializer

otherwise, we might end up with an improper crash of cabs2cil
parent 2db8b0c2
......@@ -7216,7 +7216,7 @@ and doExp local_env
we won't evaluate it. Hence, it can contain
non-const constructions *)
let asconst =
if is_true_cond = `CFalse then CNoConst else asconst
if is_true_cond = `CFalse then CMayConst else asconst
in
let r2, se2, e2', t2 =
doExp (no_paren_local_env local_env) asconst e2 what'
......@@ -7224,18 +7224,20 @@ and doExp local_env
r2, se2, Some e2', t2
in
(* Do e3 for real. See above for the value of asconst *)
let asconst' = if is_true_cond = `CTrue then CNoConst else asconst in
let asconst' = if is_true_cond = `CTrue then CMayConst else asconst in
let r3, se3, e3', t3 =
doExp (no_paren_local_env local_env) asconst' e3 what'
in
let tresult = conditionalConversion t2 t3 in
if asconst <> CNoConst && is_true_cond = `CTrue then begin
clean_up_chunk_locals se2;
clean_up_chunk_locals se3;
let loc = e2.expr_loc in
let e2' = match e2'o with None -> Cil.one ~loc | Some e -> e in
let _,e2' = castTo t2 tresult e2' in
finishExp [] empty e2' tresult;
end else if asconst <> CNoConst && is_true_cond = `CFalse then begin
clean_up_chunk_locals se2;
clean_up_chunk_locals se3;
let _,e3' = castTo t3 tresult e3' in
finishExp [] empty e3' tresult
......
......@@ -10,6 +10,8 @@ char test_ge = { ((-1.) >= 0.) ? 1. : 2. };
char test_cast[] = { 1 >= (0?1U:(-1)) ? 1. : 2.,
((double)1) >= (0?1U:(-1)) ? 1. : 2. };
double a = 2 >= 5 ? 5 ? (long)0 || 0 ? 0. >= 0 ?: 0 : 2 : 5 : 0;
extern int f(void);
/* no call should be evaluated. */
......
......@@ -4,5 +4,6 @@ char pixels[3] = {(char)0.0, (char)0.0, (char)1.0};
char test_neg = (char)2.;
char test_ge = (char)2.;
char test_cast[2] = {(char)2., (char)2.};
double a = (double)0;
char no_call[2] = {(char)1, (char)2};
Markdown is supported
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