Skip to content

Commit

Permalink
[tfg][functiondef_import] Emit error on empty function attributes
Browse files Browse the repository at this point in the history
Disallow empty function attributes. Emit an error when one is encountered.

PiperOrigin-RevId: 448629968
  • Loading branch information
tensorflower-gardener committed May 14, 2022
1 parent 230e240 commit 1cf45b8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tensorflow/core/ir/importexport/functiondef_import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ Status ImportGenericFunction(
// Import the function attributes with a `tf.` prefix to match the current
// infrastructure expectations.
for (const auto& namedAttr : func.attr()) {
if (namedAttr.first.empty())
return InvalidArgument("Invalid function attribute name");
const std::string& name = "tf." + namedAttr.first;
const AttrValue& tf_attr = namedAttr.second;
TF_ASSIGN_OR_RETURN(Attribute attr,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# RUN: not tfg-translate -graphdef-to-mlir %s 2>&1 | FileCheck %s

# CHECK: Invalid function attribute name

library {
function {
signature {
name: "foo"
input_arg {
name: "a"
}
output_arg {
name: "d"
}
}
node_def {
op: "Const"
attr {
key: "_b"
value {
placeholder: "T"
}
}
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "value"
value {
tensor {
dtype: DT_INT32
tensor_shape {
}
}
}
}
}
ret {
key: "d"
value: "a"
}
attr {
key: ""
value {
s: "a"
}
}
}
}

0 comments on commit 1cf45b8

Please sign in to comment.