allow caller attributes on llvm.sideffect
MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -281,14 +281,13 @@ public:
FnAttrs attrs;
vector<ParamAttrs> param_attrs;
if (!approx) {
- // call_val, attrs, param_attrs, approx
- auto known = known_call(i, TLI, *BB, args);
- if (get<0>(known))
- RETURN_IDENTIFIER(std::move(get<0>(known)));
+ auto [known, attrs0, params0, approx0] = known_call(i, TLI, *BB, args);
+ if (known)
+ RETURN_IDENTIFIER(std::move(known));
- attrs = std::move(get<1>(known));
- param_attrs = std::move(get<2>(known));
- approx = get<3>(known);
+ attrs = std::move(attrs0);
+ param_attrs = std::move(params0);
+ approx = approx0;
}
auto ty = llvm_type2alive(i.getType());
@@ -315,13 +314,8 @@ public:
llvm::AttributeList attrs_callsite = i.getAttributes();
llvm::AttributeList attrs_fndef = fn ? fn->getAttributes()
: llvm::AttributeList();
- const auto &ret = llvm::AttributeList::ReturnIndex;
- const auto &fnidx = llvm::AttributeList::FunctionIndex;
- handleRetAttrs(attrs_callsite.getAttributes(ret), attrs);
- handleRetAttrs(attrs_fndef.getAttributes(ret), attrs);
- handleFnAttrs(attrs_callsite.getAttributes(fnidx), attrs);
- handleFnAttrs(attrs_fndef.getAttributes(fnidx), attrs);
+ parse_fn_attrs(i, attrs);
if (auto op = dyn_cast<llvm::FPMathOperator>(&i)) {
if (op->hasNoNaNs())
@@ -1063,6 +1057,7 @@ public:
}
case llvm::Intrinsic::sideeffect: {
FnAttrs attrs;
+ parse_fn_attrs(i, attrs);
attrs.set(FnAttrs::InaccessibleMemOnly);
attrs.set(FnAttrs::WillReturn);
attrs.set(FnAttrs::NoThrow);
@@ -1070,6 +1065,7 @@ public:
}
case llvm::Intrinsic::trap: {
FnAttrs attrs;
+ parse_fn_attrs(i, attrs);
attrs.set(FnAttrs::NoReturn);
attrs.set(FnAttrs::NoThrow);
return make_unique<FnCall>(Type::voidTy, "", "#trap", std::move(attrs));
@@ -1388,6 +1384,20 @@ public:
}
}
+ void parse_fn_attrs(const llvm::CallInst &i, FnAttrs &attrs) {
+ auto fn = i.getCalledFunction();
+ llvm::AttributeList attrs_callsite = i.getAttributes();
+ llvm::AttributeList attrs_fndef = fn ? fn->getAttributes()
+ : llvm::AttributeList();
+ auto ret = llvm::AttributeList::ReturnIndex;
+ auto fnidx = llvm::AttributeList::FunctionIndex;
+
+ handleRetAttrs(attrs_callsite.getAttributes(ret), attrs);
+ handleRetAttrs(attrs_fndef.getAttributes(ret), attrs);
+ handleFnAttrs(attrs_callsite.getAttributes(fnidx), attrs);
+ handleFnAttrs(attrs_fndef.getAttributes(fnidx), attrs);
+ }
+
optional<Function> run() {
constexpr_idx = 0;

ADD
tests/alive-tv/attrs/sideeffect.srctgt.ll
+declare void @llvm.sideeffect()
+
+define void @src() {
+ call void @llvm.sideeffect() readnone
+ ret void
+}
+
+define void @tgt() {
+ ret void
+}

allow caller attributes on llvm.sideffect