Skip to content

Commit 896aada

Browse files
committed
[NFCI][mlir][Tests] Rename identifiers minor/major to avoid clashes with system headers
Identifiers major and minor are often already taken in POSIX systems due to their presence in <sys/types.h> as part of the makedev library function. This causes compilation failures on FreeBSD and Linux systems with glibc <2.28. This change renames the identifiers to major_/minor_. Differential Revision: https://reviews.llvm.org/D156683
1 parent fbeda97 commit 896aada

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

mlir/test/lib/Dialect/Test/TestDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ TestVersionedOpA::readProperties(::mlir::DialectBytecodeReader &reader,
12931293
// We can materialize missing properties post parsing before verification.
12941294
const auto *version =
12951295
reinterpret_cast<const TestDialectVersion *>(*maybeVersion);
1296-
if ((version->major < 2)) {
1296+
if ((version->major_ < 2)) {
12971297
return success();
12981298
}
12991299
}
@@ -1324,7 +1324,7 @@ ::mlir::LogicalResult TestOpWithVersionedProperties::readFromMlirBytecode(
13241324
// We can materialize missing properties post parsing before verification.
13251325
const auto *version =
13261326
reinterpret_cast<const TestDialectVersion *>(*maybeVersion);
1327-
if ((version->major < 2))
1327+
if ((version->major_ < 2))
13281328
needToParseAnotherInt = false;
13291329
}
13301330
if (needToParseAnotherInt && failed(reader.readVarInt(value2)))

mlir/test/lib/Dialect/Test/TestDialect.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ namespace test {
6565

6666
struct TestDialectVersion : public mlir::DialectVersion {
6767
TestDialectVersion() = default;
68-
TestDialectVersion(uint32_t _major, uint32_t _minor)
69-
: major(_major), minor(_minor){};
70-
uint32_t major = 2;
71-
uint32_t minor = 0;
68+
TestDialectVersion(uint32_t majorVersion, uint32_t minorVersion)
69+
: major_(majorVersion), minor_(minorVersion){};
70+
// We cannot use 'major' and 'minor' here because these identifiers may
71+
// already be used by <sys/types.h> on many POSIX systems including Linux and
72+
// FreeBSD.
73+
uint32_t major_ = 2;
74+
uint32_t minor_ = 0;
7275
};
7376

7477
// Define some classes to exercises the Properties feature.

mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ struct TestBytecodeDialectInterface : public BytecodeDialectInterface {
8383
(succeeded(versionOr))
8484
? *reinterpret_cast<const TestDialectVersion *>(*versionOr)
8585
: TestDialectVersion();
86-
if (version.major < 2)
86+
if (version.major_ < 2)
8787
return readAttrOldEncoding(reader);
88-
if (version.major == 2 && version.minor == 0)
88+
if (version.major_ == 2 && version.minor_ == 0)
8989
return readAttrNewEncoding(reader);
9090
// Forbid reading future versions by returning nullptr.
9191
return Attribute();
@@ -94,30 +94,30 @@ struct TestBytecodeDialectInterface : public BytecodeDialectInterface {
9494
// Emit a specific version of the dialect.
9595
void writeVersion(DialectBytecodeWriter &writer) const final {
9696
auto version = TestDialectVersion();
97-
writer.writeVarInt(version.major); // major
98-
writer.writeVarInt(version.minor); // minor
97+
writer.writeVarInt(version.major_); // major
98+
writer.writeVarInt(version.minor_); // minor
9999
}
100100

101101
std::unique_ptr<DialectVersion>
102102
readVersion(DialectBytecodeReader &reader) const final {
103-
uint64_t major, minor;
104-
if (failed(reader.readVarInt(major)) || failed(reader.readVarInt(minor)))
103+
uint64_t major_, minor_;
104+
if (failed(reader.readVarInt(major_)) || failed(reader.readVarInt(minor_)))
105105
return nullptr;
106106
auto version = std::make_unique<TestDialectVersion>();
107-
version->major = major;
108-
version->minor = minor;
107+
version->major_ = major_;
108+
version->minor_ = minor_;
109109
return version;
110110
}
111111

112112
LogicalResult upgradeFromVersion(Operation *topLevelOp,
113113
const DialectVersion &version_) const final {
114114
const auto &version = static_cast<const TestDialectVersion &>(version_);
115-
if ((version.major == 2) && (version.minor == 0))
115+
if ((version.major_ == 2) && (version.minor_ == 0))
116116
return success();
117-
if (version.major > 2 || (version.major == 2 && version.minor > 0)) {
117+
if (version.major_ > 2 || (version.major_ == 2 && version.minor_ > 0)) {
118118
return topLevelOp->emitError()
119119
<< "current test dialect version is 2.0, can't parse version: "
120-
<< version.major << "." << version.minor;
120+
<< version.major_ << "." << version.minor_;
121121
}
122122
// Prior version 2.0, the old op supported only a single attribute called
123123
// "dimensions". We can perform the upgrade.

mlir/test/lib/IR/TestBytecodeCallbacks.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class TestDialectVersionParser : public cl::parser<test::TestDialectVersion> {
2929

3030
bool parse(cl::Option &O, StringRef /*argName*/, StringRef arg,
3131
test::TestDialectVersion &v) {
32-
long long major, minor;
33-
if (getAsSignedInteger(arg.split(".").first, 10, major))
32+
long long major_, minor_;
33+
if (getAsSignedInteger(arg.split(".").first, 10, major_))
3434
return O.error("Invalid argument '" + arg);
35-
if (getAsSignedInteger(arg.split(".").second, 10, minor))
35+
if (getAsSignedInteger(arg.split(".").second, 10, minor_))
3636
return O.error("Invalid argument '" + arg);
37-
v = test::TestDialectVersion(major, minor);
37+
v = test::TestDialectVersion(major_, minor_);
3838
// Returns true on error.
3939
return false;
4040
}
4141
static void print(raw_ostream &os, const test::TestDialectVersion &v) {
42-
os << v.major << "." << v.minor;
42+
os << v.major_ << "." << v.minor_;
4343
};
4444
};
4545

@@ -127,7 +127,7 @@ struct TestBytecodeCallbackPass
127127
[&](Type entryValue, std::optional<StringRef> &dialectGroupName,
128128
DialectBytecodeWriter &writer) -> LogicalResult {
129129
// Do not override anything if version less than 2.0.
130-
if (targetEmissionVersion.major >= 2)
130+
if (targetEmissionVersion.major_ >= 2)
131131
return failure();
132132

133133
// For version less than 2.0, override the encoding of IntegerType.
@@ -159,7 +159,7 @@ struct TestBytecodeCallbackPass
159159
// supported. For the purpose of the test, just use
160160
// `targetEmissionVersion`.
161161
(void)version;
162-
if (targetEmissionVersion.major >= 2)
162+
if (targetEmissionVersion.major_ >= 2)
163163
return success();
164164

165165
// `dialectName` is the name of the group we have the opportunity to

0 commit comments

Comments
 (0)