From 92fae514ba62bf6f8c781889611bd5e14b3414a6 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Tue, 23 Nov 2021 17:53:43 -0600 Subject: [PATCH 1/3] Fix abigen with int expression template arguments In my contracts, I use several template arguments which are expressions which resolve to integral values (such as an eosio::name) but are not literal integer values. This works great in my contracts, but causes abigen to fail. Fix abigen in cases where a template argument is an expression that resolves to an integer, but isn't an integer literal. --- tools/include/eosio/gen.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/include/eosio/gen.hpp b/tools/include/eosio/gen.hpp index fdf631a7ec..a6092f02cf 100644 --- a/tools/include/eosio/gen.hpp +++ b/tools/include/eosio/gen.hpp @@ -370,7 +370,8 @@ struct generation_utils { if (auto ce = llvm::dyn_cast(std::get(arg))) { auto il = llvm::dyn_cast(ce->getSubExpr()); return std::to_string(il->getValue().getLimitedValue()); - } + } else if (auto ce = llvm::dyn_cast(std::get(arg))) + return ce->getResultAsAPSInt().toString(10); } else { return std::get(arg).toString(10); } From 0b0c1c6fa98125bfe9b7c1092089ca89b5bca4cb Mon Sep 17 00:00:00 2001 From: Nathaniel Hourt Date: Sat, 18 Mar 2023 21:45:03 -0500 Subject: [PATCH 2/3] Update tools/include/eosio/gen.hpp Add braces Co-authored-by: Scott B --- tools/include/eosio/gen.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/include/eosio/gen.hpp b/tools/include/eosio/gen.hpp index a6092f02cf..8e2494d428 100644 --- a/tools/include/eosio/gen.hpp +++ b/tools/include/eosio/gen.hpp @@ -370,8 +370,9 @@ struct generation_utils { if (auto ce = llvm::dyn_cast(std::get(arg))) { auto il = llvm::dyn_cast(ce->getSubExpr()); return std::to_string(il->getValue().getLimitedValue()); - } else if (auto ce = llvm::dyn_cast(std::get(arg))) + } else if (auto ce = llvm::dyn_cast(std::get(arg))) { return ce->getResultAsAPSInt().toString(10); + } } else { return std::get(arg).toString(10); } From 8dfff37a7be04de8d392d0b82eba2bc3011c2e1d Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Sat, 18 Mar 2023 22:37:26 -0500 Subject: [PATCH 3/3] Ref #99: Add test This test fails without the fix to issue #99, and passes with it. The failure is a bit odd -- it doesn't fail because cdt-cpp crashes; rather, it fails because the crashed cdt-cpp did not output an abi file and therefore it cannot match the golden record... But hey, it does test the issue, just rather indirectly. =) --- .../abigen-pass/tagged_number_test.abi | 38 +++++++++++++++++++ .../abigen-pass/tagged_number_test.cpp | 17 +++++++++ .../abigen-pass/tagged_number_test.json | 9 +++++ 3 files changed, 64 insertions(+) create mode 100644 tests/toolchain/abigen-pass/tagged_number_test.abi create mode 100644 tests/toolchain/abigen-pass/tagged_number_test.cpp create mode 100644 tests/toolchain/abigen-pass/tagged_number_test.json diff --git a/tests/toolchain/abigen-pass/tagged_number_test.abi b/tests/toolchain/abigen-pass/tagged_number_test.abi new file mode 100644 index 0000000000..5d36bb80a1 --- /dev/null +++ b/tests/toolchain/abigen-pass/tagged_number_test.abi @@ -0,0 +1,38 @@ +{ + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", + "version": "eosio::abi/1.2", + "types": [], + "structs": [ + { + "name": "TaggedNumber_3472950412842106880", + "base": "", + "fields": [ + { + "name": "value", + "type": "uint64" + } + ] + }, + { + "name": "test", + "base": "", + "fields": [ + { + "name": "", + "type": "TaggedNumber_3472950412842106880" + } + ] + } + ], + "actions": [ + { + "name": "test", + "type": "test", + "ricardian_contract": "" + } + ], + "tables": [], + "ricardian_clauses": [], + "variants": [], + "action_results": [] +} \ No newline at end of file diff --git a/tests/toolchain/abigen-pass/tagged_number_test.cpp b/tests/toolchain/abigen-pass/tagged_number_test.cpp new file mode 100644 index 0000000000..6ececc057c --- /dev/null +++ b/tests/toolchain/abigen-pass/tagged_number_test.cpp @@ -0,0 +1,17 @@ +#include + +using namespace eosio; + +template +struct TaggedNumber { + uint64_t value; +}; + +class [[eosio::contract]] tagged_number_test : public contract { + public: + using contract::contract; + + [[eosio::action]] + void test(TaggedNumber<"a.tag"_n.value>) { + } +}; diff --git a/tests/toolchain/abigen-pass/tagged_number_test.json b/tests/toolchain/abigen-pass/tagged_number_test.json new file mode 100644 index 0000000000..f6e07bf6b2 --- /dev/null +++ b/tests/toolchain/abigen-pass/tagged_number_test.json @@ -0,0 +1,9 @@ +{ + "tests" : [ + { + "expected" : { + "abi-file" : "tagged_number_test.abi" + } + } + ] +}