[clang] [CIR][ABI] Add restrict, nonnull, and ReturnsNonNull attributes (PR #188281)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 25 15:46:45 PDT 2026


================
@@ -708,6 +713,33 @@ void CIRGenModule::constructFunctionArgumentAttributes(
             builder.getI64IntegerAttr(
                 getNaturalPointeeTypeAlignment(argType).getQuantity()));
     }
+
+    // Source-level parameter attributes (restrict, nonnull).  These
+    // require the FunctionDecl to access ParmVarDecl info.
+    if (fd) {
+      unsigned paramIdx = &argAttrList - argAttrs.data();
+      unsigned srcIdx = info.isInstanceMethod() ? paramIdx - 1 : paramIdx;
+      if (srcIdx < fd->getNumParams()) {
+        const ParmVarDecl *pvd = fd->getParamDecl(srcIdx);
+        QualType pvdType = pvd->getType();
+
+        // restrict on pointer parameters → noalias.
+        if (pvdType->isPointerType() && pvdType.isRestrictQualified())
----------------
andykaylor wrote:

It's not clear to me whether this is a bug in classic codegen or not. What you're doing here looks correct. Classic codegen is checking `Arg->getType().isRestrictQualified()`. Maybe this is missing the restrict qualifier?

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


More information about the cfe-commits mailing list