[llvm] r290628 - [sanitizer-coverage] sort the switch cases
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 27 13:20:06 PST 2016
Author: kcc
Date: Tue Dec 27 15:20:06 2016
New Revision: 290628
URL: http://llvm.org/viewvc/llvm-project?rev=290628&view=rev
Log:
[sanitizer-coverage] sort the switch cases
Modified:
llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/trunk/test/Instrumentation/SanitizerCoverage/switch-tracing.ll
Modified: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp?rev=290628&r1=290627&r2=290628&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp Tue Dec 27 15:20:06 2016
@@ -601,6 +601,11 @@ void SanitizerCoverageModule::InjectTrac
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,
Modified: llvm/trunk/test/Instrumentation/SanitizerCoverage/switch-tracing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/SanitizerCoverage/switch-tracing.ll?rev=290628&r1=290627&r2=290628&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/SanitizerCoverage/switch-tracing.ll (original)
+++ llvm/trunk/test/Instrumentation/SanitizerCoverage/switch-tracing.ll Tue Dec 27 15:20:06 2016
@@ -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
More information about the llvm-commits
mailing list