[libc-commits] [lldb] [clang-tools-extra] [libcxx] [lld] [clang] [libc] [llvm] [compiler-rt] [flang] Make clang report invalid target versions for all environment types. (PR #78655)

Fangrui Song via libc-commits libc-commits at lists.llvm.org
Thu Feb 1 10:29:01 PST 2024


================
@@ -1219,8 +1222,24 @@ 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());
+      StringRef Suffix = (Twine("-") + ObjectFormatTypeName).str();
----------------
MaskRay wrote:

This creates a temporary `std::string` and binds it on a StringRef. The temporary `std::string` is then destroyed, leading to a dangling reference, which Clang helpfully warns -Wdangling-gsl

https://github.com/llvm/llvm-project/pull/78655


More information about the libc-commits mailing list