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.
Generate itype string from AST when extracting from source fails (#693)
Fixes an assertion failure (#594) when attempting to extract the string representation of an itype expression from the original source code if the itype expression is inside a macro. The string representation for itypes in macros is now re-generated from the AST. The fix in its current form leads to some unnecessary expansion of macros. This is discussed in #694.
- Loading branch information
1 parent
fd4d8af
commit 07c5311
Showing
3 changed files
with
47 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 -alltypes -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null - | ||
// RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %s -- | ||
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/macro_itype.c -- | diff %t.checked/macro_itype.c - | ||
|
||
// Example encountered while converting libjpeg. This triggered an assertion | ||
// fail because the ItypeStr extracted from the source was empty. | ||
#define macro0 int *a : itype(_Ptr<int>); | ||
struct s { macro0 }; | ||
//CHECK: struct s { macro0 }; | ||
|
||
// Example from issue correctcomputation/checkedc-clang#594. | ||
#define PARAM_DECL_WITH_ITYPE int *p : itype(_Ptr<int>) | ||
void foo(PARAM_DECL_WITH_ITYPE); | ||
//CHECK: void foo(PARAM_DECL_WITH_ITYPE); | ||
|
||
// Just removing the assertion that failed on the above example caused this to | ||
// rewrite incorrectly. The ItypeStr would be left empty, so first parameter | ||
// would be rewritten to `int *b` even though the rewriter intended to give it | ||
// an itype. If the parameter was then passed a checked pointer, there would be | ||
// a Checked C compiler error. Ideally, 3C wouldn't need to change the | ||
// declaration of `b` at all (see issue correctcomputation/checkedc-clang#694). | ||
#define macro1 : itype(_Ptr<int>) | ||
void fn(int *b macro1, int *c) { | ||
//CHECK: void fn(int *b : itype(_Ptr<int>), _Ptr<int> c) { | ||
b = 1; | ||
} | ||
void caller() { | ||
int *e; | ||
//CHECK: _Ptr<int> e = ((void *)0); | ||
fn(e, 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