Skip to content

Commit 95097a8

Browse files
authored
Merge pull request diffblue#5685 from tautschnig/noop
Handle MSVC's __noop in type checker
2 parents 4c3a0a6 + 42e1431 commit 95097a8

File tree

14 files changed

+48
-45
lines changed

14 files changed

+48
-45
lines changed

regression/ansi-c/noop1/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// this is permitted - __noop yields a compile-time constant 0
2+
int array[__noop() + 1];
3+
4+
struct S
5+
{
6+
int x;
7+
};
8+
9+
int main(int argc, char *argv)
10+
{
11+
struct S s;
12+
// the arguments to __noop are type checked, and thus the following is not
13+
// permitted
14+
__noop((char *)s);
15+
}

regression/ansi-c/noop1/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--i386-win32
4+
type cast from 'struct S' not permitted
5+
^EXIT=(1|64)$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

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

Lines changed: 0 additions & 9 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$

regression/cbmc/noop2/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main(int argc, char *argv)
2+
{
3+
int x = 0;
4+
__noop(++x);
5+
__CPROVER_assert(x == 0, "__noop ignores side effects");
6+
}

regression/cbmc-library/__noop-01/test.desc renamed to regression/cbmc/noop2/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--pointer-check --bounds-check
3+
-win32
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)