From 845b48b293f388d93686ecaddf3bfa02a91760dd Mon Sep 17 00:00:00 2001 From: youben11 Date: Wed, 2 Mar 2022 15:07:58 +0100 Subject: [PATCH] refactor: remove variable length array usages --- compiler/CMakeLists.txt | 10 ---------- compiler/lib/ClientLib/ClientLambda.cpp | 6 +++--- compiler/lib/ClientLib/Serializers.cpp | 3 ++- compiler/lib/ServerLib/ServerLambda.cpp | 5 +++-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index 2577786bb..a4d794b96 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -12,16 +12,6 @@ if (APPLE) add_definitions("-Wno-narrowing") endif() -add_compile_options(-Wfatal-errors) # stop at first error - # variable length array = vla -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - # using Clang - add_compile_options(-Wno-vla-extension) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # using GCC - add_compile_options(-Wno-vla) -endif() - # If we are trying to build the compiler with LLVM/MLIR as libraries if( NOT DEFINED LLVM_EXTERNAL_CONCRETELANG_SOURCE_DIR ) message(FATAL_ERROR "Concrete compiler requires a unified build with LLVM/MLIR") diff --git a/compiler/lib/ClientLib/ClientLambda.cpp b/compiler/lib/ClientLib/ClientLambda.cpp index 2be553a2f..203ce6798 100644 --- a/compiler/lib/ClientLib/ClientLambda.cpp +++ b/compiler/lib/ClientLib/ClientLambda.cpp @@ -138,11 +138,11 @@ decryptReturnedTensor(std::istream &istream, ClientLambda &lambda, << expectedRank << " which cannot be decrypted to rank " << rank; } OUTCOME_TRY(auto values, lambda.decryptReturnedValues(keySet, istream)); - size_t sizes[rank]; + llvm::SmallVector sizes; for (size_t dim = 0; dim < rank; dim++) { - sizes[dim] = shape.dimensions[dim]; + sizes.push_back(shape.dimensions[dim]); } - return flatToTensor(values, sizes); + return flatToTensor(values, sizes.data()); } outcome::checked diff --git a/compiler/lib/ClientLib/Serializers.cpp b/compiler/lib/ClientLib/Serializers.cpp index 6ea8e8413..9a5e20a81 100644 --- a/compiler/lib/ClientLib/Serializers.cpp +++ b/compiler/lib/ClientLib/Serializers.cpp @@ -82,10 +82,11 @@ std::ostream &operator<<(std::ostream &ostream, const ClientParameters &cp) { std::istream &operator>>(std::istream &istream, ClientParameters ¶ms) { size_t size; readSize(istream, size); - char buffer[size + 1]; + char *buffer = new char[size + 1]; buffer[size] = '\0'; // llvm::json::parse requires \0 ended buffer. istream.read(buffer, size); auto paramsOrErr = llvm::json::parse(buffer); + delete[] buffer; if (auto err = paramsOrErr.takeError()) { llvm::errs() << "Parsing client parameters error: " << std::move(err) << "\n"; diff --git a/compiler/lib/ServerLib/ServerLambda.cpp b/compiler/lib/ServerLib/ServerLambda.cpp index cc424453d..94f2c7834 100644 --- a/compiler/lib/ServerLib/ServerLambda.cpp +++ b/compiler/lib/ServerLib/ServerLambda.cpp @@ -61,8 +61,8 @@ encrypted_scalars_and_sizes_t encrypted_scalars_and_sizes_t_from_MemRef( for (size_t r = 0; r < memref_rank; r++) { result.sizes[r] = sizes[r]; } - size_t - index[memref_rank]; // ephemeral multi dim index to compute global strides + size_t *index = new size_t[memref_rank]; // ephemeral multi dim index to + // compute global strides for (size_t r = 0; r < memref_rank; r++) { index[r] = 0; } @@ -74,6 +74,7 @@ encrypted_scalars_and_sizes_t encrypted_scalars_and_sizes_t_from_MemRef( result.values[i] = aligned[offset + g_index]; next_coord_index(index, sizes, memref_rank); } + delete[] index; return result; }