[clang] [CIR] Initial support for sanitizer attributes (PR #220625)

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 22 09:49:28 PDT 2026


================
@@ -144,6 +144,15 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
   theModule->setAttr(cir::CIRDialect::getIntTypeWidthAttrName(),
                      builder.getI32IntegerAttr(target.getIntWidth()));
 
+  llvm::SmallVector<cir::SanitizeKind> sanitizerKinds;
+  if (getLangOpts().Sanitize.has(SanitizerKind::Address))
----------------
Lancern wrote:

The classic codegen handles (most) sanitizers by attaching corresponding LLVM attributes to the emitted functions. For example, if ASAN is enabled, OGCG would attach the LLVM attribute `llvm::Attribute::SanitizeAddress` to the emitted LLVM function.

If we're going to mimic OGCG as much as possible, we may need to 1) invent corresponding CIR attributes for these LLVM function attributes, or 2) we could follow what this PR is currently doing by inventing a single CIR attribute that holds a set of bit-flags indicating the enabled sanitizers. Both approaches would introduce some level of redundancy: 1) would introduce significant amount of new attributes, and 2) would introduce boilerplate code to convert `SanitizerMask` to the CIR attribute and to convert the CIR attribute to the LLVM function attributes.

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


More information about the cfe-commits mailing list