From a75d53c83f8afbfc107da37774a13908e8718276 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 17 Jan 2018 21:59:02 +0000 Subject: [PATCH] [polly] [ScopInfo] Don't use isl_val_get_num_si. isl_val_get_num_si crashes on overflow, so don't use it on arbitrary integers. Testcase only crashes on platforms where long is 32 bits because of the signature of isl_val_get_num_si; not sure if it's possible to write a testcase which crashes if long is 64 bits. There are a few other places in polly which use isl_val_get_num_si; they probably need to be fixed as well. I don't think polly uses any of the other "long" isl APIs in an unsafe manner. Differential Revision: https://reviews.llvm.org/D42129 llvm-svn: 322766 --- polly/lib/Analysis/ScopInfo.cpp | 10 ++++-- polly/test/ScopInfo/multidim_fold_constant_dim.ll | 40 ++++++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index d2bc71f..1ef900d 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -3428,9 +3428,13 @@ void Scop::foldSizeConstantsToRight() { int ValInt = 1; - if (isl_val_is_int(Val)) - ValInt = isl_val_get_num_si(Val); - isl_val_free(Val); + if (isl_val_is_int(Val)) { + auto ValAPInt = APIntFromVal(Val); + if (ValAPInt.isSignedIntN(32)) + ValInt = ValAPInt.getSExtValue(); + } else { + isl_val_free(Val); + } Int.push_back(ValInt); diff --git a/polly/test/ScopInfo/multidim_fold_constant_dim.ll b/polly/test/ScopInfo/multidim_fold_constant_dim.ll index 1ee555f..5c32b46 100644 --- a/polly/test/ScopInfo/multidim_fold_constant_dim.ll +++ b/polly/test/ScopInfo/multidim_fold_constant_dim.ll @@ -36,6 +36,7 @@ source_filename = "/tmp/test.c" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" %struct.com = type { double, double } +%struct.com2 = type { [20000000000 x double] } define void @foo(i64 %n, %struct.com* %A) { entry: @@ -84,10 +85,39 @@ for.end9: ; preds = %for.cond ret void } -define i32 @main() { +; CHECK: Arrays { +; CHECK-NEXT: double MemRef_O[*][%n]; // Element size 8 +; CHECK-NEXT: } + +define void @foo_overflow(i64 %n, %struct.com2* nocapture %O) local_unnamed_addr #0 { entry: - %A = alloca [100 x [1000 x %struct.com]], align 16 - %tmp = getelementptr inbounds [100 x [1000 x %struct.com]], [100 x [1000 x %struct.com]]* %A, i64 0, i64 0, i64 0 - call void @foo(i64 1000, %struct.com* nonnull %tmp) - ret i32 0 + br label %for.body + +for.cond.cleanup: ; preds = %for.cond.cleanup3 + ret void + +for.body: ; preds = %for.cond.cleanup3, %entry + %i.024 = phi i64 [ 0, %entry ], [ %inc12, %for.cond.cleanup3 ] + %0 = mul nsw i64 %i.024, %n + %arrayidx = getelementptr inbounds %struct.com2, %struct.com2* %O, i64 %0 + br label %for.body4 + +for.cond.cleanup3: ; preds = %for.body4 + %inc12 = add nuw nsw i64 %i.024, 1 + %exitcond25 = icmp eq i64 %inc12, 100 + br i1 %exitcond25, label %for.cond.cleanup, label %for.body + +for.body4: ; preds = %for.body4, %for.body + %j.023 = phi i64 [ 0, %for.body ], [ %inc, %for.body4 ] + %arrayidx5 = getelementptr inbounds %struct.com2, %struct.com2* %arrayidx, i64 %j.023 + %Real = getelementptr inbounds %struct.com2, %struct.com2* %arrayidx5, i64 0, i32 0 + %arrayidx6 = getelementptr inbounds [20000000000 x double], [20000000000 x double]* %Real, i64 0, i64 1 + %1 = load double, double* %arrayidx6, align 8 + %arrayidx10 = getelementptr inbounds [20000000000 x double], [20000000000 x double]* %Real, i64 0, i64 0 + %2 = load double, double* %arrayidx10, align 8 + %add = fadd double %1, %2 + store double %add, double* %arrayidx10, align 8 + %inc = add nuw nsw i64 %j.023, 1 + %exitcond = icmp eq i64 %inc, 1000 + br i1 %exitcond, label %for.cond.cleanup3, label %for.body4 } -- 2.7.4