-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
The implementation is currently like
template<typename OperatorType, typename... OperatorArguments>
SimpleNode &
CreateOpNode(const std::vector<Output *> & operands, OperatorArguments... operatorArguments)
{
JLM_ASSERT(!operands.empty());
return SimpleNode::Create(
*operands[0]->region(),
std::make_unique<OperatorType>(std::move(operatorArguments)...),
operands);
}but we can avoid potential copying of arguments by using perfect forwarding, like so:
template<typename OperatorType, typename... OperatorArguments>
SimpleNode &
CreateOpNode(const std::vector<Output *> & operands, OperatorArguments&&... operatorArguments)
{
JLM_ASSERT(!operands.empty());
return SimpleNode::Create(
*operands[0]->region(),
std::make_unique<OperatorType>(std::forward<OperatorArguments>(operatorArguments)...),
operands);
}The problem is that this causes some annoying false-positive warnings.
The following snippet from IfConversionTests.cpp, for example:
const auto & c0 = jlm::rvsdg::CreateOpNode<jlm::rvsdg::ctlconstant_op>(
*gammaNode0->subregion(0),
jlm::rvsdg::ControlValueRepresentation(0, 2));gives
tests/jlm/llvm/opt/IfConversionTests.cpp: In function ‘void EmptyGammaWithTwoSubregions()’:
tests/jlm/llvm/opt/IfConversionTests.cpp:180:16: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
180 | const auto & c0 = jlm::rvsdg::CreateOpNode<jlm::rvsdg::ctlconstant_op>(
| ^~
compilation terminated due to -Wfatal-errors.
cc1plus: all warnings being treated as errors
It is possible to wrap the definitions of CreateOpNode with _Pragma("GCC diagnostic ignored \"-Wdangling-reference\""), but I'm not a huge fan of it. example
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels