[clang] [llvm] [Sanitizer] Make sanitizer passes idempotent (PR #99439)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 07:22:31 PDT 2024


================
@@ -12,12 +12,33 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Instrumentation.h"
+#include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/TargetParser/Triple.h"
 
 using namespace llvm;
 
+static cl::opt<bool> ClIgnoreRedundantInstrumentation(
+    "ignore-redundant-instrumentation",
+    cl::desc("Ignore redundant instrumentation"), cl::Hidden, cl::init(false));
+
+/// Check if module has flag attached, if not add the flag.
+bool llvm::checkIfAlreadyInstrumented(Module &M, StringRef flag) {
+  if (M.getModuleFlag(flag)) {
+    if (ClIgnoreRedundantInstrumentation)
+      return true;
+    std::string diagInfo =
+        "Redundant instrumentation detected, with module flag: " +
+        std::string(flag);
+    M.getContext().diagnose(
+        DiagnosticInfoInlineAsm(diagInfo, DiagnosticSeverity::DS_Warning));
----------------
nikic wrote:

This doesn't seem related to inline asm?

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


More information about the llvm-commits mailing list