Skip to content

Commit 5112622

Browse files
committed
Handle MSVC's __noop in type checker
The documentation states that it does not generate any code other than `0`. Hence, don't maintain a library function, but instead discard the expression in the type checker.
1 parent 56944fb commit 5112622

File tree

11 files changed

+17
-51
lines changed

11 files changed

+17
-51
lines changed

regression/cbmc-library/__noop-01/main.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

regression/cbmc-library/__noop-01/test.desc

Lines changed: 0 additions & 8 deletions
This file was deleted.

regression/cbmc/noop1/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#include <assert.h>
2-
31
int some_function()
42
{
53
// this will not be executed
6-
assert(0);
4+
__CPROVER_assert(0, "not executed");
75
}
86

97
int main()

regression/cbmc/noop1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
3+
-winx64
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ void ansi_c_internal_additions(std::string &code)
295295

296296
// this is Visual C/C++ only
297297
if(config.ansi_c.os==configt::ansi_ct::ost::OS_WIN)
298-
code+="int __noop();\n"
299-
"int __assume(int);\n";
298+
code += "int __assume(int);\n";
300299

301300
// ARM stuff
302301
if(config.ansi_c.mode==configt::ansi_ct::flavourt::ARM)

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,20 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
18841884
{
18851885
// yes, it's a builtin
18861886
}
1887+
else if(
1888+
identifier == "__noop" &&
1889+
config.ansi_c.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
1890+
{
1891+
// https://docs.microsoft.com/en-us/cpp/intrinsics/noop
1892+
// typecheck and discard, just generating 0 instead
1893+
for(auto &op : expr.arguments())
1894+
typecheck_expr(op);
1895+
1896+
exprt result = from_integer(0, signed_int_type());
1897+
expr.swap(result);
1898+
1899+
return;
1900+
}
18871901
else if(
18881902
auto gcc_polymorphic = typecheck_gcc_polymorphic_builtin(
18891903
identifier, expr.arguments(), f_op.source_location()))

src/ansi-c/library/noop.c

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/ansi-c/library_check.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ for f in "$@"; do
1010
perl -p -i -e 's/(_mm_.fence)/s$1/' __libcheck.c
1111
perl -p -i -e 's/(__sync_)/s$1/' __libcheck.c
1212
perl -p -i -e 's/(__atomic_)/s$1/' __libcheck.c
13-
perl -p -i -e 's/(__noop)/s$1/' __libcheck.c
1413
"$CC" -std=gnu99 -E -include library/cprover.h -D__CPROVER_bool=_Bool -D__CPROVER_thread_local=__thread -DLIBRARY_CHECK -o __libcheck.i __libcheck.c
1514
"$CC" -S -Wall -Werror -pedantic -Wextra -std=gnu99 __libcheck.i \
1615
-o __libcheck.s -Wno-unused-label -Wno-unknown-pragmas

src/ansi-c/windows_builtin_headers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
int __noop();
21
int __assume(int);

src/goto-programs/goto_clean_expr.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,6 @@ void goto_convertt::clean_expr(
387387
return;
388388
}
389389
}
390-
else if(statement==ID_function_call)
391-
{
392-
if(to_side_effect_expr_function_call(expr).function().id()==ID_symbol &&
393-
to_symbol_expr(
394-
to_side_effect_expr_function_call(expr).
395-
function()).get_identifier()=="__noop")
396-
{
397-
// __noop needs special treatment, as arguments are not
398-
// evaluated
399-
to_side_effect_expr_function_call(expr).arguments().clear();
400-
}
401-
}
402390
}
403391
else if(expr.id()==ID_forall || expr.id()==ID_exists)
404392
{

src/goto-programs/goto_convert_function_call.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ void goto_convertt::do_function_call(
5353

5454
clean_expr(new_function, dest, mode);
5555

56-
// the arguments of __noop do not get evaluated
57-
if(new_function.id()==ID_symbol &&
58-
to_symbol_expr(new_function).get_identifier()=="__noop")
59-
{
60-
new_arguments.clear();
61-
}
62-
6356
Forall_expr(it, new_arguments)
6457
clean_expr(*it, dest, mode);
6558

0 commit comments

Comments
 (0)