[Openmp-commits] [PATCH] D102858: [libomptarget] Improve dlwrap compile time error diagnostic

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu May 20 11:33:36 PDT 2021


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

[libomptarget] Improve dlwrap compile time error diagnostic

The dlwrap interface takes an explict arity, e.g. DLWRAP(cuAlloc, 2);
This probably can't be eliminated as it controls the argument list of an
external symbol, not an inline header function. If the arity given is too
big, the error from clang referring to the line is in the middle of
implementation details.

/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1277:7: error: static_assert failed

  due to requirement '0UL < tuple_size<std::tuple<>>::value' "tuple index is in range"
  static_assert(__i < tuple_size<tuple<>>::value,
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1260:7: ...
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1260:7: ...
/home/amd/llvm-project/openmp/libomptarget/include/dlwrap.h:93:27 ...

/home/amd/llvm-project/openmp/libomptarget/plugins/cuda/dynamic_cuda/cuda.cpp:34:1: note: in

  instantiation of template class 'dlwrap::trait<cudaError_enum (*)(unsigned long *, unsigned
  long)>::arg<2>' requested here

DLWRAP(cuMemAlloc, 3);
^
/home/amd/llvm-project/openmp/libomptarget/include/dlwrap.h:51:31: ...
/home/amd/llvm-project/openmp/libomptarget/include/dlwrap.h:166:3: ...
/home/amd/llvm-project/openmp/libomptarget/include/dlwrap.h:133:3: ...
/home/amd/llvm-project/openmp/libomptarget/include/dlwrap.h:186:37: ...

If the arity is too small, the diagnostic is better:

cuda/dynamic_cuda/cuda.cpp:34:1: error: too few

  arguments to function call, expected 2, have 1

DLWRAP(cuMemAlloc, 1);

This patch changes the diagnostic to:

cuda/dynamic_cuda/cuda.cpp:34:1: error:

  static_assert failed due to requirement '1 == trait<cudaError_enum (*)(unsigned long *, unsigned
  long)>::nargs' "Arity Error"

DLWRAP(cuMemAlloc, 1);

or

cuda/dynamic_cuda/cuda.cpp:34:1: error:

  static_assert failed due to requirement '3 == trait<cudaError_enum (*)(unsigned long *, unsigned
  long)>::nargs' "Arity Error"

DLWRAP(cuMemAlloc, 3);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102858

Files:
  openmp/libomptarget/include/dlwrap.h


Index: openmp/libomptarget/include/dlwrap.h
===================================================================
--- openmp/libomptarget/include/dlwrap.h
+++ openmp/libomptarget/include/dlwrap.h
@@ -158,6 +158,7 @@
       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: D102858.346806.patch
Type: text/x-patch
Size: 631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210520/cc738b75/attachment.bin>


More information about the Openmp-commits mailing list