From b4a6c0e76e962fb8da7724b763d5044f0607c212 Mon Sep 17 00:00:00 2001 From: Tianqi Chen <tqchen@users.noreply.github.com> Date: Wed, 20 Jun 2018 14:10:00 -0700 Subject: [PATCH] [BUILD] Fix reflection build for gcc-8 (#1304) --- dmlc-core | 2 +- src/lang/reflection.cc | 38 ++++++++++++++++++++------------------ src/pass/unroll_loop.cc | 4 ++-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/dmlc-core b/dmlc-core index 9b3f9753a..e864aa675 160000 --- a/dmlc-core +++ b/dmlc-core @@ -1 +1 @@ -Subproject commit 9b3f9753ae81d657743c555e0cacc4e43f0bed2d +Subproject commit e864aa6757cdbe78b1296fe5231fd3050b7802c3 diff --git a/src/lang/reflection.cc b/src/lang/reflection.cc index ba580e75e..d0d857006 100644 --- a/src/lang/reflection.cc +++ b/src/lang/reflection.cc @@ -375,41 +375,43 @@ class NodeAttrSetter : public AttrVisitor { std::string type_key; std::unordered_map<std::string, runtime::TVMArgValue> attrs; - template<typename T> - void SetValue(const char* key, T* value) { - auto it = attrs.find(key); - if (it == attrs.end()) { - LOG(FATAL) << type_key << ": require field " << key; - } - *value = it->second.operator T(); - attrs.erase(it); - } void Visit(const char* key, double* value) final { - SetValue(key, value); + *value = GetAttr(key).operator double(); } void Visit(const char* key, int64_t* value) final { - SetValue(key, value); + *value = GetAttr(key).operator int64_t(); } void Visit(const char* key, uint64_t* value) final { - SetValue(key, value); + *value = GetAttr(key).operator uint64_t(); } void Visit(const char* key, int* value) final { - SetValue(key, value); + *value = GetAttr(key).operator int(); } void Visit(const char* key, bool* value) final { - SetValue(key, value); + *value = GetAttr(key).operator bool(); } void Visit(const char* key, std::string* value) final { - SetValue(key, value); + *value = GetAttr(key).operator std::string(); } void Visit(const char* key, void** value) final { - SetValue(key, value); + *value = GetAttr(key).operator void*(); } void Visit(const char* key, Type* value) final { - SetValue(key, value); + *value = GetAttr(key).operator Type(); } void Visit(const char* key, NodeRef* value) final { - SetValue(key, value); + *value = GetAttr(key).operator NodeRef(); + } + + private: + runtime::TVMArgValue GetAttr(const char* key) { + auto it = attrs.find(key); + if (it == attrs.end()) { + LOG(FATAL) << type_key << ": require field " << key; + } + runtime::TVMArgValue v = it->second; + attrs.erase(it); + return v; } }; diff --git a/src/pass/unroll_loop.cc b/src/pass/unroll_loop.cc index 09844cb75..6c0ac5175 100644 --- a/src/pass/unroll_loop.cc +++ b/src/pass/unroll_loop.cc @@ -29,14 +29,14 @@ class LoopUnroller : public IRMutator { Stmt Mutate_(const AttrStmt* op, const Stmt& stmt) final { if (op->attr_key == "pragma_auto_unroll_max_step") { - int value; + int value = 0; CHECK(arith::GetConstInt(op->value, &value)); std::swap(value, auto_max_step_); Stmt ret = this->Mutate(op->body); std::swap(value, auto_max_step_); return ret; } else if (op->attr_key == "pragma_unroll_explicit") { - int value; + int value = 0; CHECK(arith::GetConstInt(op->value, &value)); bool explicit_unroll = value; std::swap(explicit_unroll, explicit_unroll_); -- GitLab