[clang] d96f526 - [clang][test] Disallow using the default module cache path in lit tests

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 12 09:55:13 PDT 2022


Author: Ben Langmuir
Date: 2022-09-12T09:54:56-07:00
New Revision: d96f526196ac4cebfdd318473816f6d4b9d76707

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

LOG: [clang][test] Disallow using the default module cache path in lit tests

Make the default module cache path invalid when running lit tests so
that tests are forced to provide a cache path. This avoids accidentally
escaping to the system default location, and would have caught the
failure recently found in ClangScanDeps/multiple-commands.c.

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

Added: 
    

Modified: 
    clang/test/Driver/modules-cache-path.m
    clang/test/Modules/driver.c
    llvm/utils/lit/lit/llvm/config.py

Removed: 
    


################################################################################
diff  --git a/clang/test/Driver/modules-cache-path.m b/clang/test/Driver/modules-cache-path.m
index 1da27d2143631..f700a9738742f 100644
--- a/clang/test/Driver/modules-cache-path.m
+++ b/clang/test/Driver/modules-cache-path.m
@@ -1,4 +1,4 @@
-// RUN: %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-DEFAULT
+// RUN: env -u CLANG_MODULE_CACHE_PATH %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-DEFAULT
 // CHECK-DEFAULT: -fmodules-cache-path={{.*}}clang{{[/\\]+}}ModuleCache
 
 // RUN: env CLANG_MODULE_CACHE_PATH=/dev/null \

diff  --git a/clang/test/Modules/driver.c b/clang/test/Modules/driver.c
index 34fc163a5ccd4..8ffa23ba4e71c 100644
--- a/clang/test/Modules/driver.c
+++ b/clang/test/Modules/driver.c
@@ -1,4 +1,4 @@
-// RUN: %clang -fmodules -fimplicit-module-maps %s -### 2>&1 | FileCheck -check-prefix CHECK-NO_MODULE_CACHE %s
+// RUN: env -u CLANG_MODULE_CACHE_PATH %clang -fmodules -fimplicit-module-maps %s -### 2>&1 | FileCheck -check-prefix CHECK-NO_MODULE_CACHE %s
 // RUN: %clang -fmodules -fimplicit-module-maps -fmodules-cache-path=blarg %s -### 2>&1 | FileCheck -check-prefix CHECK-WITH_MODULE_CACHE %s
 
 // CHECK-NO_MODULE_CACHE: {{clang.*"-fmodules-cache-path=.*ModuleCache"}}

diff  --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py
index 591b9938f211f..6149f4db7e0ca 100644
--- a/llvm/utils/lit/lit/llvm/config.py
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -495,6 +495,10 @@ def use_clang(self, additional_tool_dirs=[], additional_flags=[],
 
         self.clear_environment(possibly_dangerous_env_vars)
 
+        # Make the default module cache path invalid so that tests are forced to
+        # provide a cache path if they use implicit modules.
+        self.with_environment('CLANG_MODULE_CACHE_PATH', '/dev/null')
+
         # Tweak the PATH to include the tools dir and the scripts dir.
         # Put Clang first to avoid LLVM from overriding out-of-tree clang
         # builds.


        


More information about the cfe-commits mailing list