Skip to content

Segfault when if statement pattern variable name is reused in a later scope #51091

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

Closed
Mike278 opened this issue Jan 21, 2023 · 0 comments
Closed
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@Mike278
Copy link

Mike278 commented Jan 21, 2023

Obviously these features are still WIP, but just logging another crash I came across in case it's helpful.

void main() {
  if (0 case var x) {
    print(x);
  }
  var x = 1;
  print(x);
}

This crashes with:

Full stack trace
$ dart-sdk/bin/dart --enable-experiment=records,patterns bug.dart

===== CRASH =====
si_signo=Segmentation fault(11), si_code=1, si_addr=0x18
version=3.0.0-edge.ba8f0bd947c613013ed4659ea44da851bf35a99f (be) (Sat Jan 21 01:02:49 2023 +0000) on "linux_x64"
pid=223, thread=230, isolate_group=main(0x5562f5cc2000), isolate=(nil)((nil))
os=linux, arch=x64, comp=no, sim=no
isolate_instructions=5562f3201080, vm_instructions=5562f3201080
fp=7fe9be27c150, sp=7fe9be27c0e0, pc=5562f38dc4e7
  pc 0x00005562f38dc4e7 fp 0x00007fe9be27c150 dart::kernel::ScopeBuilder::LookupVariable(long)+0x1f7
  pc 0x00005562f38dc2af fp 0x00007fe9be27c170 dart::kernel::ScopeBuilder::VisitVariableGet(long)+0xf
  pc 0x00005562f38da36d fp 0x00007fe9be27c1b0 dart::kernel::ScopeBuilder::VisitExpression()+0x61d
  pc 0x00005562f38dbf48 fp 0x00007fe9be27c1e0 dart::kernel::ScopeBuilder::VisitArguments()+0x58
  pc 0x00005562f38da2f1 fp 0x00007fe9be27c220 dart::kernel::ScopeBuilder::VisitExpression()+0x5a1
  pc 0x00005562f38db548 fp 0x00007fe9be27c280 dart::kernel::ScopeBuilder::VisitStatement()+0x218
  pc 0x00005562f38db16b fp 0x00007fe9be27c320 dart::kernel::ScopeBuilder::VisitFunctionNode()+0x14b
  pc 0x00005562f38da842 fp 0x00007fe9be27c380 dart::kernel::ScopeBuilder::VisitNode()+0x112
  pc 0x00005562f38d9510 fp 0x00007fe9be27c4f0 dart::kernel::ScopeBuilder::BuildScopes()+0x1230
  pc 0x00005562f3465d27 fp 0x00007fe9be27c820 dart::ParsedFunction::EnsureKernelScopes()+0x37
  pc 0x00005562f389e493 fp 0x00007fe9be27c850 dart::kernel::StreamingFlowGraphBuilder::ParseKernelASTFunction()+0x53
  pc 0x00005562f389e2e1 fp 0x00007fe9be27c900 dart::kernel::StreamingFlowGraphBuilder::BuildGraph()+0xb1
  pc 0x00005562f38b4005 fp 0x00007fe9be27cbc0 dart::kernel::FlowGraphBuilder::BuildGraph()+0x65
  pc 0x00005562f34feb80 fp 0x00007fe9be27cde0 dart::DartCompilationPipeline::BuildFlowGraph(dart::Zone*, dart::ParsedFunction*, dart::ZoneGrowableArray<dart::ICData const*>*, long, bool)+0x40
  pc 0x00005562f34ffd91 fp 0x00007fe9be27d510 dart::CompileParsedFunctionHelper::Compile(dart::CompilationPipeline*)+0x581
  pc 0x00005562f3500948 fp 0x00007fe9be27dc20 dart-sdk/bin/dart+0x235c948
  pc 0x00005562f350048a fp 0x00007fe9be27dcb0 dart::Compiler::CompileFunction(dart::Thread*, dart::Function const&)+0x11a
  pc 0x00005562f3405ba1 fp 0x00007fe9be27dcf0 dart::Function::EnsureHasCode() const+0x61
  pc 0x00005562f34feff6 fp 0x00007fe9be27e260 dart::DRT_CompileFunction(dart::NativeArguments)+0x186
  pc 0x00007fe9c5982ac3 fp 0x00007fe9be27e2a0 Unknown symbol
  pc 0x00007fe9c5982b24 fp 0x00007fe9be27e2d0 Unknown symbol
  pc 0x00007fe9c4b238f6 fp 0x00007fe9be27e2f8 Unknown symbol
  pc 0x00007fe9c4b2382c fp 0x00007fe9be27e358 Unknown symbol
  pc 0x00007fe9c4b22727 fp 0x00007fe9be27e398 Unknown symbol
  pc 0x00007fe9c4b2247f fp 0x00007fe9be27e400 Unknown symbol
  pc 0x00007fe9c4b21cf6 fp 0x00007fe9be27e458 Unknown symbol
  pc 0x00007fe9c5982f0c fp 0x00007fe9be27e4d0 Unknown symbol
  pc 0x00005562f3376ee9 fp 0x00007fe9be27e570 dart::DartEntry::InvokeCode(dart::Code const&, unsigned long, dart::Array const&, dart::Array const&, dart::Thread*)+0x139
  pc 0x00005562f3376d68 fp 0x00007fe9be27e5d0 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long)+0x148
  pc 0x00005562f33790c7 fp 0x00007fe9be27e610 dart::DartLibraryCalls::HandleMessage(long, dart::Instance const&)+0x147
  pc 0x00005562f339c078 fp 0x00007fe9be27eba0 dart::IsolateMessageHandler::HandleMessage(std::__2::unique_ptr<dart::Message, std::__2::default_delete<dart::Message>>)+0x348
  pc 0x00005562f33c5287 fp 0x00007fe9be27ec10 dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool)+0x137
  pc 0x00005562f33c58cb fp 0x00007fe9be27ec60 dart::MessageHandler::TaskCallback()+0x1db
  pc 0x00005562f34ed6db fp 0x00007fe9be27ece0 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*)+0x13b
  pc 0x00005562f34edb28 fp 0x00007fe9be27ed10 dart::ThreadPool::Worker::Main(unsigned long)+0x78
  pc 0x00005562f3464e56 fp 0x00007fe9be27edd0 dart-sdk/bin/dart+0x22c0e56
-- End of DumpStackTrace
  pc 0x0000000000000000 fp 0x00007fe9be27e2a0 sp 0x0000000000000000 [Stub] CallToRuntime
  pc 0x00007fe9c5982b24 fp 0x00007fe9be27e2d0 sp 0x00007fe9be27e2b0 [Stub] LazyCompile
  pc 0x00007fe9c4b238f6 fp 0x00007fe9be27e2f8 sp 0x00007fe9be27e2e0 [Unoptimized] main
  pc 0x00007fe9c4b2382c fp 0x00007fe9be27e358 sp 0x00007fe9be27e308 [Unoptimized] [email protected]:call
  pc 0x00007fe9c4b22727 fp 0x00007fe9be27e398 sp 0x00007fe9be27e368 [Unoptimized] _delayEntrypointInvocation@1026248.<anonymous closure>
  pc 0x00007fe9c4b2247f fp 0x00007fe9be27e400 sp 0x00007fe9be27e3a8 [Unoptimized] [email protected]:call
  pc 0x00007fe9c4b21cf6 fp 0x00007fe9be27e458 sp 0x00007fe9be27e410 [Unoptimized] _RawReceivePort@1026248._handleMessage@1026248
  pc 0x00007fe9c5982f0c fp 0x00007fe9be27e4d0 sp 0x00007fe9be27e468 [Stub] InvokeDartCode
=== Crash occurred when compiling file://[...]/bug.dart_::_main in unoptimized JIT mode in unknown pass
=== Flow Graph not available
Aborted

Using different variable names works:

void main() {
  if (0 case var x) {
    print(x);
  }
  var y = 1;
  print(y);
}

Both switch statements and switch expressions work with the same variable name:

void main() {
  switch (0) {
    case var x: print(x);
  }
  var x = 1;
  print(x);
}
void main() {
  print(switch (0) {
    var x => x
  });
  var x = 1;
  print(x);
}
@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 21, 2023
@a-siva a-siva added this to the Dart 3 beta 3 milestone Jan 23, 2023
@a-siva a-siva added the P2 A bug or feature request we're likely to work on label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants