[polly] r306479 - [JSONImport] Check, if the size of an imported array is positive
Andreas Simbuerger via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 15:30:44 PDT 2017
Author: simbuerg
Date: Tue Jun 27 15:30:44 2017
New Revision: 306479
URL: http://llvm.org/viewvc/llvm-project?rev=306479&view=rev
Log:
[JSONImport] Check, if the size of an imported array is positive
Added:
polly/trunk/test/JSONExporter/ImportArrays/ImportArrays-Negative-size.ll
polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop
polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop.transformed
Modified:
polly/trunk/lib/Exchange/JSONExporter.cpp
Modified: polly/trunk/lib/Exchange/JSONExporter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Exchange/JSONExporter.cpp?rev=306479&r1=306478&r2=306479&view=diff
==============================================================================
--- polly/trunk/lib/Exchange/JSONExporter.cpp (original)
+++ polly/trunk/lib/Exchange/JSONExporter.cpp Tue Jun 27 15:30:44 2017
@@ -701,8 +701,16 @@ bool JSONImporter::importArrays(Scop &S,
return false;
}
std::vector<unsigned> DimSizes;
- for (unsigned i = 0; i < Arrays[ArrayIdx]["sizes"].size(); i++)
+ for (unsigned i = 0; i < Arrays[ArrayIdx]["sizes"].size(); i++) {
+ auto Size = std::stoi(Arrays[ArrayIdx]["sizes"][i].asCString());
+
+ // Check if the size if positive.
+ if (Size <= 0) {
+ errs() << "The size at index " << i << " is =< 0.\n";
+ return false;
+ }
DimSizes.push_back(std::stoi(Arrays[ArrayIdx]["sizes"][i].asCString()));
+ }
S.createScopArrayInfo(ElementType, Arrays[ArrayIdx]["name"].asCString(),
DimSizes);
}
Added: polly/trunk/test/JSONExporter/ImportArrays/ImportArrays-Negative-size.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/JSONExporter/ImportArrays/ImportArrays-Negative-size.ll?rev=306479&view=auto
==============================================================================
--- polly/trunk/test/JSONExporter/ImportArrays/ImportArrays-Negative-size.ll (added)
+++ polly/trunk/test/JSONExporter/ImportArrays/ImportArrays-Negative-size.ll Tue Jun 27 15:30:44 2017
@@ -0,0 +1,77 @@
+; RUN: opt %loadPolly -polly-scops -analyze -polly-import-jscop-dir=%S -polly-import-jscop -polly-import-jscop-postfix=transformed < %s 2>&1 | FileCheck %s
+;
+; #define Ni 1056
+; #define Nj 1056
+; #define Nk 1024
+;
+; void ImportArray_Negative_size(double beta, double A[Ni][Nk], double B[Ni][Nj]) {
+; int i,j,k;
+;
+; for (i = 0; i < Ni; i++) {
+; for (j = 0; j < Nj; j++) {
+; for (k = 0; k < Nk; ++k) {
+; B[i][j] = beta * A[i][k];
+; }
+; }
+; }
+; }
+;
+; Verify if the JSONImporter checks if the size of the new array is positive.
+; CHECK: The size at index 0 is =< 0.
+;
+; ModuleID = 'ImportArrays-Negative-size.ll'
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+; Function Attrs: nounwind uwtable
+define void @ImportArrays_Negative_Size(double %beta, [1024 x double]* nocapture readonly %A, [1056 x double]* nocapture %B) local_unnamed_addr {
+entry:
+ br label %for.cond1.preheader
+
+for.cond1.preheader: ; preds = %for.inc16, %entry
+ %indvars.iv35 = phi i64 [ 0, %entry ], [ %indvars.iv.next36, %for.inc16 ]
+ br label %for.cond4.preheader
+
+for.cond4.preheader: ; preds = %for.inc13, %for.cond1.preheader
+ %indvars.iv32 = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next33, %for.inc13 ]
+ %arrayidx12 = getelementptr inbounds [1056 x double], [1056 x double]* %B, i64 %indvars.iv35, i64 %indvars.iv32
+ br label %for.body6
+
+for.body6: ; preds = %for.body6, %for.cond4.preheader
+ %indvars.iv = phi i64 [ 0, %for.cond4.preheader ], [ %indvars.iv.next.3, %for.body6 ]
+ %arrayidx8 = getelementptr inbounds [1024 x double], [1024 x double]* %A, i64 %indvars.iv35, i64 %indvars.iv
+ %0 = load double, double* %arrayidx8, align 8
+ %mul = fmul double %0, %beta
+ store double %mul, double* %arrayidx12, align 8
+ %indvars.iv.next = or i64 %indvars.iv, 1
+ %arrayidx8.1 = getelementptr inbounds [1024 x double], [1024 x double]* %A, i64 %indvars.iv35, i64 %indvars.iv.next
+ %1 = load double, double* %arrayidx8.1, align 8
+ %mul.1 = fmul double %1, %beta
+ store double %mul.1, double* %arrayidx12, align 8
+ %indvars.iv.next.1 = or i64 %indvars.iv, 2
+ %arrayidx8.2 = getelementptr inbounds [1024 x double], [1024 x double]* %A, i64 %indvars.iv35, i64 %indvars.iv.next.1
+ %2 = load double, double* %arrayidx8.2, align 8
+ %mul.2 = fmul double %2, %beta
+ store double %mul.2, double* %arrayidx12, align 8
+ %indvars.iv.next.2 = or i64 %indvars.iv, 3
+ %arrayidx8.3 = getelementptr inbounds [1024 x double], [1024 x double]* %A, i64 %indvars.iv35, i64 %indvars.iv.next.2
+ %3 = load double, double* %arrayidx8.3, align 8
+ %mul.3 = fmul double %3, %beta
+ store double %mul.3, double* %arrayidx12, align 8
+ %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
+ %exitcond.3 = icmp eq i64 %indvars.iv.next.3, 1024
+ br i1 %exitcond.3, label %for.inc13, label %for.body6
+
+for.inc13: ; preds = %for.body6
+ %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
+ %exitcond34 = icmp eq i64 %indvars.iv.next33, 1056
+ br i1 %exitcond34, label %for.inc16, label %for.cond4.preheader
+
+for.inc16: ; preds = %for.inc13
+ %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
+ %exitcond37 = icmp eq i64 %indvars.iv.next36, 1056
+ br i1 %exitcond37, label %for.end18, label %for.cond1.preheader
+
+for.end18: ; preds = %for.inc16
+ ret void
+}
Added: polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%25for.cond1.preheader---%25for.end18.jscop?rev=306479&view=auto
==============================================================================
--- polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop (added)
+++ polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop Tue Jun 27 15:30:44 2017
@@ -0,0 +1,61 @@
+{
+ "arrays" : [
+ {
+ "name" : "MemRef_A",
+ "sizes" : [ "*", "1024" ],
+ "type" : "double"
+ },
+ {
+ "name" : "MemRef_B",
+ "sizes" : [ "*", "1056" ],
+ "type" : "double"
+ }
+ ],
+ "context" : "{ : }",
+ "name" : "%for.cond1.preheader---%for.end18",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 4i2] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_beta[] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 1 + 4i2] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 2 + 4i2] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 3 + 4i2] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ }
+ ],
+ "domain" : "{ Stmt_for_body6[i0, i1, i2] : 0 <= i0 <= 1055 and 0 <= i1 <= 1055 and 0 <= i2 <= 255 }",
+ "name" : "Stmt_for_body6",
+ "schedule" : "{ Stmt_for_body6[i0, i1, i2] -> [i0, i1, i2] }"
+ }
+ ]
+}
Added: polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop.transformed
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%25for.cond1.preheader---%25for.end18.jscop.transformed?rev=306479&view=auto
==============================================================================
--- polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop.transformed (added)
+++ polly/trunk/test/JSONExporter/ImportArrays/ImportArrays_Negative_Size___%for.cond1.preheader---%for.end18.jscop.transformed Tue Jun 27 15:30:44 2017
@@ -0,0 +1,67 @@
+{
+ "arrays" : [
+ {
+ "name" : "MemRef_A",
+ "sizes" : [ "*", "1024" ],
+ "type" : "double"
+ },
+ {
+ "name" : "MemRef_B",
+ "sizes" : [ "*", "1056" ],
+ "type" : "double"
+ },
+ {
+ "name" : "D",
+ "sizes" : [ "-270336" ],
+ "type" : "double",
+ "allocation" : "heap"
+ }
+ ],
+ "context" : "{ : }",
+ "name" : "%for.cond1.preheader---%for.end18",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 4i2] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_beta[] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 1 + 4i2] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 2 + 4i2] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ },
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 3 + 4i2] }"
+ },
+ {
+ "kind" : "write",
+ "relation" : "{ Stmt_for_body6[i0, i1, i2] -> MemRef_B[i0, i1] }"
+ }
+ ],
+ "domain" : "{ Stmt2[i0, i1, i2] : 0 <= i0 <= 1055 and 0 <= i1 <= 1055 and 0 <= i2 <= 255 }",
+ "name" : "Stmt2",
+ "schedule" : "{ Stmt2[i0, i1, i2] -> [i0, i1, i2] }"
+ }
+ ]
+}
More information about the llvm-commits
mailing list