Merge changes I485a362d,I7a1ba66f into main

* changes:
  Update clang for standalone builds
  make base::Uuid and cmd getopt thread-safe via mutex
diff --git a/buildtools/BUILD.gn b/buildtools/BUILD.gn
index 6a44fbe..1d6e039 100644
--- a/buildtools/BUILD.gn
+++ b/buildtools/BUILD.gn
@@ -1421,7 +1421,10 @@
   ]
   cflags = [ "-DFAKE_LOG_DEVICE=1" ]
   if (!is_win) {
-    cflags += [ "-Wno-deprecated-declarations" ]
+    cflags += [
+      "-Wno-deprecated-declarations",
+      "-Wno-vla-cxx-extension",
+    ]
   }
   public_configs = [ ":libunwindstack_config" ]
 }
diff --git a/gn/standalone/BUILD.gn b/gn/standalone/BUILD.gn
index c397d5c..43c81d0 100644
--- a/gn/standalone/BUILD.gn
+++ b/gn/standalone/BUILD.gn
@@ -89,6 +89,10 @@
       "-Wno-unknown-sanitizers",
       "-Wno-unknown-warning-option",
       "-Wno-unsafe-buffer-usage",
+
+      # TODO(primiano): -Wswitch-default could be useful but will require a mass
+      # codebase cleanup.
+      "-Wno-switch-default",
     ]
   } else if (!is_clang && !is_win) {
     # Use return std::move(...) for compatibility with old GCC compilers.
diff --git a/src/base/uuid.cc b/src/base/uuid.cc
index 180a651..f335cfd 100644
--- a/src/base/uuid.cc
+++ b/src/base/uuid.cc
@@ -16,9 +16,11 @@
 
 #include "perfetto/ext/base/uuid.h"
 
+#include <mutex>
 #include <random>
 
 #include "perfetto/base/time.h"
+#include "perfetto/ext/base/no_destructor.h"
 
 namespace perfetto {
 namespace base {
@@ -51,6 +53,12 @@
   Uuid uuid;
   auto& data = *uuid.data();
 
+  // std::random is not thread safe and users of this class might mistakenly
+  // assume Uuidv4() is thread_safe because from the outside looks like a
+  // local object.
+  static base::NoDestructor<std::mutex> rand_mutex;
+  std::unique_lock<std::mutex> rand_lock(rand_mutex.ref());
+
   for (size_t i = 0; i < sizeof(data);) {
     // Note: the 32-th bit of rng() is always 0 as minstd_rand operates modulo
     // 2**31. Fill in blocks of 16b rather than 32b to not lose 1b of entropy.
diff --git a/src/perfetto_cmd/perfetto_cmd.cc b/src/perfetto_cmd/perfetto_cmd.cc
index 37918c6..9d77c4b 100644
--- a/src/perfetto_cmd/perfetto_cmd.cc
+++ b/src/perfetto_cmd/perfetto_cmd.cc
@@ -39,6 +39,7 @@
 #include <fstream>
 #include <iostream>
 #include <iterator>
+#include <mutex>
 #include <random>
 #include <sstream>
 #include <thread>
@@ -50,6 +51,7 @@
 #include "perfetto/ext/base/ctrl_c_handler.h"
 #include "perfetto/ext/base/file_utils.h"
 #include "perfetto/ext/base/getopt.h"
+#include "perfetto/ext/base/no_destructor.h"
 #include "perfetto/ext/base/pipe.h"
 #include "perfetto/ext/base/string_view.h"
 #include "perfetto/ext/base/temp_file.h"
@@ -356,6 +358,11 @@
     return 1;
   }
 
+  // getopt is not thread safe and cmdline parsing requires a mutex for the case
+  // of concurrent cmdline parsing for bugreport snapshots.
+  static base::NoDestructor<std::mutex> getopt_mutex;
+  std::unique_lock<std::mutex> getopt_lock(getopt_mutex.ref());
+
   optind = 1;  // Reset getopt state. It's reused by the snapshot thread.
   for (;;) {
     int option =
@@ -565,6 +572,7 @@
     has_config_options = true;
     config_options.categories.push_back(argv[i]);
   }
+  getopt_lock.unlock();
 
   if (query_service_ && (is_detach() || is_attach() || background_)) {
     PERFETTO_ELOG("--query cannot be combined with any other argument");
diff --git a/tools/install-build-deps b/tools/install-build-deps
index 802ae9e..d1efa23 100755
--- a/tools/install-build-deps
+++ b/tools/install-build-deps
@@ -165,13 +165,13 @@
     # tools/clang/scripts/update.py.
     Dependency(
         'buildtools/linux64/clang.tgz',
-        'https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-16-init-8697-g60809cd2-1.tgz',
-        '5ae35f85e0d32136795c6b223bf64263d46678dd4a24fea4e9039e58a32670de',
+        'https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-18-init-17730-gf670112a-5.tgz',
+        'ce6201b728ea485d4b116aa3b5e8ae3b34ee2775f25924c5714fdbe42fb2b787',
         'linux', 'x64'),
     Dependency(
         'buildtools/win/clang.tgz',
-        'https://commondatastorage.googleapis.com/chromium-browser-clang/Win/clang-llvmorg-16-init-8697-g60809cd2-1.tgz',
-        '086faec822acba5b9c0308c6a8be34424031027d757efa2b81805aed18ffc521',
+        'https://commondatastorage.googleapis.com/chromium-browser-clang/Win/clang-llvmorg-18-init-17730-gf670112a-5.tgz',
+        '972011cc8a5bc5d5fbe08773089058a264ee0e19af019df28f0972ee9bd0493f',
         'windows', 'x64'),
 ]