Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/frontc/cabs2cil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4423,11 +4423,21 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
| Lval (Var {vname= ("__builtin_nan" | "__builtin_nanf" | "__builtin_nanl" | "__builtin_nans" | "__builtin_nansf" | "__builtin_nansl"); _}, NoOffset) -> true
| _ -> false
in
let isSparseBuiltin =
match f'' with
| Lval (Var {vname= ("__context__"); _}, NoOffset) ->
ignore (warn "Ignoring __context__ builtin of Linux kernel Sparse");
true
| _ -> false
in
if isBuiltinNan && asconst then
(* Replace call to builtin nan with computation yielding NaN *)
let onef = Const(CReal(0.0,FDouble,None)) in
let zerodivzero = mkCast ~kind:Internal ~e:(BinOp(Div,onef,onef,doubleType)) ~newt:resType in
(empty,zerodivzero,resType)
else if isSparseBuiltin then
let one = Const(CInt(cilint_of_int 1, IInt, None)) in
(empty, one, intType)
Comment on lines +4438 to +4440
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to replace it with an arbitrary constant 1?
Why does it need to be handled in CIL? Couldn't it just remain as a normal function call that's added to Goblint's LibraryFunctions?

Or alternatively, wouldn't it be enough to introduce initSparseBuiltins like

cil/src/cil.ml

Line 2903 in e21285a

let initGccBuiltins () : unit =
if it needs an implicit declaration and a signature?
Most builtins are not specifically handled here, only the ones that really have to do something at compile time. But this __context__ doesn't seem to require anything like this.

else (
(* If the "--forceRLArgEval" flag was used, make sure
we evaluate args right-to-left.
Expand Down
4 changes: 4 additions & 0 deletions test/small1/sparse_context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void test() {
__context__(RCU);
__context__(This, should, be, ignored);
}