llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clangir Author: Kunal Dubey (xakep8) <details> <summary>Changes</summary> Attached a CIR parameter attribute for function paramerters whose source type has a const-qualier. This preserves source signature info in declarations without changing the lowered pointer type itself. This keeps the ordinary pointer/lvalue typing unchanged while making the qualifier available on the signature side. Fixes #<!-- -->217687 --- Full diff: https://github.com/llvm/llvm-project/pull/218114.diff 2 Files Affected: - (modified) clang/include/clang/CIR/Dialect/IR/CIRDialect.td (+1) - (modified) clang/lib/CIR/CodeGen/CIRGenCall.cpp (+17) ``````````diff diff --git a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td index d974cb1fa4544..57ce67805fdad 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRDialect.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRDialect.td @@ -90,6 +90,7 @@ def CIR_Dialect : Dialect { static llvm::StringRef getAMDGPUSramEccAttrName() { return "cir.amdgpu_sramecc"; } static llvm::StringRef getOpenCLKernelArgMetadataAttrName() { return "cir.cl.kernel_arg_metadata"; } static llvm::StringRef getDefaultTlsModelAttrName() { return "cir.default_tls_model"; } + static llvm::StringRef getConstPointeeAttrName() { return "cir.const_pointee"; } void registerAttributes(); void registerTypes(); diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index 3e689e031f7ad..5602d163bdd62 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -17,7 +17,9 @@ #include "CIRGenFunctionInfo.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/Attributes.h" +#include "clang/AST/TypeBase.h" #include "clang/CIR/ABIArgInfo.h" +#include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/MissingFeatures.h" #include "llvm/ADT/FloatingPointMode.h" #include "llvm/ADT/StringSet.h" @@ -663,6 +665,16 @@ void CIRGenModule::constructFunctionReturnAttributes( } } +static bool hasConstQualifiedPointee(QualType type) { + if (const auto *ptrTy = type->getAs<PointerType>()) + return ptrTy->getPointeeType().isConstQualified(); + + if (const auto *refTy = type->getAs<ReferenceType>()) + return refTy->getPointeeType().isConstQualified(); + + return false; +} + void CIRGenModule::constructFunctionArgumentAttributes( const CIRGenFunctionInfo &info, const Decl *targetDecl, bool isThunk, bool attrOnCallSite, llvm::MutableArrayRef<mlir::NamedAttrList> argAttrs) { @@ -771,6 +783,11 @@ void CIRGenModule::constructFunctionArgumentAttributes( argAttrList.set(mlir::LLVM::LLVMDialect::getNoAliasAttrName(), mlir::UnitAttr::get(&getMLIRContext())); + // const pointer handling + if (pvd && hasConstQualifiedPointee(pvd->getType())) + argAttrList.set(cir::CIRDialect::getConstPointeeAttrName(), + mlir::UnitAttr::get(&getMLIRContext())); + // __attribute__((nonnull)) on pointer parameters. Checks both // per-parameter and function-level nonnull attributes. if (pvd && argType->isAnyPointerType() && !codeGenOpts.NullPointerIsValid) { `````````` </details> https://github.com/llvm/llvm-project/pull/218114 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
