From a760ade545f956369916c37dfa405ec770e854a3 Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Thu, 17 Jun 2021 10:27:47 +0200 Subject: [PATCH] enhance(compiler): Better error message for glwe error --- compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp | 9 +++++---- .../tests/Dialect/MidLFHE/types_glwe_err_error_2.mlir | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 compiler/tests/Dialect/MidLFHE/types_glwe_err_error_2.mlir diff --git a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp b/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp index e81d9415d..cfa2b47b6 100644 --- a/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp +++ b/compiler/lib/Dialect/MidLFHE/IR/MidLFHEDialect.cpp @@ -100,10 +100,11 @@ unsigned nbBitsFromLog2StdDev(signed log2StdDev, signed bits) { signed int phantomLeft = (bits - scalingFactor) - phantomBits - p - paddingBits; if (phantomLeft < 0) { - // TODO: better message ... - emitError() << "GLWE message cannot be represented " - << (bits - scalingFactor) << "vs" - << (phantomBits - p - paddingBits); + emitError() << "GLWE padding + message + phantom = " + << phantomBits + p + paddingBits + << " cannot be represented cannot be represented in bits - " + "scalingFactor = " + << (bits - scalingFactor); return ::mlir::failure(); } } diff --git a/compiler/tests/Dialect/MidLFHE/types_glwe_err_error_2.mlir b/compiler/tests/Dialect/MidLFHE/types_glwe_err_error_2.mlir new file mode 100644 index 000000000..6649ece98 --- /dev/null +++ b/compiler/tests/Dialect/MidLFHE/types_glwe_err_error_2.mlir @@ -0,0 +1,6 @@ +// RUN: not zamacompiler %s 2>&1| FileCheck %s + +// CHECK-LABEL: error: GLWE padding + message + phantom = 25 cannot be represented cannot be represented in bits - scalingFactor = 24 +func @glwe(%arg0: !MidLFHE.glwe<{1024,12,64}{15,7,3,40,-25}>) -> !MidLFHE.glwe<{1024,12,64}{15,7,3,40,-25}> { + return %arg0: !MidLFHE.glwe<{1024,12,64}{15,7,3,40,-25}> +} \ No newline at end of file