Skip to content

Commit 875d3a4

Browse files
Allow cast any type to TVoid to just evaluate side-effects
1 parent 918a4ef commit 875d3a4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/frontc/cabs2cil.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ let rec castTo ?(fromsource=false)
14161416
result
14171417

14181418
(* The expression is evaluated for its side-effects *)
1419-
| (TInt _ | TEnum _ | TPtr _ ), TVoid _ ->
1419+
| _ , TVoid _ ->
14201420
(ot, e)
14211421

14221422
(* Even casts between structs are allowed when we are only

test/small1/c99-tgmath2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ typedef struct loc_t
1010

1111

1212
void fun(const loc_t* loc) {
13-
long l;
13+
long l =8;
1414
int n0 =(int)sqrt(l); // works
1515
int n1 =(int)sqrt(loc->nloc); // fails
1616
}
@@ -21,4 +21,5 @@ int main() {
2121
loc.nloc = 5;
2222
loc_t* ptr = &loc;
2323
fun(ptr);
24+
SUCCESS;
2425
}

0 commit comments

Comments
 (0)