[clang] e082973 - [Clang][libc] Add wrapper headers for `assert.h` for the GPU libc

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 1 16:34:37 PDT 2023


Author: Joseph Huber
Date: 2023-09-01T18:34:09-05:00
New Revision: e0829739bc77606aa4dcd4769869d2e9ad9d2ec0

URL: https://github.com/llvm/llvm-project/commit/e0829739bc77606aa4dcd4769869d2e9ad9d2ec0
DIFF: https://github.com/llvm/llvm-project/commit/e0829739bc77606aa4dcd4769869d2e9ad9d2ec0.diff

LOG: [Clang][libc] Add wrapper headers for `assert.h` for the GPU libc

Summary:
This patch adds the `assert.h` wrapper header. I forgot to include this
in the last patch.

Added: 
    clang/lib/Headers/llvm_libc_wrappers/assert.h

Modified: 
    clang/lib/Headers/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index e6154d7ecd80ea..39030d433a61ec 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -318,11 +318,13 @@ set(openmp_wrapper_files
 )
 
 set(llvm_libc_wrapper_files
+  llvm_libc_wrappers/assert.h
   llvm_libc_wrappers/stdio.h
   llvm_libc_wrappers/stdlib.h
   llvm_libc_wrappers/string.h
   llvm_libc_wrappers/ctype.h
   llvm_libc_wrappers/inttypes.h
+  llvm_libc_wrappers/time.h
 )
 
 include(GetClangResourceDir)

diff  --git a/clang/lib/Headers/llvm_libc_wrappers/assert.h b/clang/lib/Headers/llvm_libc_wrappers/assert.h
new file mode 100644
index 00000000000000..de650ca8442a19
--- /dev/null
+++ b/clang/lib/Headers/llvm_libc_wrappers/assert.h
@@ -0,0 +1,34 @@
+//===-- Wrapper for C standard assert.h declarations on the GPU ------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLANG_LLVM_LIBC_WRAPPERS_ASSERT_H__
+#define __CLANG_LLVM_LIBC_WRAPPERS_ASSERT_H__
+
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__)
+#error "This file is for GPU offloading compilation only"
+#endif
+
+#include_next <assert.h>
+
+#if __has_include(<llvm-libc-decls/assert.h>)
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define __LIBC_ATTRS __attribute__((device))
+#endif
+
+#pragma omp begin declare target
+
+#include <llvm-libc-decls/assert.h>
+
+#pragma omp end declare target
+
+#undef __LIBC_ATTRS
+
+#endif
+
+#endif // __CLANG_LLVM_LIBC_WRAPPERS_ASSERT_H__


        


More information about the cfe-commits mailing list