[Openmp-commits] [PATCH] D106543: [libomptarget][nfc] Improve static assert message in dlwrap

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Jul 22 06:24:11 PDT 2021


JonChesterfield created this revision.
JonChesterfield added reviewers: jdoerfert, tianshilei1992.
JonChesterfield requested review of this revision.
Herald added a project: OpenMP.
Herald added a subscriber: openmp-commits.

Revision of D102858 <https://reviews.llvm.org/D102858>. Raise dlwrap arity argument to template argument
so the correct value is given in the error message. E.g. '2 == 1' instead of
'2 == trait<>::nargs'.

Arity higher than it should be:
Before diff

  $/plugins/cuda/dynamic_cuda/cuda.cpp:23:1: error: 
        static_assert failed due to requirement '2 == trait<cudaError_enum (*)(unsigned int)>::nargs'
        "Arity Error"
  DLWRAP_INTERNAL(cuInit, 2);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ...
  $/include/dlwrap.h:166:3: note: expanded from macro
        'DLWRAP_COMMON'
    static_assert(ARITY == trait<decltype(&SYMBOL)>::nargs, "Arity Error");      \

After diff
In file included from $/plugins/cuda/dynamic_cuda/cuda.cpp:16:

  $/include/dlwrap.h:131:3: error: static_assert failed due to
        requirement '2UL == 1UL' "Arity Error"
    static_assert(Requested == Required, "Arity Error");
    ^             ~~~~~~~~~~~~~~~~~~~~~
  $/plugins/cuda/dynamic_cuda/cuda.cpp:23:1: note: in
        instantiation of function template specialization 'dlwrap::verboseAssert<2UL, 1UL>' requested
        here
  DLWRAP_INTERNAL(cuInit, 2);

Arity lower than it should be:
Before diff

  $/plugins/cuda/dynamic_cuda/cuda.cpp:131:10: error: no
        matching function for call to 'dlwrap_cuInit'
    return dlwrap_cuInit(X);
           ^~~~~~~~~~~~~
  $/plugins/cuda/dynamic_cuda/cuda.cpp:23:1: note: candidate
        function not viable: requires 0 arguments, but 1 was provided
  DLWRAP_INTERNAL(cuInit, 0);

After diff
In file included from $/plugins/cuda/dynamic_cuda/cuda.cpp:16:

  $/include/dlwrap.h:131:3: error: static_assert failed due to
        requirement '0UL == 1UL' "Arity Error"
    static_assert(Requested == Required, "Arity Error");
    ^             ~~~~~~~~~~~~~~~~~~~~~
  $/plugins/cuda/dynamic_cuda/cuda.cpp:23:1: note: in
        instantiation of function template specialization 'dlwrap::verboseAssert<0UL, 1UL>' requested
        here
  DLWRAP_INTERNAL(cuInit, 0);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106543

Files:
  openmp/libomptarget/include/dlwrap.h


Index: openmp/libomptarget/include/dlwrap.h
===================================================================
--- openmp/libomptarget/include/dlwrap.h
+++ openmp/libomptarget/include/dlwrap.h
@@ -127,6 +127,10 @@
   return {{dlwrap::type::symbol<Is>::call()...}};
 }
 
+template <size_t Requested, size_t Required> constexpr void verboseAssert() {
+  static_assert(Requested == Required, "Arity Error");
+}
+
 } // namespace dlwrap
 
 #define DLWRAP_INSTANTIATE(SYM_USE, SYM_DEF, ARITY)                            \
@@ -153,12 +157,12 @@
   struct SYMBOL##_Trait : public dlwrap::trait<decltype(&SYMBOL)> {            \
     using T = dlwrap::trait<decltype(&SYMBOL)>;                                \
     static T::FunctionType get() {                                             \
+      verboseAssert<ARITY, trait<decltype(&SYMBOL)>::nargs>();                 \
       constexpr size_t Index = DLWRAP_ID() - 1;                                \
       void *P = *dlwrap::pointer(Index);                                       \
       return reinterpret_cast<T::FunctionType>(P);                             \
     }                                                                          \
   };                                                                           \
-  static_assert(ARITY == trait<decltype(&SYMBOL)>::nargs, "Arity Error");      \
   }
 
 #define DLWRAP_IMPL(SYMBOL, ARITY)                                             \


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106543.360786.patch
Type: text/x-patch
Size: 1449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210722/ce4ea717/attachment.bin>


More information about the Openmp-commits mailing list