[clang] [llvm] [Clang] Add `-fsanitize-compilation-dir=` for reproducible sanitizer builds (PR #201803)

Björn Svensson via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 12 06:01:28 PDT 2026


================
@@ -2831,8 +2837,26 @@ GlobalVariable *ModuleAddressSanitizer::getOrCreateModuleName() {
   if (!ModuleName) {
     // We shouldn't merge same module names, as this string serves as unique
     // module ID in runtime.
+    std::string ModuleNameStr = M.getModuleIdentifier();
+
+    // If a compilation dir is set, make absolute paths relative to it.
+    if (!CompilationDir.empty()) {
+      SmallString<256> Path(ModuleNameStr);
+      if (sys::path::is_absolute(Path)) {
+        SmallString<256> CompDir(CompilationDir);
+        if (!sys::path::is_absolute(CompDir))
+          sys::fs::make_absolute(CompDir);
+        sys::path::remove_dots(CompDir, /*remove_dot_dot=*/true);
+        // Ensure trailing separator so "/foo" doesn't match "/foobar/x.c".
+        if (!CompDir.empty() && !sys::path::is_separator(CompDir.back()))
+          CompDir += sys::path::get_separator();
----------------
bjosv wrote:

As I understand it M.getModuleIdentifier() seems to be used by LTO (module hashing, output naming, function import) and diagnostics. Modifying it in the frontend would affect those consumers, so this keeps the change scoped to only ASan, but maybe I missed something


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


More information about the cfe-commits mailing list