-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compiler assert about bounds expression already existing. (#537)
The children() method for iterating over chidren of AST cast expressions was incorrectly including compiler-generated bounds expressions. Child AST nodes should be nodes that appear in the source program and additional information shouldn't be treated as child nodes. There were complex IR invariants about when a bounds expression stored within a cast expression was child AST node or not. This change fixes the bug and simplifies the AST invariants. This fixes issue #526. for cast expressions, there is now one entry for bounds expressions declared as part of the program. There are separate nodes for normalized bounds and inferred bounds. Testing: - Added a new regression test case for the failing case. - Passes existing Checked C and clang Checked C tests.
- Loading branch information
Showing
6 changed files
with
68 additions
and
40 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
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,29 @@ | ||
// | ||
// This is a regression test case for | ||
// https://github.com/Microsoft/checkedc-clang/issues/526 | ||
// | ||
// The compiler was crashing with an internal assertion that an expression | ||
// to which a bounds check was going to be added already had a bounds | ||
// check. | ||
// | ||
// The problem is that the compiler was traversing the 1st argument of a | ||
// _Dynamic_bounds_cast operation twice. The compiler inferred bounds | ||
// that use the 1st argument. It then attached them to the AST. There | ||
// was a lack of clarity in the IR and the inferred bounds were also | ||
// traversed, causing the assert. | ||
// | ||
// RUN: %clang -cc1 -verify %s | ||
// expected-no-diagnostics | ||
|
||
struct obj { | ||
_Array_ptr<_Nt_array_ptr<char>> names : count(len); | ||
unsigned int len; | ||
}; | ||
|
||
void f(const struct obj *object ) { | ||
unsigned int i = 0; | ||
_Nt_array_ptr<const char> t : count(0) = | ||
_Dynamic_bounds_cast<_Nt_array_ptr<const char>>(object->names[i], | ||
count(0)); | ||
} | ||
|