caller_fn_path
);
+ // FIXME(richkadel): (1) Replace raw function name with mangled function name;
+ // (2) Replace hardcoded `1234` in `hash` with a computed hash (as discussed in)
+ // the MCP (compiler-team/issues/278); and replace the hardcoded `1` for
+ // `num_counters` with the actual number of counters per function (when the
+ // changes are made to inject more than one counter per function).
let (fn_name, _len_val) = self.const_str(Symbol::intern(&caller_fn_path));
let index = args[0].immediate();
let hash = self.const_u64(1234);
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::Span;
+use rustc_target::abi;
pub struct InstrumentCoverage;
}
// The first counter (start of the function) is index zero.
-const INIT_FUNCTION_COUNTER: u128 = 0;
+const INIT_FUNCTION_COUNTER: u32 = 0;
/// Injects calls to placeholder function `count_code_region()`.
// FIXME(richkadel): As a first step, counters are only injected at the top of each function.
let count_code_region_fn =
function_handle(tcx, span, tcx.lang_items().count_code_region_fn().unwrap());
- let counter_index = const_int_operand(tcx, span, tcx.types.u32, INIT_FUNCTION_COUNTER);
+ let counter_index =
+ const_int_operand(tcx, span, tcx.types.u32, Scalar::from_u32(INIT_FUNCTION_COUNTER));
let mut patch = MirPatch::new(body);
tcx: TyCtxt<'tcx>,
span: Span,
ty: Ty<'tcx>,
- val: u128,
+ val: Scalar,
) -> Operand<'tcx> {
- let param_env_and_ty = ty::ParamEnv::empty().and(ty);
- let size = tcx
- .layout_of(param_env_and_ty)
- .unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
- .size;
+ debug_assert!({
+ let param_env_and_ty = ty::ParamEnv::empty().and(ty);
+ let type_size = tcx
+ .layout_of(param_env_and_ty)
+ .unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
+ .size;
+ let scalar_size = abi::Size::from_bytes(match val {
+ Scalar::Raw { size, .. } => size,
+ _ => panic!("Invalid scalar type {:?}", val),
+ });
+ scalar_size == type_size
+ });
Operand::Constant(box Constant {
span,
user_ty: None,
- literal: ty::Const::from_scalar(tcx, Scalar::from_uint(val, size), ty),
+ literal: ty::Const::from_scalar(tcx, val, ty),
})
}
// What we need to run borrowck etc.
&promote_pass,
&simplify::SimplifyCfg::new("qualify-consts"),
+ // If the `instrument-coverage` option is enabled, analyze the CFG, identify each
+ // conditional branch, construct a coverage map to be passed to LLVM, and inject counters
+ // where needed.
+ &instrument_coverage::InstrumentCoverage,
]],
);
// `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late,
// but before optimizations begin.
&add_retag::AddRetag,
- // If the `instrument-coverage` option is enabled, analyze the CFG, identify each
- // conditional branch, construct a coverage map to be passed to LLVM, and inject counters
- // where needed.
- &instrument_coverage::InstrumentCoverage,
&simplify::SimplifyCfg::new("elaborate-drops"),
];