[llvm] 17095df - Move interpreter check before modifying the allocation type.

Jacob Hegna via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 12:50:51 PDT 2022


Author: Jacob Hegna
Date: 2022-10-12T19:50:36Z
New Revision: 17095dfe361341e491897ea18b544901bb00f5af

URL: https://github.com/llvm/llvm-project/commit/17095dfe361341e491897ea18b544901bb00f5af
DIFF: https://github.com/llvm/llvm-project/commit/17095dfe361341e491897ea18b544901bb00f5af.diff

LOG: Move interpreter check before modifying the allocation type.

Added: 
    

Modified: 
    llvm/lib/Analysis/TFLiteUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/TFLiteUtils.cpp b/llvm/lib/Analysis/TFLiteUtils.cpp
index 9a7a441e0d26..6c6d61f4afba 100644
--- a/llvm/lib/Analysis/TFLiteUtils.cpp
+++ b/llvm/lib/Analysis/TFLiteUtils.cpp
@@ -121,6 +121,11 @@ TFModelEvaluatorImpl::TFModelEvaluatorImpl(
   tflite::InterpreterBuilder Builder(*Model, Resolver);
   Builder(&Interpreter);
 
+  if (!Interpreter) {
+    invalidate();
+    return;
+  }
+
   // We assume the input buffers are valid for the lifetime of the interpreter.
   // By default, tflite allocates memory in an arena and will periodically take
   // away memory and reallocate it in a 
diff erent location after evaluations in
@@ -130,8 +135,7 @@ TFModelEvaluatorImpl::TFModelEvaluatorImpl(
     Interpreter->tensor(I)->allocation_type =
         TfLiteAllocationType::kTfLiteArenaRwPersistent;
 
-  if (!Interpreter ||
-      Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
+  if (Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
     invalidate();
     return;
   }


        


More information about the llvm-commits mailing list