[clang] [CIR] Add nothrow attribute to the call operation (PR #145178)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 1 11:08:15 PDT 2025
================
@@ -77,17 +77,38 @@ void CIRGenFunction::emitAggregateStore(mlir::Value value, Address dest) {
builder.createStore(*currSrcLoc, value, dest);
}
+static void addAttributesFromFunctionProtoType(CIRGenBuilderTy &builder,
+ mlir::NamedAttrList &attrs,
+ const FunctionProtoType *fpt) {
+ if (!fpt)
+ return;
+
+ if (!isUnresolvedExceptionSpec(fpt->getExceptionSpecType()) &&
+ fpt->isNothrow())
+ attrs.set("nothrow", mlir::UnitAttr::get(builder.getContext()));
+}
+
/// Construct the CIR attribute list of a function or call.
void CIRGenModule::constructAttributeList(CIRGenCalleeInfo calleeInfo,
- cir::SideEffect &sideEffect) {
+ mlir::NamedAttrList &attrs) {
assert(!cir::MissingFeatures::opCallCallConv());
- sideEffect = cir::SideEffect::All;
+ auto sideEffect = cir::SideEffect::All;
- assert(!cir::MissingFeatures::opCallAttrs());
+ addAttributesFromFunctionProtoType(getBuilder(), attrs,
+ calleeInfo.getCalleeFunctionProtoType());
const Decl *targetDecl = calleeInfo.getCalleeDecl().getDecl();
if (targetDecl) {
+ if (targetDecl->hasAttr<NoThrowAttr>())
+ attrs.set("nothrow", mlir::UnitAttr::get(&getMLIRContext()));
----------------
bcardosolopes wrote:
See `extraClassDeclaration` in `LLVMDialect.td`, we should do similar with attribute names, and here it would become a `getNoThrowAttrName()` call.
https://github.com/llvm/llvm-project/pull/145178
More information about the cfe-commits
mailing list