-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CT sizeof(+friends) for {.importc, completeStruct.} types, enable ABI static checks #13926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2d00cd9
-d:checkabi obsolete (ABI check now enforced); add `addTypeHeader` he…
timotheecour 7d06ee5
add test
timotheecour d0c457a
add test
timotheecour fc79122
works
timotheecour 5c7e164
works
timotheecour 5ea8483
fix dups
timotheecour 2dc4432
cleanups
timotheecour 1efe7b0
cleanups
timotheecour 6d14346
import sizeof at CT for {.completeType.}
timotheecour 606d61a
fixups
timotheecour ac90c1a
aftermath
timotheecour eb3ac47
address comments; revert default enabling of -d:checkAbi for now
timotheecour c8292d7
mimportc_size_check.nim => msizeof5.nim; merge mabi_check.nim into ms…
timotheecour 27f69dd
all pragmas in errmsgs should be written: '.importc' (un-ambiguous an…
timotheecour ec0fc8f
revert changes to stdlib related to fixes for -d:checkAbi (deferred t…
timotheecour 691e2b1
fixup
timotheecour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
| ## tests for -d:checkAbi used by addAbiCheck via NIM_STATIC_ASSERT | ||
|
|
||
| {.emit:"""/*TYPESECTION*/ | ||
| struct Foo1{ | ||
| int a; | ||
| }; | ||
| struct Foo2{ | ||
| int a; | ||
| }; | ||
| enum Foo3{k1, k2}; | ||
| typedef enum Foo3 Foo3b; | ||
| typedef enum Foo4{k3, k4} Foo4; | ||
|
|
||
| typedef int Foo5[3]; | ||
|
|
||
| typedef struct Foo6{ | ||
| int a1; | ||
| bool a2; | ||
| double a3; | ||
| struct Foo6* a4; | ||
| } Foo6; | ||
| """.} | ||
|
|
||
| template ensureCgen(T: typedesc) = | ||
| ## ensures cgen | ||
| var a {.volatile.}: T | ||
|
|
||
| block: | ||
| type Foo1Alias{.importc: "struct Foo1", size: sizeof(cint).} = object | ||
| a: cint | ||
| ensureCgen Foo1Alias | ||
|
|
||
| block: | ||
| type Foo3Alias{.importc: "enum Foo3", size: sizeof(cint).} = enum | ||
| k1, k2 | ||
| ensureCgen Foo3Alias | ||
|
|
||
| block: | ||
| type Foo3bAlias{.importc: "Foo3b", size: sizeof(cint).} = enum | ||
| k1, k2 | ||
| ensureCgen Foo3bAlias | ||
|
|
||
| block: | ||
| type Foo3b{.importc, size: sizeof(cint).} = enum | ||
| k1, k2 | ||
| ensureCgen Foo3b | ||
| static: | ||
| doAssert Foo3b.sizeof == cint.sizeof | ||
|
|
||
| block: | ||
| type Foo4{.importc, size: sizeof(cint).} = enum | ||
| k3, k4 | ||
| # adding entries should not yield duplicate ABI checks, as enforced by | ||
| # `typeABICache`. | ||
| # Currently the test doesn't check for this but you can inspect the cgen'd file | ||
| ensureCgen Foo4 | ||
| ensureCgen Foo4 | ||
| ensureCgen Foo4 | ||
|
|
||
| block: | ||
| type Foo5{.importc.} = array[3, cint] | ||
| ensureCgen Foo5 | ||
|
|
||
| block: | ||
| type Foo5{.importc.} = array[3, cint] | ||
| ensureCgen Foo5 | ||
|
|
||
| block: # CT sizeof | ||
| type Foo6GT = object # grountruth | ||
| a1: cint | ||
| a2: bool | ||
| a3: cfloat | ||
| a4: ptr Foo6GT | ||
|
|
||
| type Foo6{.importc, completeStruct.} = object | ||
| a1: cint | ||
| a2: bool | ||
| a3: cfloat | ||
| a4: ptr Foo6 | ||
|
|
||
| static: doAssert compiles(static(Foo6.sizeof)) | ||
| static: doAssert Foo6.sizeof == Foo6GT.sizeof | ||
| static: doAssert (Foo6, int, array[2, Foo6]).sizeof == | ||
| (Foo6GT, int, array[2, Foo6GT]).sizeof | ||
|
|
||
| block: | ||
| type GoodImportcType {.importc: "signed char", nodecl.} = char | ||
| # "good" in sense the sizeof will match | ||
| ensureCgen GoodImportcType | ||
|
|
||
| block: | ||
| type Foo6{.importc.} = object | ||
| a1: cint | ||
| doAssert compiles(Foo6.sizeof) | ||
| static: doAssert not compiles(static(Foo6.sizeof)) | ||
|
|
||
| when defined caseBad: | ||
| # Each case below should give a static cgen assert fail message | ||
|
|
||
| block: | ||
| type BadImportcType {.importc: "unsigned char", nodecl.} = uint64 | ||
| # "sizeof" check will fail | ||
| ensureCgen BadImportcType | ||
|
|
||
| block: | ||
| type Foo2AliasBad{.importc: "struct Foo2", size: 1.} = object | ||
| a: cint | ||
| ensureCgen Foo2AliasBad | ||
|
|
||
| block: | ||
| type Foo5{.importc.} = array[4, cint] | ||
| ensureCgen Foo5 | ||
|
|
||
| block: | ||
| type Foo5{.importc.} = array[3, bool] | ||
| ensureCgen Foo5 | ||
|
|
||
| block: | ||
| type Foo6{.importc, completeStruct.} = object | ||
| a1: cint | ||
| # a2: bool # missing this should trigger assert fail | ||
| a3: cfloat | ||
| a4: ptr Foo6 | ||
| ensureCgen Foo6 | ||
|
|
||
| when false: | ||
| block: | ||
| # pre-existing BUG: this should give a CT error in semcheck because `size` | ||
| # disagrees with `array[3, cint]` | ||
| type Foo5{.importc, size: 1.} = array[3, cint] | ||
| ensureCgen Foo5 |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.