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

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 7 22:29:24 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();
----------------
vitalybuka wrote:

Why M.getModuleIdentifier() is not already fixed by fsanitize_compilation_dir in the clang?
If so, we need no special sanitizer specific processing?

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


More information about the cfe-commits mailing list