From 6bb10922b1d6d6d7635cb7570f577dc90028512f Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Wed, 28 Jun 2023 10:32:33 +0800 Subject: [PATCH] fix: Short-circuit on empty locations for locals --- scip_indexer/SCIPIndexer.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scip_indexer/SCIPIndexer.cc b/scip_indexer/SCIPIndexer.cc index 45b803ef7..16dd3c543 100644 --- a/scip_indexer/SCIPIndexer.cc +++ b/scip_indexer/SCIPIndexer.cc @@ -807,6 +807,16 @@ class CFGTraversal final { // The type should be provided if we have an lvalue. bool emitLocalOccurrence(const cfg::CFG &cfg, const cfg::BasicBlock *bb, cfg::LocalOccurrence local, ValueCategory category, core::TypePtr type) { + auto loc = local.loc; + if (!loc.exists() || loc.empty()) { + // Safeguard against incorrect merges from upstream Sorbet, where + // some changes cause empty source locations to propagate down here. + // + // FIXME: Investigate which code patterns trigger this; normally + // locals should carry non-empty locations, but this was + // triggered on some private code. + return false; + } auto localRef = local.variable; auto localVar = localRef.data(cfg); auto symRef = this->aliasMap.try_consume(localRef); @@ -848,7 +858,6 @@ class CFGTraversal final { } ENFORCE(this->functionLocals.contains(localRef), "should've added local earlier if it was missing"); absl::Status status; - auto loc = local.loc; auto &gs = this->ctx.state; auto file = this->ctx.file; if (symRef.has_value()) {