[sanitizer-coverage] sort the switch cases

llvm-svn: 290628
This commit is contained in:
Kostya Serebryany 2016-12-27 21:20:06 +00:00
parent 2cd4d50d15
commit aece9ad2f5
2 changed files with 7 additions and 2 deletions

View File

@ -601,6 +601,11 @@ void SanitizerCoverageModule::InjectTraceForSwitch(
C = ConstantExpr::getCast(CastInst::ZExt, It.getCaseValue(), Int64Ty);
Initializers.push_back(C);
}
std::sort(Initializers.begin() + 2, Initializers.end(),
[](const Constant *A, const Constant *B) {
return cast<ConstantInt>(A)->getLimitedValue() <
cast<ConstantInt>(B)->getLimitedValue();
});
ArrayType *ArrayOfInt64Ty = ArrayType::get(Int64Ty, Initializers.size());
GlobalVariable *GV = new GlobalVariable(
*CurModule, ArrayOfInt64Ty, false, GlobalVariable::InternalLinkage,

View File

@ -11,8 +11,8 @@ entry:
; CHECK-NEXT: call void @__sanitizer_cov_trace_switch(i64 [[TMP]], i64* getelementptr inbounds ([5 x i64], [5 x i64]* @__sancov_gen_cov_switch_values, i32 0, i32 0))
switch i32 %x, label %sw.epilog [
i32 1, label %sw.bb
i32 101, label %sw.bb.1
i32 1001, label %sw.bb.2
i32 1001, label %sw.bb.1
i32 101, label %sw.bb.2
]
sw.bb: ; preds = %entry