Skip to content

Commit e4c80a5

Browse files
authored
Merge pull request #5285 from thk123/cpp-new-cmake
Fix CPP models when using CMake Build
2 parents 641a14e + 9c5a5c4 commit e4c80a5

File tree

7 files changed

+59
-9
lines changed

7 files changed

+59
-9
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <cassert>
2+
3+
int main()
4+
{
5+
int *some_data = new int(10);
6+
assert(some_data);
7+
assert(*some_data == 10);
8+
return 0;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.cpp
3+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Ensure that the new operator is implemented.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--string-abstraction --show-goto-functions
4+
strlen#return_value = \(.*\)s#strarg->length - POINTER_OFFSET\(s\);
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Ensure that the --string-abstraction flag enables the string abstraction
10+
version of string functions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--show-goto-functions
4+
IF !\(\(signed int\)s\[\(.*\)len\] != 0\) THEN GOTO 2
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Ensure that if the string abstraction flag is not provided, the regular model for
10+
string functions is used (in this case searching for the terminator).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
int main()
5+
{
6+
char *x = malloc(sizeof(char) * 10);
7+
x[8] = '\0';
8+
assert(strlen(x) == 8);
9+
}

src/ansi-c/cprover_library.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ std::string get_cprover_library_text(
4545
const struct cprover_library_entryt cprover_library[],
4646
const std::string &prologue)
4747
{
48-
std::ostringstream library_text(prologue);
48+
// the default mode is ios_base::out which means subsequent write to the
49+
// stream will overwrite the original content
50+
std::ostringstream library_text(prologue, std::ios_base::ate);
4951

5052
std::size_t count=0;
5153

src/cpp/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
file(GLOB cpp_library_sources "library/*.c")
22

3-
add_custom_command(OUTPUT converter_input.txt
4-
COMMAND cat ${cpp_library_sources} > converter_input.txt
5-
DEPENDS ${cpp_library_sources}
6-
)
7-
83
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
9-
COMMAND ../ansi-c/converter < "converter_input.txt" > "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
10-
DEPENDS "converter_input.txt" ../ansi-c/converter
11-
)
4+
COMMAND cat ${cpp_library_sources} | $<TARGET_FILE:converter> > "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
5+
DEPENDS converter ${cpp_library_sources})
126

137
################################################################################
148

@@ -33,6 +27,12 @@ endif()
3327
file(GLOB_RECURSE sources "*.cpp" "*.h")
3428
add_library(cpp ${sources})
3529

30+
set_source_files_properties(
31+
${sources}
32+
PROPERTIES
33+
OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/cprover_library.inc"
34+
)
35+
3636
generic_includes(cpp)
3737

3838
target_link_libraries(cpp util ansi-c)

0 commit comments

Comments
 (0)