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

semfold bug with negative value * 0 #12783

Closed
mratsim opened this issue Dec 1, 2019 · 3 comments
Closed

semfold bug with negative value * 0 #12783

mratsim opened this issue Dec 1, 2019 · 3 comments

Comments

@mratsim
Copy link
Collaborator

mratsim commented Dec 1, 2019

Test

let a = -1 * 0

Crashes with

fatal.nim(39)            sysFatal
Error: unhandled exception: int128.nim(383, 11) `false` overflow [AssertionError]

Stack trace

.../Nim/compiler/nim.nim(106) nim
.../Nim/compiler/nim.nim(83) handleCmdLine
.../Nim/compiler/cmdlinehelper.nim(98) loadConfigsAndRunMainCommand
.../Nim/compiler/main.nim(188) mainCommand
.../Nim/compiler/main.nim(92) commandCompileToC
.../Nim/compiler/modules.nim(144) compileProject
.../Nim/compiler/modules.nim(85) compileModule
.../Nim/compiler/passes.nim(213) processModule
.../Nim/compiler/passes.nim(86) processTopLevelStmt
.../Nim/compiler/sem.nim(600) myProcess
.../Nim/compiler/sem.nim(568) semStmtAndGenerateGenerics
.../Nim/compiler/semstmts.nim(2214) semStmt
.../Nim/compiler/semexprs.nim(986) semExprNoType
.../Nim/compiler/semexprs.nim(2758) semExpr
.../Nim/compiler/semstmts.nim(1990) semProc
.../Nim/compiler/semstmts.nim(1910) semProcAux
.../Nim/compiler/semexprs.nim(1744) semProcBody
.../Nim/compiler/semexprs.nim(2740) semExpr
.../Nim/compiler/semstmts.nim(2154) semStmtList
.../Nim/compiler/semexprs.nim(2718) semExpr
.../Nim/compiler/semstmts.nim(164) semIf
.../Nim/compiler/semstmts.nim(104) semExprBranch
.../Nim/compiler/semexprs.nim(2740) semExpr
.../Nim/compiler/semstmts.nim(2154) semStmtList
.../Nim/compiler/semexprs.nim(2750) semExpr
.../Nim/compiler/semstmts.nim(881) semFor
.../Nim/compiler/semstmts.nim(762) semForVars
.../Nim/compiler/semstmts.nim(104) semExprBranch
.../Nim/compiler/semexprs.nim(2740) semExpr
.../Nim/compiler/semstmts.nim(2154) semStmtList
.../Nim/compiler/semexprs.nim(2738) semExpr
.../Nim/compiler/semexprs.nim(1696) semAsgn
.../Nim/compiler/semexprs.nim(64) semExprWithType
.../Nim/compiler/semexprs.nim(2637) semExpr
.../Nim/compiler/semexprs.nim(968) semDirectOp
.../Nim/compiler/semexprs.nim(861) afterCallActions
.../Nim/compiler/semexprs.nim(34) semTemplateExpr
.../Nim/compiler/sem.nim(441) semAfterMacroCall
.../Nim/compiler/semexprs.nim(2740) semExpr
.../Nim/compiler/semstmts.nim(2154) semStmtList
.../Nim/compiler/semexprs.nim(2662) semExpr
.../Nim/compiler/semexprs.nim(967) semDirectOp
.../Nim/compiler/semexprs.nim(816) semOverloadedCallAnalyseEffects
.../Nim/compiler/semcall.nim(532) semOverloadedCall
.../Nim/compiler/semcall.nim(335) resolveOverloads
.../Nim/compiler/semcall.nim(93) pickBestCandidate
.../Nim/compiler/sigmatch.nim(2520) matches
.../Nim/compiler/sigmatch.nim(2457) matchesAux
.../Nim/compiler/sigmatch.nim(2259) prepareOperand
.../Nim/compiler/semexprs.nim(49) semOperand
.../Nim/compiler/semexprs.nim(2662) semExpr
.../Nim/compiler/semexprs.nim(967) semDirectOp
.../Nim/compiler/semexprs.nim(816) semOverloadedCallAnalyseEffects
.../Nim/compiler/semcall.nim(532) semOverloadedCall
.../Nim/compiler/semcall.nim(335) resolveOverloads
.../Nim/compiler/semcall.nim(93) pickBestCandidate
.../Nim/compiler/sigmatch.nim(2520) matches
.../Nim/compiler/sigmatch.nim(2457) matchesAux
.../Nim/compiler/sigmatch.nim(2259) prepareOperand
.../Nim/compiler/semexprs.nim(49) semOperand
.../Nim/compiler/semexprs.nim(2662) semExpr
.../Nim/compiler/semexprs.nim(968) semDirectOp
.../Nim/compiler/semexprs.nim(875) afterCallActions
.../Nim/compiler/semexprs.nim(735) evalAtCompileTime
.../Nim/compiler/semfold.nim(661) getConstExpr
.../Nim/compiler/semfold.nim(417) magicCall
.../Nim/compiler/semfold.nim(207) evalOp
.../Nim/compiler/semfold.nim(93) foldMul
.../Nim/compiler/int128.nim(383) *
.../Nim/lib/system/assertions.nim(27) failedAssertImpl
.../Nim/lib/system/assertions.nim(20) raiseAssert
.../Nim/lib/system/fatal.nim(39) sysFatal
Error: unhandled exception: .../Nim/compiler/int128.nim(383, 11) `false` overflow [AssertionError]
FAILURE

Tagging high-priority because it's hard to workaround, you need to insert indirections so that the compiler doesn't semfold

@mratsim mratsim added Severe VM see also `const` label Compiler Crash labels Dec 1, 2019
@Araq
Copy link
Member

Araq commented Dec 3, 2019

This is ridiculous and makes me want to throw away int128...

@cooldome
Copy link
Member

cooldome commented Dec 3, 2019

Looks like it is just incorrect assert

@mratsim
Copy link
Collaborator Author

mratsim commented Dec 3, 2019

Yes one fix would be to shortcut if one operand is zero.

I agree it's very annoying, but looking into the code it seems like a honest mistake.
Having no asserts would be worse because we wouldn't even understand the original assumptions.

cooldome added a commit to cooldome/Nim that referenced this issue Dec 4, 2019
@Araq Araq closed this as completed in 9b0e874 Dec 5, 2019
narimiran pushed a commit to narimiran/Nim that referenced this issue Dec 10, 2019
* fixes nim-lang#12783

* Trigger build

(cherry picked from commit 9b0e874)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants