-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAPHNE-#595] Fix crash when using UDF with zero results where one va…
…lue is needed (#605) The core issue is that DaphneDSL UDFs without return value internally returned an invalid mlir::Value. Upon doing anything with this value (i.e., when using it in a context where exactly one value is expected, e.g., in expressions or in assignments), the program would crash (e.g., accessing any fields or calling any methods). Now we return nullptr as the result of a UDF with zero return values in visitCallExpr(). This nullptr is detected in valueOrError(), a helper function we anyway call everywhere in the DaphneDSL parser when a single value is needed, and causes an exception to be thrown The error message is not informative yet ("[error]: While parsing: something was expected to be an mlir::Value, but it was none"), but this will be improved in a follow-up commit. Added several script-level test cases, which check that DAPHNE does not accept UDFs with zero or more than one return value in places where exactly one value is expected. All of these tests on a UDF with zero return values used to crash DAPHNE with a segfault (#595 was not specific to call expressions). Actually, these are just a few examples, ideally we should have test cases for all uses of expr in the DaphneDSL grammar. Closes #595. --------- Co-authored-by: Patrick Damme <[email protected]>
- Loading branch information
1 parent
5a47688
commit 3e56ed5
Showing
20 changed files
with
163 additions
and
47 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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// invalid number of results (expecting 1, getting 2) | ||
// invalid number of results when used in assignment statement (expecting 2, getting 3) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
def f(a:si64) -> si64, si64, si64 { | ||
return a + 1, a + 2, a + 3; | ||
} | ||
|
||
x = f(123); | ||
print(x); | ||
x, y = f(123); | ||
print(x); | ||
print(y); |
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,14 +1,8 @@ | ||
// overloading typed functions with different number of results, but same arguments | ||
// invalid number of results when used in assignment statement (expecting 1, getting 0) | ||
|
||
def f(a:si64) -> si64 { | ||
return a + 1; | ||
} | ||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
x = f(100); | ||
print(x); | ||
y, z, = f(200); | ||
print(y); | ||
print(z); | ||
x = f(123); | ||
print(x); |
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,8 @@ | ||
// invalid number of results when used in assignment statement (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
x = f(123); | ||
print(x); |
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,7 @@ | ||
// invalid number of results when used in call expression (expecting 1, getting 0) | ||
|
||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
print(f(123)); |
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,7 @@ | ||
// invalid number of results when used in call expression (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
print(f(123)); |
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,8 @@ | ||
// invalid number of results when used with binary operator (expecting 1, getting 0) | ||
|
||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
x = f(123) + 1; | ||
print(x); |
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,8 @@ | ||
// invalid number of results when used with binary operator (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
x = f(123) + 1; | ||
print(x); |
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,8 @@ | ||
// invalid number of results when used in matrix literal (expecting 1, getting 0) | ||
|
||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
x = [f(123)]; | ||
print(x); |
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,8 @@ | ||
// invalid number of results when used in matrix literal (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
x = [f(123)]; | ||
print(x); |
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,10 @@ | ||
// invalid number of results when used in if-statement (expecting 1, getting 0) | ||
|
||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
if(f(123)) | ||
print("yes"); | ||
else | ||
print("no"); |
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,10 @@ | ||
// invalid number of results when used in if-statement (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
if(f(123)) | ||
print("yes"); | ||
else | ||
print("no"); |
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,8 @@ | ||
// invalid number of results when used in while-statement (expecting 1, getting 0) | ||
|
||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
while(f(123)) | ||
print("abc"); |
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,8 @@ | ||
// invalid number of results when used in while-statement (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
while(f(123)) | ||
print("abc"); |
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,12 @@ | ||
// invalid number of results when used in return-statement (expecting 1, getting 0) | ||
|
||
def f(a:si64) { | ||
return; | ||
} | ||
|
||
def g() -> si64 { | ||
return f(123); | ||
} | ||
|
||
x = g(); | ||
print(x); |
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,12 @@ | ||
// invalid number of results when used in return-statement (expecting 1, getting 2) | ||
|
||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
def g() -> si64 { | ||
return f(123); | ||
} | ||
|
||
x = g(); | ||
print(x); |
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 @@ | ||
// overloading typed functions with different number of results, but same arguments | ||
|
||
def f(a:si64) -> si64 { | ||
return a + 1; | ||
} | ||
def f(a:si64) -> si64, si64 { | ||
return a + 1, a + 2; | ||
} | ||
|
||
x = f(100); | ||
print(x); | ||
y, z, = f(200); | ||
print(y); | ||
print(z); |
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