Bug 9134 – failed assert leads to Segmentation fault when iterating file lines

Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-12-10T01:59:00Z
Last change time
2013-03-01T12:31:47Z
Assigned to
nobody
Creator
atankeev

Comments

Comment #0 by atankeev — 2012-12-10T01:59:35Z
---{ cut: testcase.d }--- import std.stdio; void main() { auto file = File("testcase.d","r"); foreach (ulong i, string line; lines(file)) assert(true == false); // Segmentation fault (core dumped) file.close(); } ---------{ EOF }--------- # rdmd testcase.d Segmentation fault (core dumped)
Comment #1 by maxim — 2012-12-10T07:21:12Z
Note: if it is compiled with -g, an AssertError is thrown.
Comment #2 by maximechevalierb — 2013-03-01T08:25:40Z
I ran into this bug as well. Adding the -g compiler option does not fix the problem for me.
Comment #3 by maximechevalierb — 2013-03-01T08:40:55Z
I have a hunch that this might be because the function with the assert is called from a function with the extern (C) calling convention. Possibly, DMD tries to unwind the stack and fails when it gets to the function with the C calling convention...
Comment #4 by maxim — 2013-03-01T09:18:23Z
I cannot it reproduce with g(In reply to comment #2) > I ran into this bug as well. Adding the -g compiler option does not fix the > problem for me. Which environment do you use? I cannot reproduce it now with 2.062 on windows and linux git head.
Comment #5 by maximechevalierb — 2013-03-01T11:35:53Z
(In reply to comment #4) > I cannot it reproduce with g(In reply to comment #2) > > I ran into this bug as well. Adding the -g compiler option does not fix the > > problem for me. > > Which environment do you use? I cannot reproduce it now with 2.062 on windows > and linux git head. DMD64 D Compiler v2.062 on Ubuntu 64 bit. assert (false); causes a segmentation fault. I believe the problem might be that this assert is in a function that is indirectly called by a function with the extern (C) calling convention. The problem is further complicated because I call this function from x86 assembler code I wrote myself. I'm guessing the stack unwinding mechanism has a heart attack when it gets to that point in the stack.
Comment #6 by maxim — 2013-03-01T11:45:18Z
(In reply to comment #5) > (In reply to comment #4) > > I cannot it reproduce with g(In reply to comment #2) > > > I ran into this bug as well. Adding the -g compiler option does not fix the > > > problem for me. > > > > Which environment do you use? I cannot reproduce it now with 2.062 on windows > > and linux git head. > > DMD64 D Compiler v2.062 on Ubuntu 64 bit. > > assert (false); causes a segmentation fault. I believe the problem might be > that this assert is in a function that is indirectly called by a function with > the extern (C) calling convention. The problem is further complicated because I > call this function from x86 assembler code I wrote myself. I'm guessing the > stack unwinding mechanism has a heart attack when it gets to that point in the > stack. OK. I can successfully run following code (with assertion failure, of course): import std.stdio; void main() { auto file = File("testcase.d","r"); foreach (ulong i, string line; lines(file)) assert(false); // Segmentation fault (core dumped) file.close(); } without any switches using githead. The fact that you are facing bug my be because it is already fixed in head. Can you test master branch? If there are no objections, I will close issue as WORKSFORME.
Comment #7 by atankeev — 2013-03-01T11:53:16Z
In 2.062 it can be reproduced if you compile this code with -release flag.
Comment #8 by maxim — 2013-03-01T11:59:50Z
(In reply to comment #7) > In 2.062 it can be reproduced if you compile this code with -release flag. It can be reproduced in any version with -release flag since assertion on constant CT zero expression results in halt instruction.
Comment #9 by atankeev — 2013-03-01T12:13:45Z
It crashes only with Ubuntu Linux 12.10, dmd64. Under win32 it works fine. Interesting that even such code crashes with dmd64 2.062/linux and -release flag: void main() { assert(false); } > It can be reproduced in any version with -release flag since assertion on constant CT zero expression results in halt instruction. No. In win32 I have just an exception and in linux I have segmentation fault. Should I explain why is it unacceptable behavior?
Comment #10 by atankeev — 2013-03-01T12:27:58Z
Comment #11 by atankeev — 2013-03-01T12:31:47Z
*** This issue has been marked as a duplicate of issue 5517 ***