Skip to content

fixes #24974; SIGSEGV when raising Defect/doAssert #24985

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 1 commit into from
Jun 10, 2025
Merged

fixes #24974; SIGSEGV when raising Defect/doAssert #24985

merged 1 commit into from
Jun 10, 2025

Conversation

ringabout
Copy link
Member

fixes #24974

requires result initializations when encountering unreachable code (e.g. quit)

@@ -1234,7 +1234,9 @@ proc allPathsAsgnResult(p: BProc; n: PNode): InitResultEnum =
else:
allPathsInBranch(n[i].lastSon)
of nkCallKinds:
if canRaiseDisp(p, n[0]):
if canRaiseDisp(p, n[0]) or
(n[0].kind == nkSym and sfNoReturn in n[0].sym.flags):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there can be calls that don't return that are not marked as noreturn.

Copy link
Member Author

@ringabout ringabout Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other cases are already covered by canRaiseDisp, which is quite conservative about functions that never raises. In general, only functions in the system can be exempt from this checking. Otherwise, we have systemRaisesDefect for functions in the system

e.g.

proc `[]`*[T](s: openArray[T]; i: BackwardsIndex): T {.inline, systemRaisesDefect.} =
  system.`[]`(s, s.len - int(i))

We can treat noreturn function calls consistently as result must be initialized in these cases

@Araq Araq merged commit 638a8bf into devel Jun 10, 2025
21 checks passed
@Araq Araq deleted the pr_cgen_f branch June 10, 2025 12:12
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 638a8bf

Hint: mm: orc; opt: speed; options: -d:release
182715 lines; 9.401s; 659.359MiB peakmem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SIGSEGV when raising Defect/doAssert
2 participants