[clang] [llvm] [Sanitizer] Make sanitizer passes idempotent (PR #99439)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 13:39:44 PDT 2024
================
@@ -12,12 +12,47 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Instrumentation.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.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));
+
+namespace {
+/// Diagnostic information for IR instrumentation reporting.
+class DiagnosticInfoInstrumentation : public DiagnosticInfo {
+ const Twine &Msg;
+
+public:
+ DiagnosticInfoInstrumentation(const Twine &DiagMsg,
+ DiagnosticSeverity Severity = DS_Warning)
+ : DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
+ void print(DiagnosticPrinter &DP) const override { DP << Msg; }
+};
+} // namespace
+
+/// Check if module has flag attached, if not add the flag.
+bool llvm::checkIfAlreadyInstrumented(Module &M, StringRef Flag) {
----------------
vitalybuka wrote:
Early return please and DS_Error?
```suggestion
bool llvm::checkIfAlreadyInstrumented(Module &M, StringRef Flag) {
if (!M.getModuleFlag(Flag)) {
M.addModuleFlag(Module::ModFlagBehavior::Override, Flag, 1);
return false;
}
if (ClIgnoreRedundantInstrumentation)
return true;
std::string diagInfo =
"Redundant instrumentation detected, with module flag: " +
std::string(Flag);
M.getContext().diagnose(DiagnosticInfoInstrumentation(
diagInfo, DiagnosticSeverity::DS_Error));
return true;
}
```
https://github.com/llvm/llvm-project/pull/99439
More information about the llvm-commits
mailing list