[Mlir-commits] [mlir] 896aada - [NFCI][mlir][Tests] Rename identifiers minor/major to avoid clashes with system headers
Roger Ferrer Ibanez
llvmlistbot at llvm.org
Mon Jul 31 07:37:54 PDT 2023
Author: Roger Ferrer Ibanez
Date: 2023-07-31T14:36:35Z
New Revision: 896aada3b632bd58297acc3745d61fc24904f34e
URL: https://github.com/llvm/llvm-project/commit/896aada3b632bd58297acc3745d61fc24904f34e
DIFF: https://github.com/llvm/llvm-project/commit/896aada3b632bd58297acc3745d61fc24904f34e.diff
LOG: [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
Added:
Modified:
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestDialect.h
mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
mlir/test/lib/IR/TestBytecodeCallbacks.cpp
Removed:
################################################################################
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp
index c45aad6d72591b..1edd4aa40da043 100644
--- a/mlir/test/lib/Dialect/Test/TestDialect.cpp
+++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp
@@ -1293,7 +1293,7 @@ TestVersionedOpA::readProperties(::mlir::DialectBytecodeReader &reader,
// We can materialize missing properties post parsing before verification.
const auto *version =
reinterpret_cast<const TestDialectVersion *>(*maybeVersion);
- if ((version->major < 2)) {
+ if ((version->major_ < 2)) {
return success();
}
}
@@ -1324,7 +1324,7 @@ ::mlir::LogicalResult TestOpWithVersionedProperties::readFromMlirBytecode(
// We can materialize missing properties post parsing before verification.
const auto *version =
reinterpret_cast<const TestDialectVersion *>(*maybeVersion);
- if ((version->major < 2))
+ if ((version->major_ < 2))
needToParseAnotherInt = false;
}
if (needToParseAnotherInt && failed(reader.readVarInt(value2)))
diff --git a/mlir/test/lib/Dialect/Test/TestDialect.h b/mlir/test/lib/Dialect/Test/TestDialect.h
index d4ba2b4ad23395..31a29cc7f9f7aa 100644
--- a/mlir/test/lib/Dialect/Test/TestDialect.h
+++ b/mlir/test/lib/Dialect/Test/TestDialect.h
@@ -65,10 +65,13 @@ namespace test {
struct TestDialectVersion : public mlir::DialectVersion {
TestDialectVersion() = default;
- TestDialectVersion(uint32_t _major, uint32_t _minor)
- : major(_major), minor(_minor){};
- uint32_t major = 2;
- uint32_t minor = 0;
+ TestDialectVersion(uint32_t majorVersion, uint32_t minorVersion)
+ : major_(majorVersion), minor_(minorVersion){};
+ // We cannot use 'major' and 'minor' here because these identifiers may
+ // already be used by <sys/types.h> on many POSIX systems including Linux and
+ // FreeBSD.
+ uint32_t major_ = 2;
+ uint32_t minor_ = 0;
};
// Define some classes to exercises the Properties feature.
diff --git a/mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp b/mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
index 7fc30b60b2f0d5..5da22ddb081292 100644
--- a/mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
+++ b/mlir/test/lib/Dialect/Test/TestDialectInterfaces.cpp
@@ -83,9 +83,9 @@ struct TestBytecodeDialectInterface : public BytecodeDialectInterface {
(succeeded(versionOr))
? *reinterpret_cast<const TestDialectVersion *>(*versionOr)
: TestDialectVersion();
- if (version.major < 2)
+ if (version.major_ < 2)
return readAttrOldEncoding(reader);
- if (version.major == 2 && version.minor == 0)
+ if (version.major_ == 2 && version.minor_ == 0)
return readAttrNewEncoding(reader);
// Forbid reading future versions by returning nullptr.
return Attribute();
@@ -94,30 +94,30 @@ struct TestBytecodeDialectInterface : public BytecodeDialectInterface {
// Emit a specific version of the dialect.
void writeVersion(DialectBytecodeWriter &writer) const final {
auto version = TestDialectVersion();
- writer.writeVarInt(version.major); // major
- writer.writeVarInt(version.minor); // minor
+ writer.writeVarInt(version.major_); // major
+ writer.writeVarInt(version.minor_); // minor
}
std::unique_ptr<DialectVersion>
readVersion(DialectBytecodeReader &reader) const final {
- uint64_t major, minor;
- if (failed(reader.readVarInt(major)) || failed(reader.readVarInt(minor)))
+ uint64_t major_, minor_;
+ if (failed(reader.readVarInt(major_)) || failed(reader.readVarInt(minor_)))
return nullptr;
auto version = std::make_unique<TestDialectVersion>();
- version->major = major;
- version->minor = minor;
+ version->major_ = major_;
+ version->minor_ = minor_;
return version;
}
LogicalResult upgradeFromVersion(Operation *topLevelOp,
const DialectVersion &version_) const final {
const auto &version = static_cast<const TestDialectVersion &>(version_);
- if ((version.major == 2) && (version.minor == 0))
+ if ((version.major_ == 2) && (version.minor_ == 0))
return success();
- if (version.major > 2 || (version.major == 2 && version.minor > 0)) {
+ if (version.major_ > 2 || (version.major_ == 2 && version.minor_ > 0)) {
return topLevelOp->emitError()
<< "current test dialect version is 2.0, can't parse version: "
- << version.major << "." << version.minor;
+ << version.major_ << "." << version.minor_;
}
// Prior version 2.0, the old op supported only a single attribute called
// "dimensions". We can perform the upgrade.
diff --git a/mlir/test/lib/IR/TestBytecodeCallbacks.cpp b/mlir/test/lib/IR/TestBytecodeCallbacks.cpp
index 1464a80865f776..4e02bdc600cd63 100644
--- a/mlir/test/lib/IR/TestBytecodeCallbacks.cpp
+++ b/mlir/test/lib/IR/TestBytecodeCallbacks.cpp
@@ -29,17 +29,17 @@ class TestDialectVersionParser : public cl::parser<test::TestDialectVersion> {
bool parse(cl::Option &O, StringRef /*argName*/, StringRef arg,
test::TestDialectVersion &v) {
- long long major, minor;
- if (getAsSignedInteger(arg.split(".").first, 10, major))
+ long long major_, minor_;
+ if (getAsSignedInteger(arg.split(".").first, 10, major_))
return O.error("Invalid argument '" + arg);
- if (getAsSignedInteger(arg.split(".").second, 10, minor))
+ if (getAsSignedInteger(arg.split(".").second, 10, minor_))
return O.error("Invalid argument '" + arg);
- v = test::TestDialectVersion(major, minor);
+ v = test::TestDialectVersion(major_, minor_);
// Returns true on error.
return false;
}
static void print(raw_ostream &os, const test::TestDialectVersion &v) {
- os << v.major << "." << v.minor;
+ os << v.major_ << "." << v.minor_;
};
};
@@ -127,7 +127,7 @@ struct TestBytecodeCallbackPass
[&](Type entryValue, std::optional<StringRef> &dialectGroupName,
DialectBytecodeWriter &writer) -> LogicalResult {
// Do not override anything if version less than 2.0.
- if (targetEmissionVersion.major >= 2)
+ if (targetEmissionVersion.major_ >= 2)
return failure();
// For version less than 2.0, override the encoding of IntegerType.
@@ -159,7 +159,7 @@ struct TestBytecodeCallbackPass
// supported. For the purpose of the test, just use
// `targetEmissionVersion`.
(void)version;
- if (targetEmissionVersion.major >= 2)
+ if (targetEmissionVersion.major_ >= 2)
return success();
// `dialectName` is the name of the group we have the opportunity to
More information about the Mlir-commits
mailing list