Skip to content

Commit acdcac0

Browse files
authored
[mlir-tblgen] Suffix underscore to prevent conflict (#166017)
In the case where the property name is value, the generated op def file would have a collision for hash_value.
1 parent b7e922a commit acdcac0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

mlir/test/mlir-tblgen/op-properties.td

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def OpWithProps : NS_Op<"op_with_props"> {
3232
ArrayProp<StringProp>:$strings,
3333
DefaultValuedProp<I32Prop, "0">:$default_int,
3434
OptionalProp<I64Prop>:$optional,
35-
DefaultI64Array:$intArray
35+
DefaultI64Array:$value
3636
);
3737
}
3838

@@ -94,10 +94,10 @@ def OpWithOptionalPropsAndAttrs :
9494
// DECL: ::llvm::ArrayRef<std::string> getStrings()
9595
// DECL: using default_intTy = int32_t;
9696
// DECL: default_intTy default_int = 0;
97-
// DECL: intArrayTy intArray = ::llvm::SmallVector<int64_t>{};
98-
// DECL: ::llvm::ArrayRef<int64_t> getIntArray()
97+
// DECL: valueTy value = ::llvm::SmallVector<int64_t>{};
98+
// DECL: ::llvm::ArrayRef<int64_t> getValue()
9999
// DECL: return ::llvm::ArrayRef<int64_t>{propStorage}
100-
// DECL: void setIntArray(::llvm::ArrayRef<int64_t> propValue)
100+
// DECL: void setValue(::llvm::ArrayRef<int64_t> propValue)
101101
// DECL: propStorage.assign
102102
// DECL-LABEL: class OpWithProps :
103103
// DECL: setString(::llvm::StringRef newString)
@@ -111,14 +111,14 @@ def OpWithOptionalPropsAndAttrs :
111111
// DECL-SAME: ::llvm::ArrayRef<std::string> strings,
112112
// DECL-SAME: /*optional*/int32_t default_int = 0,
113113
// DECL-SAME: /*optional*/std::optional<int64_t> optional = std::nullopt,
114-
// DECL-SAME: /*optional*/::llvm::ArrayRef<int64_t> intArray = ::llvm::ArrayRef<int64_t>{});
114+
// DECL-SAME: /*optional*/::llvm::ArrayRef<int64_t> value = ::llvm::ArrayRef<int64_t>{});
115115

116116
// DEFS-LABEL: OpWithProps::computePropertiesHash
117-
// DEFS: hash_intArray
117+
// DEFS: hash_value_
118118
// DEFS: using ::llvm::hash_value;
119119
// DEFS-NEXT: return hash_value(::llvm::ArrayRef<int64_t>{propStorage})
120120
// DEFS: hash_value(prop.optional)
121-
// DEFS: hash_intArray(prop.intArray)
121+
// DEFS: hash_value_(prop.value)
122122

123123
// -----
124124

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ void OpEmitter::genPropertiesSupport() {
16291629
// Hashing for the property
16301630

16311631
const char *propHashFmt = R"decl(
1632-
auto hash_{0} = [] (const auto &propStorage) -> llvm::hash_code {
1632+
auto hash_{0}_ = [] (const auto &propStorage) -> llvm::hash_code {
16331633
using ::llvm::hash_value;
16341634
return {1};
16351635
};
@@ -1655,7 +1655,7 @@ void OpEmitter::genPropertiesSupport() {
16551655
if (const auto *namedProperty =
16561656
llvm::dyn_cast_if_present<const NamedProperty *>(attrOrProp)) {
16571657
if (!namedProperty->prop.getHashPropertyCall().empty()) {
1658-
hashMethod << "\n hash_" << namedProperty->name << "(prop."
1658+
hashMethod << "\n hash_" << namedProperty->name << "_(prop."
16591659
<< namedProperty->name << ")";
16601660
} else {
16611661
hashMethod << "\n hash_value(prop." << namedProperty->name

0 commit comments

Comments
 (0)