Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clang/lib/Headers/__clang_hip_runtime_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ __attribute__((weak)) inline __device__ void free(void *__ptr) {
#endif //__cplusplus

#if !defined(__HIPCC_RTC__)
// We must include the forward declarations before cmath is included.
// Otherwise `constexpr` functions in <cmath> would be implicitely __host__
// __device__. Declaring the __device__ verison before allows us to overload
// them with __device__ versions (this behavour is only valid for system
// headers).
#include <__clang_cuda_math_forward_declares.h>
#include <cmath>
#include <cstdlib>
#include <stdlib.h>
Expand Down Expand Up @@ -144,7 +150,6 @@ typedef __SIZE_TYPE__ size_t;
#if defined(__HIPCC_RTC__)
#include <__clang_hip_cmath.h>
#else
#include <__clang_cuda_math_forward_declares.h>
#include <__clang_hip_cmath.h>
#include <__clang_cuda_complex_builtins.h>
#include <algorithm>
Expand Down
70 changes: 70 additions & 0 deletions clang/test/Headers/hip-constexpr-cmath.hip
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// REQUIRES: amdgpu-registered-target
// RUN: rm -rf %t
// RUN: split-file %s %t
//
// Test with the pre-202604 stl
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
// RUN: -internal-isystem %t/stl/include \
// RUN: -internal-isystem %t/stl/2025/include \
// RUN: -internal-isystem %S/Inputs/include \
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
// RUN: -target-cpu gfx906 -verify %t/main.hip -fcuda-is-device -o /dev/null
//
// Test with the 202604 stl
// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
// RUN: -internal-isystem %S/../../lib/Headers/cuda_wrappers \
// RUN: -internal-isystem %t/stl/include \
// RUN: -internal-isystem %t/stl/2026/include \
// RUN: -internal-isystem %S/Inputs/include \
// RUN: -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
// RUN: -target-cpu gfx906 -verify %t/main.hip -fcuda-is-device -o /dev/null

#--- stl/include/stl_common
_CLANG_BUILTIN2(isunordered)
_CLANG_BUILTIN2(isgreater)
_CLANG_BUILTIN2(isgreaterequal)
_CLANG_BUILTIN2(isless)
_CLANG_BUILTIN2(islessequal)
_CLANG_BUILTIN2(islessgreater)

#define FP_NAN 0
#define FP_INFINITE 1
#define FP_ZERO 2
#define FP_SUBNORMAL 3
#define FP_NORMAL 4
#--- stl/2025/include/version
#define _MSVC_STL_UPDATE 202508L
#--- stl/2025/include/cmath
#define _CLANG_BUILTIN2(NAME) \
bool NAME(float x, float y) noexcept { \
return __builtin_##NAME(x, y); \
}

#include <stl_common>
#--- stl/2026/include/version
#define _MSVC_STL_UPDATE 202604L
#--- stl/2026/include/cmath
#define _CLANG_BUILTIN2(NAME) \
bool constexpr NAME(float x, float y) noexcept { \
return __builtin_##NAME(x, y); \
}

#include <stl_common>
#--- main.hip
// expected-no-diagnostics

#include <cmath>

#define TEST_CMP(NAME) \
bool __attribute__((device)) test_device_ ## NAME (float x) { \
bool b = NAME(x, x); \
return b; \
}

TEST_CMP(isunordered)
TEST_CMP(isgreater)
TEST_CMP(isgreaterequal)
TEST_CMP(isless)
TEST_CMP(islessequal)
TEST_CMP(islessgreater)