[PATCH] D148757: [clang] Follow user-provided order for prefix map

Gulfem Savrun Yeniceri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 16:31:57 PDT 2023


gulfem created this revision.
Herald added a project: All.
gulfem requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch uses llvm::MapVector instead of std::map to ensure
that iteration order is the insertion order for file prefix remapping
for coverage and debug info in order to follow the prefix remapping
order that the user specifies.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148757

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/CoverageMappingGen.h
  clang/test/Profile/coverage-prefix-map.c


Index: clang/test/Profile/coverage-prefix-map.c
===================================================================
--- clang/test/Profile/coverage-prefix-map.c
+++ clang/test/Profile/coverage-prefix-map.c
@@ -19,3 +19,7 @@
 
 // RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -fcoverage-compilation-dir=/custom -fcoverage-prefix-map=/custom=/nonsense -o - | FileCheck --check-prefix=COVERAGE-COMPILATION-DIR %s
 // COVERAGE-COMPILATION-DIR: @__llvm_coverage_mapping = {{.*"\\02.*}}nonsense
+
+// Test that user provided prefix replacement order is followed by appending to nonse to the beginning of every path.
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name coverage-prefix-map.c %t/root/nested/coverage-prefix-map.c -fcoverage-prefix-map==nonsense -fcoverage-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=COVERAGE-PREFIX-MAP-ORDER %s
+// COVERAGE-PREFIX-MAP-ORDER: @__llvm_coverage_mapping = {{.*"\\02.*nonsense.*nonsense.*root.*nested.*coverage-prefix-map\.c}}
Index: clang/lib/CodeGen/CoverageMappingGen.h
===================================================================
--- clang/lib/CodeGen/CoverageMappingGen.h
+++ clang/lib/CodeGen/CoverageMappingGen.h
@@ -18,6 +18,8 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -107,7 +109,8 @@
   llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries;
   std::vector<llvm::Constant *> FunctionNames;
   std::vector<FunctionInfo> FunctionRecords;
-  std::map<std::string, std::string> CoveragePrefixMap;
+  llvm::MapVector<std::string, std::string, llvm::StringMap<unsigned>>
+      CoveragePrefixMap;
 
   std::string getCurrentDirname();
   std::string normalizeFilename(StringRef Filename);
Index: clang/include/clang/Basic/CodeGenOptions.h
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.h
+++ clang/include/clang/Basic/CodeGenOptions.h
@@ -17,6 +17,8 @@
 #include "clang/Basic/XRayInstr.h"
 #include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/Frontend/Debug/Options.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Target/TargetOptions.h"
@@ -206,8 +208,13 @@
   /// if non-empty.
   std::string RecordCommandLine;
 
-  std::map<std::string, std::string> DebugPrefixMap;
-  std::map<std::string, std::string> CoveragePrefixMap;
+  /// Prefix replacement map for coverage.
+  llvm::MapVector<std::string, std::string, llvm::StringMap<unsigned>>
+      CoveragePrefixMap;
+
+  /// Prefix replacement map for debug info.
+  llvm::MapVector<std::string, std::string, llvm::StringMap<unsigned>>
+      DebugPrefixMap;
 
   /// The ABI to use for passing floating point arguments.
   std::string FloatABI;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148757.515127.patch
Type: text/x-patch
Size: 3172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230419/cbfa7d7f/attachment-0001.bin>


More information about the cfe-commits mailing list