Skip to content
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

[dnm] demonstrate that dead code hits assertions #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions gcassert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ func TestParseDirectives(t *testing.T) {
19: {directives: []assertDirective{bce, inline}},
},
"testdata/inline.go": {
45: {directives: []assertDirective{inline}},
49: {directives: []assertDirective{inline}},
51: {directives: []assertDirective{inline}},
55: {directives: []assertDirective{inline}},
57: {directives: []assertDirective{inline}},
58: {directives: []assertDirective{inline}},
46: {directives: []assertDirective{inline}},
50: {directives: []assertDirective{inline}},
52: {directives: []assertDirective{inline}},
56: {directives: []assertDirective{inline}},
59: {directives: []assertDirective{inline}},
61: {directives: []assertDirective{inline}},
63: {directives: []assertDirective{inline}},
},
"testdata/noescape.go": {
21: {directives: []assertDirective{noescape}},
Expand Down Expand Up @@ -90,11 +91,12 @@ testdata/noescape.go:44: : a escapes to heap:
testdata/bce.go:8: fmt.Println(ints[5]): Found IsInBounds
testdata/bce.go:17: sum += notInlinable(ints[i]): call was not inlined
testdata/bce.go:19: sum += notInlinable(ints[i]): call was not inlined
testdata/inline.go:45: alwaysInlined(3): call was not inlined
testdata/inline.go:51: sum += notInlinable(i): call was not inlined
testdata/inline.go:55: sum += 1: call was not inlined
testdata/inline.go:58: test(0).neverInlinedMethod(10): call was not inlined
testdata/inline.go:60: otherpkg.A{}.NeverInlined(sum): call was not inlined
testdata/inline.go:46: alwaysInlined(3): call was not inlined
testdata/inline.go:52: sum += notInlinable(i): call was not inlined
testdata/inline.go:56: sum += 1: call was not inlined
testdata/inline.go:61: test(0).alwaysInlinedMethod(): call was not inlined
testdata/inline.go:63: test(0).neverInlinedMethod(10): call was not inlined
testdata/inline.go:65: otherpkg.A{}.NeverInlined(sum): call was not inlined
`
assert.Equal(t, expectedOutput, w.String())
}
7 changes: 6 additions & 1 deletion testdata/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gcassert

import (
"fmt"
"math/bits"

"github.com/jordanlewis/gcassert/testdata/otherpkg"
)
Expand Down Expand Up @@ -54,7 +55,11 @@ func caller() {
// This assertion should fail as there's nothing to inline.
sum += 1 //gcassert:inline

sum += test(0).alwaysInlinedMethod()
if bits.UintSize == 64 {
sum += test(0).alwaysInlinedMethod()
} else {
sum -= test(0).alwaysInlinedMethod()
}
sum += test(0).neverInlinedMethod(10)

otherpkg.A{}.NeverInlined(sum)
Expand Down