Skip to content

Commit

Permalink
[polly] [ScopInfo] Don't use isl_val_get_num_si.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Eli Friedman committed Jan 17, 2018
1 parent 1e28194 commit a75d53c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
10 changes: 7 additions & 3 deletions polly/lib/Analysis/ScopInfo.cpp
Expand Up @@ -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);

Expand Down
40 changes: 35 additions & 5 deletions polly/test/ScopInfo/multidim_fold_constant_dim.ll
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}

0 comments on commit a75d53c

Please sign in to comment.