Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/RISCVTargetParser.h"
#include <optional>
#include <set>

using namespace clang;

Expand Down Expand Up @@ -6953,6 +6954,27 @@ bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
return false;
}

if (getASTContext().getTargetInfo().getTriple().isOSSolaris()) {
if (const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
if (!isStdNamespace(Context.getEffectiveDeclContext(RD)))
return false;

// Issue #33114: Need non-standard mangling of std::tm etc. for
// Solaris ABI compatibility.
static std::set<StringRef> types{"div_t", "ldiv_t", "lconv", "tm"};

// <substitution> ::= tm # ::std::tm, same for the others
if (const IdentifierInfo *II = RD->getIdentifier()) {
StringRef type = II->getName();
if (types.count(type)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (types.count(type)) {
if (llvm::is_contained({"div_t", "ldiv_t", "lconv", "tm"}, type)) {

using a std::set is a bit overkill here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do: I'm pretty ignorant of C++ actually...

Out << type.size() << type;
return true;
}
}
return false;
}
}

return false;
}

Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Lex/PPMacroExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,10 +1604,12 @@ static bool isTargetVariantEnvironment(const TargetInfo &TI,
return false;
}

#if defined(__sun__) && defined(__svr4__)
#if defined(__sun__) && defined(__svr4__) && defined(__clang__) && \
__clang__ < 20
Comment on lines +1607 to +1608
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does every version of gcc we support handles that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly: the fix for GCC PR libstdc++-v3/1773 went in 13 years ago. That should be good enough ;-)

// GCC mangles std::tm as tm for binary compatibility on Solaris (Issue
// #33114). We need to match this to allow the std::put_time calls to link
// (PR #99075).
// (PR #99075). clang 20 contains a fix, but the workaround is still needed
// with older versions.
asm("_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
"RSt8ios_basecPKSt2tmPKcSB_ = "
"_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
Expand Down
27 changes: 27 additions & 0 deletions clang/test/AST/solaris-tm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// Check that std::tm and a few others are mangled as tm on Solaris only.
/// Issue #33114.
///
// RUN: %clang_cc1 -emit-llvm %s -o - -triple amd64-pc-solaris2.11 | FileCheck --check-prefix=CHECK-SOLARIS %s
// RUN: %clang_cc1 -emit-llvm %s -o - -triple x86_64-unknown-linux-gnu | FileCheck --check-prefix=CHECK-LINUX %s
//
// REQUIRES: x86-registered-target
//
// CHECK-SOLARIS: @_Z6tmfunc2tm
// CHECK-SOLARIS: @_Z7ldtfunc6ldiv_t
// CHECK-LINUX: @_Z6tmfuncSt2tm
// CHECK-LINUX: @_Z7ldtfuncSt6ldiv_t

namespace std {
extern "C" {
struct tm {
int tm_sec;
};
struct ldiv_t {
long quot;
};
}
}

void tmfunc (std::tm tm) {}

void ldtfunc (std::ldiv_t ldt) {}