[clang][test] Disallow using the default module cache path in lit tests
authorBen Langmuir <blangmuir@apple.com>
Fri, 9 Sep 2022 22:56:08 +0000 (15:56 -0700)
committerBen Langmuir <blangmuir@apple.com>
Mon, 12 Sep 2022 16:54:56 +0000 (09:54 -0700)
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

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

index 1da27d2..f700a97 100644 (file)
@@ -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 \
index 34fc163..8ffa23b 100644 (file)
@@ -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"}}
index 591b993..6149f4d 100644 (file)
@@ -495,6 +495,10 @@ class LLVMConfig(object):
 
         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.