forked from checkedc/checkedc-clang
-
Notifications
You must be signed in to change notification settings - Fork 5
Fix incorrect rewritting of function with typdefed type #436
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
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be9397f
Fix incorrect rewritting of function with typdefed type (fix #430)
john-h-kastner 71f3caf
comments
john-h-kastner abe0e17
add tests
john-h-kastner 29ace84
fix up comments
john-h-kastner 6c05f9d
Merge remote-tracking branch 'main' into fix_430
john-h-kastner 02c0b3b
Reconstruct a parameter declaration if we can't get its original source
mattmccutchen-cci ad9874a
Tweak matt's fix to pass two-file test case
john-h-kastner 65816d7
Merge branch 'main' into fix_430
john-h-kastner 05bda18
Update clang/lib/3C/DeclRewriter.cpp
john-h-kastner 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
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
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,37 @@ | ||
// RUN: rm -rf %t* | ||
// RUN: 3c -base-dir=%S -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s | ||
// RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s | ||
// RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - | ||
// RUN: 3c -base-dir=%S -output-dir=%t.checked -alltypes %s -- | ||
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/function_typedef.c -- | diff %t.checked/function_typedef.c - | ||
|
||
// Tests for the single file case in issue #430 | ||
// Functions declared using a typedef should be rewritten in a way that doesn't | ||
// crash 3C or generate uncompilable code. The expected output for these tests | ||
// is expected to change when issue #437 is resolved. | ||
|
||
typedef void foo(int*); | ||
foo foo_impl; | ||
void foo_imp(int *a) {}; | ||
//CHECK: foo foo_impl; | ||
//CHECK: void foo_imp(_Ptr<int> a) _Checked {}; | ||
|
||
typedef int *bar(); | ||
bar bar_impl; | ||
int *bar_impl() { | ||
return 0; | ||
}; | ||
//CHECK: _Ptr<int> bar_impl(void); | ||
//CHECK: _Ptr<int> bar_impl(void) _Checked { | ||
//CHECK: return 0; | ||
//CHECK: }; | ||
|
||
typedef int *baz(int *); | ||
baz baz_impl; | ||
int *baz_impl(int *a) { | ||
return 0; | ||
}; | ||
//CHECK: _Ptr<int> baz_impl(_Ptr<int> a); | ||
//CHECK: _Ptr<int> baz_impl(_Ptr<int> a) _Checked { | ||
//CHECK: return 0; | ||
//CHECK: }; |
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,13 @@ | ||
// RUN: rm -rf %t* | ||
// RUN: 3c -base-dir=%S -addcr -output-dir=%t.checked %S/function_typedef_multi.c %S/function_typedef_multi.h -- | ||
// RUN: test ! -f %t.checked/function_typedef_multi.h -a ! -f %t.checked/function_typedef_multi.c | ||
|
||
// Test for the two file case in issue #430 | ||
// This test caused an assertion to fail prior to PR #436 | ||
// This test uses function_typedef_multi.h. The header is deliberately not | ||
// included in this file. Including it prevented the assertion fail even | ||
// without the changes in PR #436. | ||
|
||
int foo(int a, int b[1]) { | ||
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,3 @@ | ||
// Used with function_typedef_multi.c | ||
typedef int a(int, int[1]); | ||
a foo; |
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,24 @@ | ||
// Test that if FunctionDeclBuilder::buildDeclVar cannot get the original source | ||
// for a parameter declaration due to a macro, it reconstructs the declaration | ||
// (including the name) instead of leaving a blank. | ||
|
||
// RUN: 3c -base-dir=%S %s -- | FileCheck -match-full-lines %s | ||
// RUN: 3c -base-dir=%S %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - | ||
|
||
// 3C is not idempotent on this file because the first pass constrains the | ||
// pointers in the macros to wild but then inlines the macros, so the second | ||
// pass will make those pointers checked. So don't try to test idempotence. | ||
|
||
typedef double mydouble; | ||
|
||
// TODO: FunctionDeclBuilder::buildDeclVar should be able to handle an itype | ||
// here, but currently the PointerConstraintVariable constructor asserts when it | ||
// fails to retrieve the original source of the itype declaration. | ||
#define parms1 volatile mydouble d, void (*f)(void) | ||
#define parms2 int *const y : count(7), _Ptr<char> z | ||
|
||
void test(parms1, int *x, parms2) {} | ||
// CHECK: void test(volatile mydouble d, void (*f)(void), _Ptr<int> x, int *const y : count(7), _Ptr<char> z) {} | ||
|
||
// Before the bug fix, we got: | ||
// void test(, , _Ptr<int> x, , ) {} |
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.
Uh oh!
There was an error while loading. Please reload this page.