forked from checkedc/checkedc-clang
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) Fixes a error in rewriting for function declaration such as typedef void foo(int*); foo bar; void bar(int *a){}; Previously `FunctionDeclBuilder` only replaced the parameter declaration of `bar` because nothing in the return type needed to be rewritten. This caused the rewriting of the first declaration to be missing the return type. With this change, `FunctionDeclBuilder` detects that `bar` is declared using a typedef type, and generates replacement text for the entire declaration instead of only the parameter list. This change does not implement proper constraint generation for these function, so the typedef foo is not rewritten. Reconstruct a parameter declaration if we can't get its original source due to a macro. Co-authored-by: Matt McCutchen (Correct Computation) <[email protected]>
- Loading branch information
1 parent
e101e89
commit ca9a08c
Showing
8 changed files
with
177 additions
and
26 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
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 |
---|---|---|
@@ -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 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 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 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, , ) {} |