-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change fixes the compiler assert reported in Github issue #575. We are inserting temporary variables for strings so that we can describe their bounds. The assert was checking that we don't compute a temporary variable more than once in an expression. The problem was that we were copying an expression that creates and binds a temporary into the bounds. The bounds is used at runtime in the dynamic_bounds_cast. This causes the temporary to be computed twice, which is what the assert is protecting against. Since we've already computed the value into a temporary, the fix is to replace the binding with a read of the temporary. Testing: - Added simple repro case that caused a compiler crash. - Added a runtime test that will be covered by a PR to the Checked C repo - Passed testing locally for Window x64. - Passed automated testing for Linux.
- Loading branch information
Showing
3 changed files
with
48 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This is a regression test case for | ||
// https://github.com/Microsoft/checkedc-clang/issues/575 | ||
// | ||
// This test checks that the compiler does not crash on a dynamic bounds | ||
// cast whose argument is a string literal. | ||
// | ||
// RUN: %clang -cc1 -verify -fcheckedc-extension %s | ||
// expected-no-diagnostics | ||
|
||
int main(void) { | ||
_Nt_array_ptr<const char> str_with_len : count(2) = | ||
_Dynamic_bounds_cast<_Nt_array_ptr<const char>>(("\n"), count(2)); | ||
return 0; | ||
} |