Skip to content

Re-use C type conversion in C++ front-end [blocks: #4560] #4559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2019
Merged
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
2 changes: 1 addition & 1 deletion regression/ansi-c/always_inline5/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE gcc-only broken-test-c++-front-end
CORE gcc-only test-c++-front-end
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/ansi-c/builtin_ia32_undef/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE test-c++-front-end
CORE broken-test-c++-front-end
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/ansi-c/gcc_attributes3/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE gcc-only broken-test-c++-front-end
CORE gcc-only test-c++-front-end
main.c

^EXIT=0$
Expand Down
6 changes: 6 additions & 0 deletions regression/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_test_pl_tests(
"$<TARGET_FILE:goto-cc>" -X gcc-only
)
else()
add_test_pl_tests(
"$<TARGET_FILE:goto-cc>"
)
endif()
2 changes: 1 addition & 1 deletion regression/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include ../../src/config.inc
include ../../src/common

ifeq ($(BUILD_ENV_),MSVC)
exe=../../../src/goto-cc/goto-cl
exe=../../../src/goto-cc/goto-cl -X gcc-only
else
exe=../../../src/goto-cc/goto-cc
endif
Expand Down
12 changes: 12 additions & 0 deletions regression/cpp/gcc_attributes1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifdef __GNUC__
const char *__attribute__((weak)) bar();
#endif

int main()
{
#ifdef __GNUC__
return bar() != 0;
#else
return 0
#endif
}
8 changes: 8 additions & 0 deletions regression/cpp/gcc_attributes1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE gcc-only
main.cpp

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
11 changes: 11 additions & 0 deletions src/ansi-c/ansi_c_convert_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,13 @@ void ansi_c_convert_typet::write(typet &type)
}
}

build_type_with_subtype(type);
set_attributes(type);
}

/// Build a vector or complex type with \p type as subtype.
void ansi_c_convert_typet::build_type_with_subtype(typet &type) const
{
if(vector_size.is_not_nil())
{
type_with_subtypet new_type(ID_frontend_vector, type);
Expand All @@ -604,7 +611,11 @@ void ansi_c_convert_typet::write(typet &type)
new_type.add_source_location()=source_location;
type.swap(new_type);
}
}

/// Add qualifiers and GCC attributes onto \p type.
void ansi_c_convert_typet::set_attributes(typet &type) const
{
if(gcc_attribute_mode.is_not_nil())
{
typet new_type=gcc_attribute_mode;
Expand Down
10 changes: 6 additions & 4 deletions src/ansi-c/ansi_c_convert_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class ansi_c_convert_typet:public messaget
// qualifiers
c_qualifierst c_qualifiers;

void read(const typet &type);
void write(typet &type);
virtual void read(const typet &type);
virtual void write(typet &type);

source_locationt source_location;

Expand All @@ -64,7 +64,7 @@ class ansi_c_convert_typet:public messaget
{
}

void clear()
virtual void clear()
{
unsigned_cnt=signed_cnt=char_cnt=int_cnt=short_cnt=
long_cnt=double_cnt=float_cnt=c_bool_cnt=proper_bool_cnt=complex_cnt=
Expand All @@ -90,7 +90,9 @@ class ansi_c_convert_typet:public messaget
}

protected:
void read_rec(const typet &type);
virtual void read_rec(const typet &type);
virtual void build_type_with_subtype(typet &type) const;
virtual void set_attributes(typet &type) const;
};

#endif // CPROVER_ANSI_C_ANSI_C_CONVERT_TYPE_H
Loading