-
Notifications
You must be signed in to change notification settings - Fork 273
Linking: replace conflicting pointer types when one declaration is extern #2024
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdlib.h> | ||
|
||
void foo(); | ||
|
||
int main() | ||
{ | ||
extern void *p; | ||
p = malloc(sizeof(int)); | ||
foo(); | ||
return 0; | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
int *p; | ||
|
||
void foo() | ||
{ | ||
*p = 42; | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
b.c | ||
a.c --pointer-check | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -24,6 +24,21 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "linking_class.h" | ||
|
||
bool casting_replace_symbolt::replace_symbol_expr(symbol_exprt &s) const | ||
{ | ||
expr_mapt::const_iterator it = expr_map.find(s.get_identifier()); | ||
|
||
if(it == expr_map.end()) | ||
return true; | ||
|
||
const exprt &e = it->second; | ||
|
||
typet type = s.type(); | ||
static_cast<exprt &>(s) = typecast_exprt::conditional_cast(e, type); | ||
|
||
return false; | ||
} | ||
|
||
std::string linkingt::expr_to_string( | ||
const namespacet &ns, | ||
const irep_idt &identifier, | ||
|
@@ -864,6 +879,11 @@ bool linkingt::adjust_object_type_rec( | |
"conflicting pointer types for variable"); | ||
#endif | ||
|
||
if(info.old_symbol.is_extern && !info.new_symbol.is_extern) | ||
{ | ||
info.set_to_new = true; // store new type | ||
} | ||
|
||
return false; | ||
} | ||
else if(t1.id()==ID_array && | ||
|
@@ -950,10 +970,10 @@ void linkingt::duplicate_object_symbol( | |
symbolt &new_symbol) | ||
{ | ||
// both are variables | ||
bool set_to_new = false; | ||
|
||
if(!base_type_eq(old_symbol.type, new_symbol.type, ns)) | ||
{ | ||
bool set_to_new=false; | ||
bool failed= | ||
adjust_object_type(old_symbol, new_symbol, set_to_new); | ||
|
||
|
@@ -1033,6 +1053,14 @@ void linkingt::duplicate_object_symbol( | |
} | ||
} | ||
} | ||
else if( | ||
set_to_new && !old_symbol.value.is_nil() && | ||
!old_symbol.value.get_bool(ID_C_zero_initializer)) | ||
{ | ||
// the type has been updated, now make sure that the initialising assignment | ||
// will have matching types | ||
old_symbol.value.make_typecast(old_symbol.type); | ||
} | ||
} | ||
|
||
void linkingt::duplicate_non_type_symbol( | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -18,6 +18,12 @@ Author: Daniel Kroening, [email protected] | |
#include <util/typecheck.h> | ||
#include <util/std_expr.h> | ||
|
||
class casting_replace_symbolt : public replace_symbolt | ||
{ | ||
private: | ||
bool replace_symbol_expr(symbol_exprt &dest) const override; | ||
}; | ||
|
||
class linkingt:public typecheckt | ||
{ | ||
public: | ||
|
@@ -35,7 +41,7 @@ class linkingt:public typecheckt | |
virtual void typecheck(); | ||
|
||
rename_symbolt rename_symbol; | ||
unchecked_replace_symbolt object_type_updates; | ||
casting_replace_symbolt object_type_updates; | ||
|
||
protected: | ||
bool needs_renaming_type( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turn into error when in gcc or clang mode?