[clang] [lldb] [llvm] [lldb] Fix object format in the Triple of Mach-O files (approach 4) (PR #145157)
David Peixotto via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 27 17:04:34 PDT 2025
================
@@ -463,6 +463,27 @@ class Triple {
const std::string &str() const { return Data; }
+ /// Return the triple string but only keep the first \p N components.
+ ///
+ /// The returned string will preserve the first \p N components exactly the
+ /// same as the original (including the leading "-" and the value, empty or
+ /// not).
+ ///
+ /// E.g. Triple("arm64-apple-ios").str(5) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").str(5) == "arm64-apple-ios--"
+ /// E.g. Triple("arm64-apple-ios--").str(4) == "arm64-apple-ios-"
+ /// E.g. Triple("arm64-apple-ios--").str(3) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").str(2) == "arm64-apple"
+ /// E.g. Triple("arm64-apple-ios--").str(1) == "arm64"
+ /// E.g. Triple("arm64-apple-ios--").str(0) == ""
+ ///
+ /// This method does not normalize any triple strings. Clients that need to
+ /// handle the non-canonical triples that users often specify should use the
+ /// normalize method.
+ ///
+ /// \returns the (shorterned) triple string.
+ StringRef str(size_t N) const;
----------------
dmpots wrote:
It looks like we already have this capability in the `normalize` method
https://github.com/llvm/llvm-project/blob/3ea1296b3724ec5c05f616c98dd883b54b672ff9/llvm/include/llvm/TargetParser/Triple.h#L388
For the use cases in this PR we could do `triple.normalize(CanonicalForm::FOUR_IDENT)`
https://github.com/llvm/llvm-project/pull/145157
More information about the llvm-commits
mailing list