[clang] dab859d - Reland: [clang driver] Move default module cache from system temporary directory

2020-06-27 Thread David Zarzycki via cfe-commits

Author: David Zarzycki
Date: 2020-06-27T05:35:15-04:00
New Revision: dab859d1bf250c4d0299ac505e2a6773c56b6503

URL: 
https://github.com/llvm/llvm-project/commit/dab859d1bf250c4d0299ac505e2a6773c56b6503
DIFF: 
https://github.com/llvm/llvm-project/commit/dab859d1bf250c4d0299ac505e2a6773c56b6503.diff

LOG: Reland: [clang driver] Move default module cache from system temporary 
directory

This fixes a unit test. Otherwise here is the original commit:

1) Shared writable directories like /tmp are a security problem.
2) Systems provide dedicated cache directories these days anyway.
3) This also refines LLVM's cache_directory() on Darwin platforms to use
   the Darwin per-user cache directory.

Reviewers: compnerd, aprantl, jakehehrlich, espindola, respindola, 
ilya-biryukov, pcc, sammccall

Reviewed By: compnerd, sammccall

Subscribers: hiraditya, llvm-commits, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D82362

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Driver.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/modules-cache-path.m
clang/unittests/Driver/ModuleCacheTest.cpp
llvm/lib/Support/Unix/Path.inc
llvm/unittests/Support/Path.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 15e6d35117b4..c24c289f94b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ New Compiler Flags
   simplify access to the many single purpose floating point options. The 
default
   setting is ``precise``.
 
+- The default module cache has moved from /tmp to a per-user cache directory.
+  By default, this is ~/.cache but on some platforms or installations, this
+  might be elsewhere. The -fmodules-cache-path=... flag continues to work.
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b024d6a0d3a3..dc18f1314f81 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -621,7 +621,8 @@ class Driver {
   static bool GetReleaseVersion(StringRef Str,
 MutableArrayRef Digits);
   /// Compute the default -fmodule-cache-path.
-  static void getDefaultModuleCachePath(SmallVectorImpl &Result);
+  /// \return True if the system provides a default cache directory.
+  static bool getDefaultModuleCachePath(SmallVectorImpl &Result);
 };
 
 /// \return True if the last defined optimization level is -Ofast.

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8903641a26c6..1fd638f435b9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -721,38 +721,6 @@ static void addDashXForInput(const ArgList &Args, const 
InputInfo &Input,
   }
 }
 
-static void appendUserToPath(SmallVectorImpl &Result) {
-#ifdef LLVM_ON_UNIX
-  const char *Username = getenv("LOGNAME");
-#else
-  const char *Username = getenv("USERNAME");
-#endif
-  if (Username) {
-// Validate that LoginName can be used in a path, and get its length.
-size_t Len = 0;
-for (const char *P = Username; *P; ++P, ++Len) {
-  if (!clang::isAlphanumeric(*P) && *P != '_') {
-Username = nullptr;
-break;
-  }
-}
-
-if (Username && Len > 0) {
-  Result.append(Username, Username + Len);
-  return;
-}
-  }
-
-// Fallback to user id.
-#ifdef LLVM_ON_UNIX
-  std::string UID = llvm::utostr(getuid());
-#else
-  // FIXME: Windows seems to have an 'SID' that might work.
-  std::string UID = "";
-#endif
-  Result.append(UID.begin(), UID.end());
-}
-
 static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
const Driver &D, const InputInfo &Output,
const ArgList &Args,
@@ -3201,11 +3169,13 @@ static void RenderBuiltinOptions(const ToolChain &TC, 
const llvm::Triple &T,
 CmdArgs.push_back("-fno-math-builtin");
 }
 
-void Driver::getDefaultModuleCachePath(SmallVectorImpl &Result) {
-  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false, Result);
-  llvm::sys::path::append(Result, "org.llvm.clang.");
-  appendUserToPath(Result);
-  llvm::sys::path::append(Result, "ModuleCache");
+bool Driver::getDefaultModuleCachePath(SmallVectorImpl &Result) {
+  if (llvm::sys::path::cache_directory(Result)) {
+llvm::sys::path::append(Result, "clang");
+llvm::sys::path::append(Result, "ModuleCache");
+return true;
+  }
+  return false;
 }
 
 static void RenderModulesOptions(Compilation &C, const Driver &D,
@@ -3262,6 +3232,7 @@ static void RenderModulesOptions(Compilation &C, const 
Driver &D,
 if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
   Path = A->getValue();
 
+bool HasPath = true;

[PATCH] D82701: [clangd][Hover] Dont crash on null types

2020-06-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82701

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -708,6 +708,24 @@
  HI.Definition = "X x";
  HI.Type = "struct X";
}},
+  {// Don't crash on null types.
+   R"cpp(
+  #define M(l, r) l = r
+  int bar();
+  void foo() {
+M(auto [^[[x]]], bar()); /*error-ok*/
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "x";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.LocalScope = "foo::";
+ HI.Definition = "";
+ HI.Type = "NULL TYPE";
+ // Bindings are in theory public members of an anonymous struct.
+ HI.AccessSpecifier = "public";
+   }},
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -124,8 +124,8 @@
   // TypePrinter doesn't resolve decltypes, so resolve them here.
   // FIXME: This doesn't handle composite types that contain a decltype in 
them.
   // We should rather have a printing policy for that.
-  while (const auto *DT = QT->getAs())
-QT = DT->getUnderlyingType();
+  while (!QT.isNull() && QT->isDecltypeType())
+QT = QT->getAs()->getUnderlyingType();
   return QT.getAsString(Policy);
 }
 


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -708,6 +708,24 @@
  HI.Definition = "X x";
  HI.Type = "struct X";
}},
+  {// Don't crash on null types.
+   R"cpp(
+  #define M(l, r) l = r
+  int bar();
+  void foo() {
+M(auto [^[[x]]], bar()); /*error-ok*/
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "x";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.LocalScope = "foo::";
+ HI.Definition = "";
+ HI.Type = "NULL TYPE";
+ // Bindings are in theory public members of an anonymous struct.
+ HI.AccessSpecifier = "public";
+   }},
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Code);
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -124,8 +124,8 @@
   // TypePrinter doesn't resolve decltypes, so resolve them here.
   // FIXME: This doesn't handle composite types that contain a decltype in them.
   // We should rather have a printing policy for that.
-  while (const auto *DT = QT->getAs())
-QT = DT->getUnderlyingType();
+  while (!QT.isNull() && QT->isDecltypeType())
+QT = QT->getAs()->getUnderlyingType();
   return QT.getAsString(Policy);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82690: [clang][SourceManager] cache Macro Expansions pt.2

2020-06-27 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

yes let's revert dffc1420451f674 
 and 
reland with this change included, also please keep the `Differential Revision: 
https://reviews.llvm.org/D80681` line on the commit message, so that it gets 
associated with the previous review, as it contains a lot of context.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82690/new/

https://reviews.llvm.org/D82690



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits