forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request diffblue#2448 from tautschnig/c++-delayed-body
Fix delayed method body conversion for templates
- Loading branch information
Showing
21 changed files
with
182 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=10$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=10$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=10$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "cpp_typecheck.h" | ||
|
||
#ifdef DEBUG | ||
#include <iostream> | ||
#endif | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/base_exceptions.h> | ||
#include <util/simplify_expr.h> | ||
|
@@ -220,6 +224,10 @@ const symbolt &cpp_typecheckt::instantiate_template( | |
const cpp_template_args_tct &full_template_args, | ||
const typet &specialization) | ||
{ | ||
#ifdef DEBUG | ||
std::cout << "instantiate_template: " << template_symbol.name << '\n'; | ||
#endif | ||
|
||
if(instantiation_stack.size()==MAX_DEPTH) | ||
{ | ||
error().source_location=source_location; | ||
|
@@ -233,10 +241,10 @@ const symbolt &cpp_typecheckt::instantiate_template( | |
instantiation_stack.back().identifier=template_symbol.name; | ||
instantiation_stack.back().full_template_args=full_template_args; | ||
|
||
#if 0 | ||
#ifdef DEBUG | ||
std::cout << "L: " << source_location << '\n'; | ||
std::cout << "I: " << template_symbol.name << '\n'; | ||
#endif | ||
#endif | ||
|
||
cpp_saved_template_mapt saved_map(template_map); | ||
|
||
|
@@ -246,7 +254,7 @@ const symbolt &cpp_typecheckt::instantiate_template( | |
assert(!specialization_template_args.has_unassigned()); | ||
assert(!full_template_args.has_unassigned()); | ||
|
||
#if 0 | ||
#ifdef DEBUG | ||
std::cout << "A: <"; | ||
forall_expr(it, specialization_template_args.arguments()) | ||
{ | ||
|
@@ -257,8 +265,8 @@ const symbolt &cpp_typecheckt::instantiate_template( | |
else | ||
std::cout << to_string(*it); | ||
} | ||
std::cout << ">\n"; | ||
#endif | ||
std::cout << ">\n\n"; | ||
#endif | ||
|
||
// do we have arguments? | ||
if(full_template_args.arguments().empty()) | ||
|
@@ -373,8 +381,8 @@ const symbolt &cpp_typecheckt::instantiate_template( | |
instantiated_with.get_sub().push_back(specialization_template_args); | ||
} | ||
|
||
#if 0 | ||
std::cout << "MAP:\n"; | ||
#ifdef DEBUG | ||
std::cout << "CLASS MAP:\n"; | ||
template_map.print(std::cout); | ||
#endif | ||
|
||
|
@@ -432,14 +440,29 @@ const symbolt &cpp_typecheckt::instantiate_template( | |
|
||
// mapping from template arguments to values/types | ||
template_map.build(method_type, specialization_template_args); | ||
#ifdef DEBUG | ||
std::cout << "METHOD MAP:\n"; | ||
template_map.print(std::cout); | ||
#endif | ||
|
||
method_decl.remove(ID_template_type); | ||
method_decl.remove(ID_is_template); | ||
|
||
convert(method_decl); | ||
} | ||
|
||
const symbolt &new_symb = lookup(new_decl.type().get(ID_identifier)); | ||
const irep_idt& new_symb_id = new_decl.type().get(ID_identifier); | ||
symbolt &new_symb = symbol_table.get_writeable_ref(new_symb_id); | ||
|
||
// add template arguments to type in order to retrieve template map when | ||
// typechecking function body | ||
new_symb.type.set(ID_C_template, template_type); | ||
new_symb.type.set(ID_C_template_arguments, specialization_template_args); | ||
|
||
#ifdef DEBUG | ||
std::cout << "instance symbol: " << new_symb.name << "\n\n"; | ||
std::cout << "template type: " << template_type.pretty() << "\n\n"; | ||
#endif | ||
|
||
return new_symb; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "cpp_typecheck.h" | ||
|
||
#ifdef DEBUG | ||
#include <iostream> | ||
#endif | ||
|
||
#include <algorithm> | ||
|
||
#include <util/arith_tools.h> | ||
|
@@ -395,7 +399,7 @@ void cpp_typecheckt::typecheck_compound_declarator( | |
irep_idt identifier; | ||
|
||
// the below is a temporary hack | ||
// if(is_method || is_static)d | ||
// if(is_method || is_static) | ||
if(id2string(cpp_scopes.current_scope().prefix).find("#anon")== | ||
std::string::npos || | ||
is_method || is_static) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ Author: Daniel Kroening, [email protected] | |
\********************************************************************/ | ||
|
||
|
||
/// \file | ||
/// C++ Language Type Checking | ||
|
||
|
@@ -19,21 +20,15 @@ void cpp_typecheckt::convert(cpp_declarationt &declaration) | |
if(declaration.is_empty()) | ||
return; | ||
|
||
// Record the function bodies so we can check them later. | ||
// This function is used recursively, so we save them. | ||
method_bodiest old_method_bodies; | ||
old_method_bodies.swap(method_bodies); | ||
// The function bodies must not be checked here, | ||
// but only at the very end when all declarations have been | ||
// processed (or considering forward declarations at least) | ||
|
||
// templates are done in a dedicated function | ||
if(declaration.is_template()) | ||
convert_template_declaration(declaration); | ||
else | ||
convert_non_template_declaration(declaration); | ||
|
||
method_bodiest b; | ||
b.swap(method_bodies); | ||
typecheck_method_bodies(b); | ||
method_bodies.swap(old_method_bodies); | ||
} | ||
|
||
void cpp_typecheckt::convert_anonymous_union( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,28 @@ Author: Daniel Kroening, [email protected] | |
/// \file | ||
/// C++ Language Type Checking | ||
|
||
#ifdef DEBUG | ||
#include <iostream> | ||
#endif | ||
|
||
#include "cpp_typecheck.h" | ||
|
||
void cpp_typecheckt::typecheck_method_bodies( | ||
method_bodiest &bodies) | ||
void cpp_typecheckt::typecheck_method_bodies() | ||
{ | ||
instantiation_stackt old_instantiation_stack; | ||
old_instantiation_stack.swap(instantiation_stack); | ||
|
||
for(auto &b : bodies) | ||
while(!method_bodies.empty()) | ||
{ | ||
symbolt &method_symbol=*b.method_symbol; | ||
template_map.swap(b.template_map); | ||
instantiation_stack.swap(b.instantiation_stack); | ||
// Dangerous not to take a copy here. We'll have to make sure that | ||
// convert is never called with the same symbol twice. | ||
method_bodyt &method_body = *method_bodies.begin(); | ||
symbolt &method_symbol = *method_body.method_symbol; | ||
|
||
template_map.swap(method_body.template_map); | ||
instantiation_stack.swap(method_body.instantiation_stack); | ||
|
||
method_bodies.erase(method_bodies.begin()); | ||
|
||
if(method_symbol.name==ID_main) | ||
add_argc_argv(method_symbol); | ||
|
@@ -30,9 +39,37 @@ void cpp_typecheckt::typecheck_method_bodies( | |
if(body.id()=="cpp_not_typechecked") | ||
continue; | ||
|
||
#ifdef DEBUG | ||
std::cout << "convert_method_body: " << method_symbol.name << std::endl; | ||
std::cout << " is_not_nil: " << body.is_not_nil() << std::endl; | ||
std::cout << " !is_zero: " << (!body.is_zero()) << std::endl; | ||
#endif | ||
if(body.is_not_nil() && !body.is_zero()) | ||
convert_function(method_symbol); | ||
} | ||
|
||
old_instantiation_stack.swap(instantiation_stack); | ||
} | ||
|
||
void cpp_typecheckt::add_method_body(symbolt *_method_symbol) | ||
{ | ||
#ifdef DEBUG | ||
std::cout << "add_method_body: " << _method_symbol->name << std::endl; | ||
#endif | ||
|
||
// We have to prevent the same method to be added multiple times | ||
// otherwise we get duplicated symbol prefixes | ||
if(methods_seen.find(_method_symbol->name) != methods_seen.end()) | ||
{ | ||
#ifdef DEBUG | ||
std::cout << " already exists" << std::endl; | ||
#endif | ||
return; | ||
} | ||
method_bodies.push_back( | ||
method_bodyt(_method_symbol, template_map, instantiation_stack)); | ||
|
||
// Converting a method body might add method bodies for methods | ||
// that we have already analyzed. Hence, we have to keep track. | ||
methods_seen.insert(_method_symbol->name); | ||
} |
Oops, something went wrong.