forked from chapel-lang/chapel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checks when default intents allow indirect modification (chapel-l…
…ang#23952) [reviewed by @mppf] Similar to chapel-lang#23885, this causes the blank intent to generate warnings when the actual argument intent ends up being `const ref` because of the argument's type. <details> I moved the `unstable` check during resolveIntents into the now-renamed function so that it was sharable by both checks instead of duplicated. Thankfully, the warning message was general enough that I didn't need any specialization for it in the blank intent case. </details> There were additional changes needed to fix some issues pointed out by valgrind with the check in general (regardless of if the `const` intent or default intent was used). Specifically records, strings, and some iterators were causing warnings about accessing uninitialized memory. To rectify that, explicitly zero the memory in these cases but only when the check will be inserted. Will look into warning for arrays passed by default/const intent when the domain is changed indirectly next Modified the blank intent test for the new expected output. Added several tests while locking down exactly what was triggering the valgrind failures. Passed a full paratest with futures and a full valgrindexe run.
- Loading branch information
Showing
18 changed files
with
200 additions
and
54 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
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,17 @@ | ||
record Foo { | ||
var x: [0..3] int; | ||
} | ||
|
||
var arr = [2, 4, 6, 2]; | ||
var globalFoo = new Foo(arr); | ||
|
||
proc takesAFoo(const arg: Foo) { | ||
writeln(arg); | ||
// Won't trigger the warning | ||
globalFoo.x[2] = 7; | ||
writeln(arg); | ||
} | ||
|
||
proc main() { | ||
takesAFoo(globalFoo); | ||
} |
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,2 @@ | ||
(x = 2 4 6 2) | ||
(x = 2 4 7 2) |
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,16 @@ | ||
record Foo { | ||
var x: bool = false; | ||
} | ||
|
||
var globalFoo = new Foo(true); | ||
|
||
proc takesAFoo(const arg: Foo) { | ||
writeln(arg); | ||
// This should trigger the warning, but not on this line number | ||
globalFoo.x = false; | ||
writeln(arg); | ||
} | ||
|
||
proc main() { | ||
takesAFoo(globalFoo); | ||
} |
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,4 @@ | ||
(x = true) | ||
(x = false) | ||
boolField.chpl:7: warning: The argument 'arg' was modified indirectly during this function, this behavior is unstable and may change in the future. | ||
If this behavior is intentional, declaring the argument as 'const ref' will silence this warning. If not, declaring the argument as 'const in' will prevent indirect modifications |
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,16 @@ | ||
record Foo { | ||
var x: bool; | ||
} | ||
|
||
var globalFoo = new Foo(true); | ||
|
||
proc takesAFoo(const arg: Foo) { | ||
writeln(arg); | ||
// This should trigger the warning, but not on this line number | ||
globalFoo.x = false; | ||
writeln(arg); | ||
} | ||
|
||
proc main() { | ||
takesAFoo(globalFoo); | ||
} |
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,4 @@ | ||
(x = true) | ||
(x = false) | ||
boolFieldNoDefaultValue.chpl:7: warning: The argument 'arg' was modified indirectly during this function, this behavior is unstable and may change in the future. | ||
If this behavior is intentional, declaring the argument as 'const ref' will silence this warning. If not, declaring the argument as 'const in' will prevent indirect modifications |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
(x = 15) | ||
(x = 3) | ||
defaultIntentMod.chpl:7: warning: The argument 'r' was modified indirectly during this function, this behavior is unstable and may change in the future. | ||
If this behavior is intentional, declaring the argument as 'const ref' will silence this warning. If not, declaring the argument as 'const in' will prevent indirect modifications |
20 changes: 20 additions & 0 deletions
20
test/unstable/const-intent/recordWithRecordFieldWithBoolField.chpl
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,20 @@ | ||
record Bar { | ||
var x: bool = false; | ||
} | ||
|
||
record Foo { | ||
var x: Bar; | ||
} | ||
|
||
var globalFoo = new Foo(new Bar(true)); | ||
|
||
proc takesAFoo(const arg: Foo) { | ||
writeln(arg); | ||
// This should trigger the warning, but not on this line number | ||
globalFoo.x.x = false; | ||
writeln(arg); | ||
} | ||
|
||
proc main() { | ||
takesAFoo(globalFoo); | ||
} |
4 changes: 4 additions & 0 deletions
4
test/unstable/const-intent/recordWithRecordFieldWithBoolField.good
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,4 @@ | ||
(x = (x = true)) | ||
(x = (x = false)) | ||
recordWithRecordFieldWithBoolField.chpl:11: warning: The argument 'arg' was modified indirectly during this function, this behavior is unstable and may change in the future. | ||
If this behavior is intentional, declaring the argument as 'const ref' will silence this warning. If not, declaring the argument as 'const in' will prevent indirect modifications |
21 changes: 21 additions & 0 deletions
21
test/unstable/const-intent/recordWithRecordFieldWithLaterBoolField.chpl
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,21 @@ | ||
record Bar { | ||
var w: int = 5; | ||
var x: bool; | ||
} | ||
|
||
record Foo { | ||
var x: Bar; | ||
} | ||
|
||
var globalFoo = new Foo(new Bar(3, true)); | ||
|
||
proc takesAFoo(const arg: Foo) { | ||
writeln(arg); | ||
// This should trigger the warning, but not on this line number | ||
globalFoo.x.x = false; | ||
writeln(arg); | ||
} | ||
|
||
proc main() { | ||
takesAFoo(globalFoo); | ||
} |
4 changes: 4 additions & 0 deletions
4
test/unstable/const-intent/recordWithRecordFieldWithLaterBoolField.good
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,4 @@ | ||
(x = (w = 3, x = true)) | ||
(x = (w = 3, x = false)) | ||
recordWithRecordFieldWithLaterBoolField.chpl:12: warning: The argument 'arg' was modified indirectly during this function, this behavior is unstable and may change in the future. | ||
If this behavior is intentional, declaring the argument as 'const ref' will silence this warning. If not, declaring the argument as 'const in' will prevent indirect modifications |