[PATCH] D32739: [Polly] JSONImporter misses checks whether the data it imports makes sense.

Bonfante Nicolas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 03:53:05 PDT 2017


niosega created this revision.
niosega created this object with edit policy "niosega (Bonfante Nicolas)".

I add some checks and some test cases for the JSONImporter.

Here are the checks I added :

JSONImporter::importContext

- The "context" key does not exist.
- String parsed by isl_set_read_from_str is not a valid isl set.
- The isl_set has the wrong number of parameters
- The isl_set is not a parameter set (i.e. one or more set dimensions,

see isl_set_is_params)

JSONImporter::importSchedule

- json["statements"][Index]["schedule"] item does not exist
- Number of indices does not match number of statements
- Cannot parse schedule map.

Generally:

- Any non-existing json item


https://reviews.llvm.org/D32739

Files:
  lib/Exchange/JSONExporter.cpp


Index: lib/Exchange/JSONExporter.cpp
===================================================================
--- lib/Exchange/JSONExporter.cpp
+++ lib/Exchange/JSONExporter.cpp
@@ -274,9 +274,23 @@

 bool JSONImporter::importContext(Scop &S, Json::Value &JScop) {
   isl_set *OldContext = S.getContext();
+
+  if (!JScop.isMember("context")) {
+    errs() << "JScop file has no key named 'context'.\n";
+    isl_set_free(OldContext);
+    return false;
+  }
+
   isl_set *NewContext =
       isl_set_read_from_str(S.getIslCtx(), JScop["context"].asCString());

+  if (!isl_set_is_params(NewContext)) {
+    errs() << "The isl_set is not a parameter set.\n";
+    isl_set_free(NewContext);
+    isl_set_free(OldContext);
+    return false;
+  }
+
   for (unsigned i = 0; i < isl_set_dim(OldContext, isl_dim_param); i++) {
     isl_id *Id = isl_set_get_dim_id(OldContext, isl_dim_param, i);
     NewContext = isl_set_set_dim_id(NewContext, isl_dim_param, i, Id);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32739.97423.patch
Type: text/x-patch
Size: 957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170502/d2444a43/attachment.bin>


More information about the llvm-commits mailing list