Skip to content

Commit 36b87d3

Browse files
committed
[Serialization] Use a more reliable macro to get the compiler tag
Use only the SWIFT_COMPILER_VERSION macro to check for swiftmodules being written by the same compiler that reads it. In practice, it's the macro used for release builds of the compiler. rdar://96868333
1 parent 82e9380 commit 36b87d3

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

include/swift/Basic/Version.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ StringRef getSwiftRevision();
191191

192192
/// Is the running compiler built with a version tag for distribution?
193193
/// When true, \c Version::getCurrentCompilerVersion returns a valid version
194-
/// and \c getSwiftRevision returns the version tuple in string format.
194+
/// and \c getCurrentCompilerTag returns the version tuple in string format.
195195
bool isCurrentCompilerTagged();
196196

197+
/// Retrieves the distribtion tag of the running compiler, if any.
198+
StringRef getCurrentCompilerTag();
199+
197200
} // end namespace version
198201
} // end namespace swift
199202

lib/Basic/Version.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,5 +507,13 @@ bool isCurrentCompilerTagged() {
507507
#endif
508508
}
509509

510+
StringRef getCurrentCompilerTag() {
511+
#ifdef SWIFT_COMPILER_VERSION
512+
return SWIFT_COMPILER_VERSION;
513+
#else
514+
return StringRef();
515+
#endif
516+
}
517+
510518
} // end namespace version
511519
} // end namespace swift

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static ValidationInfo validateControlBlock(
359359
StringRef moduleRevision = blobData;
360360
if (isCompilerTagged) {
361361
StringRef compilerRevision = forcedDebugRevision ?
362-
forcedDebugRevision : version::getSwiftRevision();
362+
forcedDebugRevision : version::getCurrentCompilerTag();
363363
if (moduleRevision != compilerRevision) {
364364
result.status = Status::RevisionIncompatible;
365365

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ void Serializer::writeHeader(const SerializationOptions &options) {
10041004
static const char* forcedDebugRevision =
10051005
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION");
10061006
auto revision = forcedDebugRevision ?
1007-
forcedDebugRevision : version::getSwiftRevision();
1007+
forcedDebugRevision : version::getCurrentCompilerTag();
10081008
Revision.emit(ScratchRecord, revision);
10091009

10101010
IsOSSA.emit(ScratchRecord, options.IsOSSA);

0 commit comments

Comments
 (0)