You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2022/07/07 23:01:22 UTC

[impala] 01/02: IMPALA-11412: CodegenFnPtr::store() has a compile time error when instantiated

This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 5a57050d1740f90a3eef5f43c578521c05f8b033
Author: Daniel Becker <da...@cloudera.com>
AuthorDate: Mon Jul 4 11:27:34 2022 +0200

    IMPALA-11412: CodegenFnPtr<FuncType>::store() has a compile time error
    when instantiated
    
    The function template 'CodegenFnPtr<FuncType>::store()' tries to
    implicitly cast a function pointer to 'void*', which is a compile time
    error. The reason this hasn't come up in the builds is that this
    function template is currently not used anywhere, and the function
    pointers are stored through the parent class, using
    'CodegenFnPtrBase::store()', which  takes a 'void*'.
    
    This commit adds the correct explicit cast from function pointer to
    'void*' in 'CodegenFnPtr<FuncType>::store()' and adds tests which
    instantiate (and test) this function template.
    
    Testing:
     - Added tests in llvm-codegen-test.cc that assert that
       'CodegenFnPtr<FuncType>::load()' gives back the same function pointer
       that we store in the object. One test stores the function pointer as
       a 'void*' through 'CodegenFnPtrBase' and the other as a typed
       function pointer through 'CodegenFnPtr<FuncType>'.
    
    Change-Id: I86c78b6237630403db6ca14a3d3e1cffe0e477db
    Reviewed-on: http://gerrit.cloudera.org:8080/18698
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/codegen/codegen-fn-ptr.h     |  2 +-
 be/src/codegen/llvm-codegen-test.cc | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/be/src/codegen/codegen-fn-ptr.h b/be/src/codegen/codegen-fn-ptr.h
index 519912be9..341d01589 100644
--- a/be/src/codegen/codegen-fn-ptr.h
+++ b/be/src/codegen/codegen-fn-ptr.h
@@ -55,7 +55,7 @@ class CodegenFnPtr : public CodegenFnPtrBase {
    }
 
    void store(FuncType value) {
-     CodegenFnPtrBase::store(value);
+     CodegenFnPtrBase::store(reinterpret_cast<void*>(value));
    }
 };
 
diff --git a/be/src/codegen/llvm-codegen-test.cc b/be/src/codegen/llvm-codegen-test.cc
index c9699c337..e1704506a 100644
--- a/be/src/codegen/llvm-codegen-test.cc
+++ b/be/src/codegen/llvm-codegen-test.cc
@@ -42,6 +42,26 @@ using std::unique_ptr;
 
 namespace impala {
 
+class CodegenFnPtrTest : public testing:: Test {
+ protected:
+   typedef int (*FnPtr)(int);
+   static int int_identity(int a) { return a; }
+   CodegenFnPtr<FnPtr> codegen_fn_ptr;
+};
+
+TEST_F(CodegenFnPtrTest, StoreVoidPtrAndLoad) {
+  void* fn_ptr = reinterpret_cast<void*>(int_identity);
+  codegen_fn_ptr.CodegenFnPtrBase::store(fn_ptr);
+  FnPtr loaded_fn_ptr = codegen_fn_ptr.load();
+  ASSERT_TRUE(loaded_fn_ptr == int_identity);
+}
+
+TEST_F(CodegenFnPtrTest, StoreNonVoidPtrAndLoad) {
+  codegen_fn_ptr.store(int_identity);
+  FnPtr loaded_fn_ptr = codegen_fn_ptr.load();
+  ASSERT_TRUE(loaded_fn_ptr == int_identity);
+}
+
 class LlvmCodeGenTest : public testing:: Test {
  protected:
   scoped_ptr<TestEnv> test_env_;