Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for matching struct to compatible interface type on fct c…
…alls (#488)
- Loading branch information
1 parent
c3d782d
commit 9c6888b
Showing
17 changed files
with
217 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
1 change: 1 addition & 0 deletions
1
test/test-files/irgenerator/interfaces/success-interface-param-struct-match/cout.out
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 @@ | ||
Test |
71 changes: 71 additions & 0 deletions
71
test/test-files/irgenerator/interfaces/success-interface-param-struct-match/ir-code.ll
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,71 @@ | ||
; ModuleID = 'source.spice' | ||
source_filename = "source.spice" | ||
|
||
%struct.Test = type { %interface.ITest } | ||
%interface.ITest = type { ptr } | ||
|
||
$_ZTS5ITest = comdat any | ||
|
||
$_ZTI5ITest = comdat any | ||
|
||
$_ZTV5ITest = comdat any | ||
|
||
$_ZTS4Test = comdat any | ||
|
||
$_ZTI4Test = comdat any | ||
|
||
$_ZTV4Test = comdat any | ||
|
||
@_ZTS5ITest = dso_local constant [7 x i8] c"5ITest\00", comdat, align 1 | ||
@_ZTV8TypeInfo = external global ptr | ||
@_ZTI5ITest = dso_local constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTV8TypeInfo, i64 2), ptr @_ZTS5ITest }, comdat, align 8 | ||
@_ZTV5ITest = dso_local unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI5ITest, ptr null] }, comdat, align 8 | ||
@_ZTS4Test = dso_local constant [6 x i8] c"4Test\00", comdat, align 1 | ||
@_ZTI4Test = dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTV8TypeInfo, i64 2), ptr @_ZTS4Test, ptr @_ZTI5ITest }, comdat, align 8 | ||
@_ZTV4Test = dso_local unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI4Test, ptr @_ZN4Test4testEv] }, comdat, align 8 | ||
@printf.str.0 = private unnamed_addr constant [5 x i8] c"Test\00", align 1 | ||
|
||
define private void @_ZN4Test4ctorEv(ptr noundef nonnull align 8 dereferenceable(8) %0) { | ||
%this = alloca ptr, align 8 | ||
store ptr %0, ptr %this, align 8 | ||
%2 = load ptr, ptr %this, align 8 | ||
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV4Test, i32 0, i32 0, i32 2), ptr %2, align 8 | ||
ret void | ||
} | ||
|
||
define private void @_ZN4Test4testEv(ptr noundef nonnull align 8 dereferenceable(8) %0) { | ||
%this = alloca ptr, align 8 | ||
store ptr %0, ptr %this, align 8 | ||
%2 = call i32 (ptr, ...) @printf(ptr noundef @printf.str.0) | ||
ret void | ||
} | ||
|
||
; Function Attrs: nofree nounwind | ||
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) #0 | ||
|
||
define private void @_Z7testFctR5ITest(ptr %0) { | ||
%test = alloca ptr, align 8 | ||
store ptr %0, ptr %test, align 8 | ||
%2 = load ptr, ptr %test, align 8 | ||
%vtable.addr = load ptr, ptr %2, align 8 | ||
%vfct.addr = getelementptr inbounds ptr, ptr %vtable.addr, i64 0 | ||
%fct = load ptr, ptr %vfct.addr, align 8 | ||
call void %fct(ptr noundef nonnull align 8 dereferenceable(8) %2) | ||
ret void | ||
} | ||
|
||
; Function Attrs: noinline nounwind optnone uwtable | ||
define dso_local i32 @main() #1 { | ||
%result = alloca i32, align 4 | ||
%test = alloca %struct.Test, align 8 | ||
%itest = alloca ptr, align 8 | ||
store i32 0, ptr %result, align 4 | ||
call void @_ZN4Test4ctorEv(ptr noundef nonnull align 8 dereferenceable(8) %test) | ||
store ptr %test, ptr %itest, align 8 | ||
%1 = load ptr, ptr %itest, align 8 | ||
call void @_Z7testFctR5ITest(ptr %1) | ||
ret i32 0 | ||
} | ||
|
||
attributes #0 = { nofree nounwind } | ||
attributes #1 = { noinline nounwind optnone uwtable } |
22 changes: 22 additions & 0 deletions
22
test/test-files/irgenerator/interfaces/success-interface-param-struct-match/source.spice
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,22 @@ | ||
type ITest interface { | ||
p test(); | ||
} | ||
|
||
type Test struct : ITest {} | ||
|
||
p Test.ctor() {} | ||
|
||
p Test.test() { | ||
printf("Test"); | ||
} | ||
|
||
p testFct(ITest& test) { | ||
test.test(); | ||
} | ||
|
||
f<int> main() { | ||
Test test = Test(); | ||
ITest& itest = test; | ||
testFct(itest); | ||
return 0; | ||
} |
8 changes: 8 additions & 0 deletions
8
test/test-files/typechecker/function-pointers/error-generic-param-types/exception.out
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 @@ | ||
[Error|Compiler]: | ||
Unresolved soft errors: There are unresolved errors. Please fix them and recompile. | ||
|
||
[Error|Semantic] ./source.spice:8:21: | ||
Referenced overloaded function: Generic functions cannot be referenced | ||
|
||
8 p(const T&) s = test; | ||
^^^^ |
10 changes: 10 additions & 0 deletions
10
test/test-files/typechecker/function-pointers/error-generic-param-types/source.spice
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 @@ | ||
type T dyn; | ||
|
||
p test<T>(const T& t) { | ||
printf("%d\n", t); | ||
} | ||
|
||
f<int> main() { | ||
p(const T&) s = test; | ||
s(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
5 changes: 0 additions & 5 deletions
5
test/test-files/typechecker/references/error-immediate-without-const/exception.out
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test/test-files/typechecker/references/error-immediate-without-const/source.spice
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
test/test-files/typechecker/variables/error-temporary-to-non-const-ref/exception.out
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,5 +1,5 @@ | ||
[Error|Semantic] ./source.spice:2:5: | ||
Temporary bound to non-const reference: Temporary values can only be bound to const reference parameters | ||
Temporary bound to non-const reference: Temporary values can only be bound to const reference variables/fields | ||
|
||
2 int& i = 123; | ||
^^^^^^^^^^^^ |