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

(c2rust-analyze) Use SubstsRef when creating an Instance to get the SymbolName so that we don't ICE on generic foreign fns like extern "rust-intrinsic"s #999

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions c2rust-analyze/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use rustc_middle::ty::FieldDef;
use rustc_middle::ty::GenericArgKind;
use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::Instance;
use rustc_middle::ty::List;
use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::Ty;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::TyKind;
Expand Down Expand Up @@ -685,8 +687,8 @@ impl<'tcx> GlobalAnalysisCtxt<'tcx> {
self.fns_failed.keys().copied()
}

pub fn known_fn(&self, def_id: DefId) -> Option<&'static KnownFn> {
let symbol = self.tcx.symbol_name(Instance::mono(self.tcx, def_id));
pub fn known_fn(&self, def_id: DefId, substs: SubstsRef<'tcx>) -> Option<&'static KnownFn> {
let symbol = self.tcx.symbol_name(Instance::new(def_id, substs));
self.known_fns.get(symbol.name).copied()
}

Expand All @@ -707,7 +709,7 @@ impl<'tcx> GlobalAnalysisCtxt<'tcx> {
.filter(|(def_id, _)| {
self.tcx.def_kind(self.tcx.parent(**def_id)) == DefKind::ForeignMod
})
.filter_map(|(&def_id, fn_sig)| Some((fn_sig, self.known_fn(def_id)?)))
.filter_map(|(&def_id, fn_sig)| Some((fn_sig, self.known_fn(def_id, List::empty())?)))
.flat_map(|(fn_sig, known_fn)| known_fn.ptr_perms(fn_sig))
}
}
Expand Down
2 changes: 1 addition & 1 deletion c2rust-analyze/src/dataflow/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<'tcx> TypeChecker<'tcx, '_> {
def_id,
substs,
is_foreign: true,
}) if self.acx.gacx.known_fn(def_id).is_some() => {
}) if self.acx.gacx.known_fn(def_id, substs).is_some() => {
// As this is actually a known `fn`, we can treat it as a normal local call.
self.visit_local_call(def_id, substs, args, destination);
}
Expand Down