================ @@ -1219,8 +1222,25 @@ VersionTuple Triple::getEnvironmentVersion() const { StringRef Triple::getEnvironmentVersionString() const { StringRef EnvironmentName = getEnvironmentName(); + + // none is a valid environment type - it basically amounts to a freestanding + // environment. + if (EnvironmentName == "none") + return ""; + StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment()); EnvironmentName.consume_front(EnvironmentTypeName); + + if (EnvironmentName.contains("-")) { + // -obj is the suffix + if (getObjectFormat() != Triple::UnknownObjectFormat) { + StringRef ObjectFormatTypeName = + getObjectFormatTypeName(getObjectFormat()); + const std::string &tmp = (Twine("-") + ObjectFormatTypeName).str(); ---------------- MaskRay wrote:
Just use `const std::string`. The lifetime extension due to `const &` is subtle and fragile, and does not give any benefit here. https://en.cppreference.com/w/cpp/language/reference_initialization#Lifetime_of_a_temporary https://abseil.io/tips/107 Then `EnvironmentName.consume_back(tmp);` Avoid the used-once `StringRef Suffix = tmp;` https://github.com/llvm/llvm-project/pull/78655 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits